Ask Your Question
3

VideoCapture doesn't work with video files

asked Dec 9 '13

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 << cap.open(filepath[i]) << endl; //always returns 0
}
Preview: (hide)

1 answer

Sort by » oldest newest most voted
3

answered Dec 9 '13

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

Preview: (hide)

Comments

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 (Dec 9 '13)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 (Jan 16 '16)edit

Question Tools

Stats

Asked: Dec 9 '13

Seen: 8,152 times

Last updated: Dec 09 '13