OpenCV + python — grab frames from a video file

吃可爱长大的小学妹 提交于 2019-12-02 17:21:20
eric

You don't have the gstreamer-ffmpeg or gsteamer-python or gsteamer-python-devel packages installed. I installed all three of them. and the exact same problem was resolved.

I'm using OpenCV 2.2.0, compiled on Ubuntu from source. I can confirm that the source code you provided works as expected. So the problem is somewhere else.

I couldn't reproduce your problem using mencoder (installing it is a bit of a problem on my machine) so I used ffmpeg to wrap a raw video in the AVI container:

ffmpeg -s cif -i ~/local/sample-video/foreman.yuv -vcodec copy foreman.avi

(foreman.yuv is a standard CIF image sequence you can find on the net if you look around).

Running the AVI from ffmpeg through your source gives this:

misha@misha-desktop:~/Desktop/stackoverflow$ python ocv_video.py foreman.avi
<Capture 0xa71120>
352.0
288.0
<iplimage(nChannels=3 width=352 height=288 widthStep=1056 )>
<iplimage(nChannels=3 width=352 height=288 widthStep=1056 )>
...

So things work as expected. What you should check:

  • Do you get any errors on standard output/standard error? OpenCV uses ffmpeg libraries to read video files, so be on the lookout for informative messages. Here's what happens if you try to play a RAW video file without a container (sounds similar to your problem):

error:

misha@misha-desktop:~/Desktop/stackoverflow$ python ocv_video.py foreman.yuv 
[IMGUTILS @ 0x7fff37c8d040] Picture size 0x0 is invalid
[IMGUTILS @ 0x7fff37c8cf20] Picture size 0x0 is invalid
[rawvideo @ 0x19e65c0] Could not find codec parameters (Video: rawvideo, yuv420p)
[rawvideo @ 0x19e65c0] Estimating duration from bitrate, this may be inaccurate
GStreamer Plugin: Embedded video playback halted; module decodebin20 reported: Your GStreamer installation is missing a plug-in.
<Capture 0x19e3130>
0.0
0.0
  • Make sure your AVI file actually contains the required information to play back the video. At a minimum, this should be the frame dimensions. RAW video typically doesn't contain any information besides the actual pixel data, so knowing the frame dimensions and FPS is required. You can wrong-guess the FPS and still get a viewable video, but if you get the dimensions wrong, the video will be unviewable.
  • Make sure the AVI file you're trying to open is actually playable. Try ffplay file.avi -- if that fails, then the problem is likely to be with the file. Try using ffmpeg to transcode instead of mencoder.
  • Make sure you can play other videos, using the same method as above. If you can't, then it's likely that your ffmpeg install is broken.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!