[英]Saving videos doesnt work in opencv2-python
I am trying to run this example code for saving a video: 我正在尝试运行此示例代码来保存视频:
cap = cv2.VideoCapture('input.mp4')
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
out.write(frame)
cv2.imshow('frame',frame)
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
It shows the video without problems, but 'output.avi' is only a 100kb file that cannot be opened with any video player. 它显示视频没有问题,但'output.avi'只是一个无法用任何视频播放器打开的100kb文件。 I tried changing the codec from *'XVID'.
我尝试从*'XVID'更改编解码器。 I tried at least a 100 different codec types from http://www.fourcc.org/codecs.php with the same result.
我从http://www.fourcc.org/codecs.php尝试了至少100种不同的编解码器类型,结果相同。 I ran out of ideas unfortunately.
不幸的是,我的想法用尽了。 How can i solve this issue ?
我该如何解决这个问题?
Thanks in advance. 提前致谢。
For OpenCV 2.4.X, you'll need to change cv2.VideoWriter_fourcc(*'XVID') 对于OpenCV 2.4.X,您需要更改cv2.VideoWriter_fourcc(*'XVID')
function to cv2.cv.FOURCC(*'XVID') . 功能为cv2.cv.FOURCC(*'XVID')。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.