I can't seem to capture frames from a file using OpenCV -- I've compiled from source on Ubuntu with all the necessary prereqs according to: http://opencv.willowgarage.com/wiki/InstallGuide%20%3A%20Debian
#!/usr/bin/env python
import cv
import sys
files = sys.argv[1:]
for f in files:
capture = cv.CaptureFromFile(f)
print capture
print cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH)
print cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT)
for i in xrange(10000):
frame = cv.QueryFrame(capture)
if frame:
print frame
Output:
ubuntu@local:~/opencv$ ./test.py bbb.avi
<Capture 0xa37b130>
0.0
0.0
The frames are always None...
I've transcoded a video file to i420 format using:
mencoder $1 -nosound -ovc raw -vf format=i420 -o $2
Any ideas?
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:(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:So things work as expected. What you should check:
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:
ffplay file.avi
-- if that fails, then the problem is likely to be with the file. Try usingffmpeg
to transcode instead ofmencoder
.ffmpeg
install is broken.You don't have the
gstreamer-ffmpeg
orgsteamer-python
orgsteamer-python-devel
packages installed. I installed all three of them. and the exact same problem was resolved.