Can't open video with opencv2


Question

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.

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)
1
1
3/16/2013 10:29:22 PM

Accepted Answer

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

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

Using a tool ffmpeg at the moment.

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.

1
5/22/2013 2:39:02 AM

Had a similar problem. Try changing

path = "C:\\Users\\Leo\\Dropbox\\Projet VISORD\\TP3\\video.mpg" 

to

path = "C:/Users/Leo/Dropbox/Projet VISORD/TP3/video.mpg"

and see if it works.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon