python cv2 视频剪切

import cv2

video_caputre = cv2.VideoCapture('source.MOV')	#原视频
# 获取读入视频的参数
fps = int(video_caputre.get(cv2.CAP_PROP_FPS))
size = int(video_caputre.get(cv2.CAP_PROP_FRAME_WIDTH)), int(video_caputre.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(fps, size)
videoWriter = cv2.VideoWriter('new.avi', cv2.VideoWriter_fourcc('X', 'V', 'I', 'D'), fps, size)

Flag = False
while True:
    ret, frame = video_caputre.read()
    if ret:
        cv2.imshow("new", frame)
        if Flag:
            videoWriter.write(frame)
        key = cv2.waitKey(1)
        if key == ord('s'):     # 按s键开始剪切
            Flag = True
        elif key == ord('e'):   # 剪切结束
            Flag = False
        elif key == ord('q'):   # 中途退出
            break
    else:
    	print("视频结束")
    	break
cv2.destroyAllWindows()
videoWriter.release()

你可能感兴趣的:(python)