读/写视频文件

这段代码经过测试后,写出来的AVI文件失去了声音

import cv2

videoCapture = cv2.VideoCapture('test.avi')
fps = videoCapture.get(cv2.CAP_PROP_FPS)
print fps

size = (int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH)), int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
print size

videoWriter = cv2.VideoWriter('MyOutput.avi', cv2.VideoWriter_fourcc('I', '4', '2', '0'), fps, size)
print videoWriter

sucess , frame = videoCapture.read()
while sucess :
    videoWriter.write(frame)
    sucess, frame = videoCapture.read()

注意:
cv2.VideoWrite_fourcc(‘I’, ‘4’, ‘2’, ‘0’) 是未压缩的YUV编码,是4:2:0色度子采样。
cv2.VideoWirte_fourcc(‘P’, ‘I’, ‘M’, ‘l’)是MPEG-1编码,文件扩展名为.avi
cv2.VideoWirte_fourcc(‘X’, ‘V’, ‘I’, ‘D’)是MPEG-4编码视频大小均匀扩展名为.avi
cv2.VideoWirte_fourcc(‘T’, ‘H’, ‘E’, ‘O’)Ogg Vorbis扩展名为.ogv
cv2.VideoWirte_fourcc(‘F’, ‘L’, ‘V’, ‘l’)flash视频,扩展名为.flv

猜你喜欢

转载自blog.csdn.net/kingroc/article/details/74774776