Why can't I open avi video in openCV?

yvetterowe picture yvetterowe · Dec 7, 2011 · Viewed 62k times · Source

I just wrote a simple video reading example with openCV2.3.1, but it seems that I cannot open avi video anyway :(

VideoCapture capture("guitarplaying.avi");
if(!capture.isOpened()){
    std::cout<<"cannot read video!\n";
    return -1;
}
Mat frame;
namedWindow("frame");

double rate = capture.get(CV_CAP_PROP_FPS);
int delay = 1000/rate;

while(true)
{
    if(!capture.read(frame)){
        break;
    }
    imshow("frame",frame);

    if(waitKey(delay)>=0)
        break;
}

capture.release();

I made a breakpoint in std::cout<<"cannot read video!\n" and find that it stopped here every time. So why avi video cannot be opened? Thanks!

Answer

nimcap picture nimcap · Dec 8, 2011

A missing OpenCV's ffmpeg.dll does not generate any warnings/errors in OpenCV 2.3.1, and code fails silently. Make sure that you have proper opencv_ffmpeg*.dll in your path.