Can't open video with opencv2


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"
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.

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.

5/22/2013 2:39:02 AM

Had a similar problem. Try changing

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


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