保存视频在OpenCV2-Python中不起作用 [英] Saving videos doesnt work in opencv2-python

查看:178
本文介绍了保存视频在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()

它显示视频没有问题,但是'output.avi'只是一个100kb的文件,无法用任何视频播放器打开. 我尝试从*'XVID'更改编解码器.我尝试了至少100种来自 http://www.fourcc.org/codecs.php 的编解码器类型具有相同的结果.不幸的是,我没有想法了. 我该如何解决这个问题?

It shows the video without problems, but 'output.avi' is only a 100kb file that cannot be opened with any video player. I tried changing the codec from *'XVID'. I tried at least a 100 different codec types from http://www.fourcc.org/codecs.php with the same result. I ran out of ideas unfortunately. How can i solve this issue ?

提前谢谢.

推荐答案

对于OpenCV 2.4.X,您需要进行更改 cv2.VideoWriter_fourcc(*'XVID')

For OpenCV 2.4.X, you’ll need to change cv2.VideoWriter_fourcc(*'XVID')

功能 cv2.cv.FOURCC(*'XVID').

function to cv2.cv.FOURCC(*'XVID') .

这篇关于保存视频在OpenCV2-Python中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆