Ask Your Question

VideoCapture doesn't work with video files

asked 2013-12-09 03:36:40 -0600

Mariusz gravatar image

My environment: Windows 7 x64 Qt 5.1.1 OpenCV 2.4.7

I have no problems opening video streams using VideoCapture class, but when it comes to opening files(like .avi or .mp4) the VideoCapture object says, that the file wasn't opened. (Tried with both absolute and relative paths) - on error messages, only isOpened returns false.

From what I've read, it has something to do with ffmpeg, but I have no idea, how I should fix it.

What should I do to be able to open video files?

string filepath[6];
filepath[0] = "C:\\absolute\\path\\test.mp4";
filepath[1] = "C:/absolute/path/test.mp4";
filepath[2] = "test.mp4";

filepath[3] = "C:\\absolute\\path\\test.avi";
filepath[4] = "C:/absolute/path/test.avi";
filepath[5] = "test.avi";

cv::VideoCapture cap;
for(int i = 0; i < 6; ++i){
    cout << filepath[i] << " ";
    cout <<[i]) << endl; //always returns 0
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-12-09 04:17:52 -0600

According to my experience, this is almost always a codec issue. Try adding the opencv_ffmpeg247.dll to your project directory.

edit flag offensive delete link more


I tried this approach - still failed. I debugged the code and it fails on: icvFFOpenCV = LoadLibrary( module_name ); in cap_ffmpeg.cpp The library is copied to: project directory, application directory, application directory/debug. I also updated PATH env variable with location of this lib.

Mariusz gravatar imageMariusz ( 2013-12-09 08:00:31 -0600 )edit

it worked for me. So please do try it first. I added both opencv_ffmpeg249.dll and opencv_ffmpeg249_64.dll and it read .avi.

iganelin gravatar imageiganelin ( 2016-01-15 18:12:29 -0600 )edit

Question Tools


Asked: 2013-12-09 03:36:40 -0600

Seen: 6,866 times

Last updated: Dec 09 '13