import argparse
parser = argparse.ArgumentParser() parser.add_argument('-i','-I','--input', help='Input vedio file') parser.add_argument('-o','-U','--output', default = "out_test.avi", help='Output vedio file, default as "out_test.avi"') parser.add_argument('-s','-S','--Start', type = int, default = 0, help='Start from X second. default from 0') parser.add_argument('-e','-E','--End', type = int, default = 1, help='End at X second, defalt at 1s')
args = parser.parse_args() INPUT = args.input OUTPUT = args.output Slice_S = args.Start Slice_E = args.End
import cv2 import numpy as np
cap = cv2.VideoCapture(INPUT) fps_c = cap.get(cv2.CAP_PROP_FPS) Vedio_h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) Vedio_w = cap.get(cv2.CAP_PROP_FRAME_WIDTH) print("Current fps:",fps_c)
Slice_S = Slice_S* fps_c Slice_E = Slice_E* fps_c
fps_o = fps_c Out_size = (int(Vedio_w),int(Vedio_h)) fourcc = cv2.VideoWriter_fourcc('M','J','P','G') videowriter = cv2.VideoWriter(OUTPUT,fourcc,fps_o,Out_size)
Num = 0 while (True): Num += 1 ret,frame=cap.read() if Num >= Slice_S and Num <= Slice_E: videowriter.write(frame) if Num >= Slice_E: break
videowriter.release()
|