【python下使用OpenCV实现计算机视觉读书笔记3】读写视频文件

代码例如以下:

import cv2
videoCapture = cv2.VideoCapture('car.avi')
fps = videoCapture.get(cv2.cv.CV_CAP_PROP_FPS)
size = (int(videoCapture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)),int(videoCapture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)))
videoWriter = cv2.VideoWriter('carDemo.avi', cv2.cv.CV_FOURCC('I','4','2','0'), fps, size)
success, frame = videoCapture.read()
while success: # Loop until there are no more frames.
    videoWriter.write(frame)
    success, frame = videoCapture.read()
VideoCapture主要有五种格式:

  • cv2.cv.CV_FOURCC('I','4','2','0'): This is an uncompressed YUV, 4:2:0 chroma subsampled. This encoding is widely compatible but produces large files. The file extension should be avi.
  • cv2.cv.CV_FOURCC('P','I','M','1'): This is MPEG-1. The file extension should be avi.
  • cv2.cv.CV_FOURCC('M','J','P','G'): This is motion-JPEG. The file extension should be avi.
  • cv2.cv.CV_FOURCC('T','H','E','O'): This is Ogg-Vorbis. The file extension should be ogv.
  • cv2.cv.CV_FOURCC('F','L','V','1'): This is Flash video. The file extension should be flv.

posted on 2019-03-31 19:20  xfgnongmin  阅读(139)  评论(0编辑  收藏  举报

导航