cv2.VideoWriter

videoCapture = cv2.VideoCapture(args.video_name)
fps = videoCapture.get(cv2.CAP_PROP_FPS)
size = (int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH)),int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
print("fps:",fps,"size:",size)
videoWriter = cv2.VideoWriter("./video/result.avi",cv2.VideoWriter_fourcc('X','V','I','D'),fps,size)
# 创建视频流写入对象,VideoWriter_fourcc为视频编解码器,20为帧播放速率,(640,480)为视频帧大小
videoWriter = cv2.VideoWriter('video.avi', cv2.VideoWriter_fourcc('I', '4', '2', '0'), 20, (640,480))
# 向视频文件写入一帧
videoWriter.write(frame)

参考: cv2.VideoCapture()和cv2.VideoWriter_fourcc()

上一篇:OpenCV学习笔记


下一篇:保存视频