Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV + python -- grab frames from a video file

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?

like image 864
Matt Billenstein Avatar asked Feb 08 '11 04:02

Matt Billenstein


1 Answers

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.

like image 62
eric Avatar answered Sep 20 '22 03:09

eric