无法使用opencv2打开视频 [英] Can't open video with opencv2

查看:103
本文介绍了无法使用opencv2打开视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从视频文件中抓取图像,但无法成功打开它,我也不知道为什么.

I'm trying to grab the images from a video file but I can't succeed to open it and I don't know why.

下面是打印False的代码示例,我期望在其中获得True.我不明白为什么我无法打开这个简单的视频文件,非常感谢任何潜在客户!

Below is a code sample that print False where I'm expecting to get a True. I don't get why I can't open this simple video file, any lead would be very much appreciated!

我先尝试了相对路径,然后移到绝对路径以查看是否有任何更改,并且仍然相同...

I tried with a relative path first then moved to an absolute path to see if anything changed and it's still the same...

video = cv2.VideoCapture()
path = "C:\\Users\\Leo\\Dropbox\\Projet VISORD\\TP3\\video.mpg"
print video.open(path)

推荐答案

cv2开箱即用支持的编解码器受到限制.一些格式可以在下面的链接中找到.我还没有尝试全部.

The codecs that cv2 supports out of the box are limited. A few of the formats can be found at the link below. I haven't tried them all yet.

http://opencv.willowgarage.com/wiki/documentation/cpp/highgui/VideoWriter

我在mp42编解码器方面有些运气.必须将相机的mp4(h264)格式转换为正确格式的avi.

I've had some luck with mp42 codec. Had to convert my camera's mp4 (h264) format to an avi in the correct format.

目前使用ffmpeg工具.

Using a tool ffmpeg at the moment.

ffmpeg -i input.mp4 -codec:v msmpeg4v2 output.avi

ffmpeg -i input.mp4 -codec:v msmpeg4v2 output.avi

这仍然有一些需要解决的问题,因为它失去了分辨率,因此我正在努力寻求更好的解决方案.我自己才刚刚开始.

This still leaves something to be desired as it loses resolution, so I am working toward a better solution myself. I only just started at this myself.

这篇关于无法使用opencv2打开视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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