简体   繁体   English

无法在Mac上的python中使用opencv读取xvid视频

[英]Cannot read xvid video with opencv in python on mac

I have been trying for hours to read a xvid .avi file on my mac with python 2.7 and opencv. 我已经尝试了几个小时,使用python 2.7和opencv在我的Mac上读取xvid .avi文件。 I have installed all the latest versions using brew and opencv is working in python and I can open images and other movie files but when I try to read a xvid avi file with 我已经使用brew安装了所有最新版本,并且opencv在python中工作,并且可以打开图像和其他电影文件,但是当我尝试使用以下命令读取xvid avi文件时

cap.cv2.VideoCapture('video.AVI')
ret, frame = cap.read()

It fails as frame is empty. 由于框架为空,它失败。 I have installed ffmpeg with brew and x264 as well and ran brew doctor. 我还安装了带有brew和x264的ffmpeg并运行了brew医生。 I am totally lost what to do now. 我完全不知道该怎么办。 Happy to provide more information if needed. 如果需要,很高兴提供更多信息。 I hope someone can help me, thanks. 希望有人能帮助我,谢谢。

I finally discovered the solution myself a couple weeks later. 几周后,我终于自己找到了解决方案。 I first had to install Perian and then via brew reinstall opencv with python and ffmpeg support: 我首先必须安装Perian ,然后通过brew重新安装带有python和ffmpeg支持的opencv:

brew uninstall opencv
brew install opencv --with-ffmpeg -v

I hope this will be useful for others. 我希望这对其他人有用。

For opencv3 (in pyenv) I'll supplement crazjo's very helpful and accurate question and answer. 对于opencv3(在pyenv中),我将补充crazjo的非常有用和准确的问答。 I also struggled in vain to read an avi file until I found his answer. 我也徒劳地努力阅读一个avi文件,直到找到他的答案。 Finally I was able to read xvid avi files! 最后,我能够读取xvid avi文件!

I did the following (I could not and did not install perian!!): 我做了以下(我不能也没有安装Perian!):

brew install ffmpeg
brew uninstall opencv3
brew install opencv3 --with-ffmpeg -v

Afterwards I made a symlink between the site-packages of my virtualenv and opencv3. 之后,我在virtualenv和opencv3的站点程序包之间建立了符号链接。

And presto it worked!! 并保存成功! I could read avi files. 我可以阅读avi文件。

Thanks once again and I hope this will also be useful for others!! 再次感谢,希望对其他人也有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM