Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible bug in OpenCV2.4 capturing frames from video

Tags:

c++

opencv

ffmpeg

Could it be that there is a bug in OpenCV2.4 highgui for capturing frames from video in windows?

I installed both the precompiled libraries, the ones compiled by me, I can compile everything perfectly and I can run my programs if

they are image based. The problem is only for videos. OpenCV crashes in this function always:

 virtual IplImage* retrieveFrame(int)
    {
        unsigned char* data = 0;
        int step=0, width=0, height=0, cn=0;

        if(!ffmpegCapture ||
           !icvRetrieveFrame_FFMPEG_p(ffmpegCapture,&data,&step,&width,&height,&cn)) <-------CRASHES HERE
           return 0;
        cvInitImageHeader(&frame, cvSize(width, height), 8, cn);
        cvSetData(&frame, data, step);
        return &frame;
    }

This is inside the class cap_ffmpeg.cpp and is called by VideoCapture.

I tried versions 2.4.2 and 2.4.9. My programes were working finde with opencv2


More information

  • Windows 7

  • Build the projects with cmake (important as it could be that cmake is not building/finding the right codecs)

  • VisualStudio 9 2008

  • OpenCV 2.4.2

EDIT

It looks like it is actually a bug, so, how can I solve this problem and change my code to be able to read avi files?

like image 205
Jav_Rock Avatar asked Sep 14 '12 11:09

Jav_Rock


2 Answers

As a temporary solution I decided to re-encode the videos so OpenCV doesn't use the ffmpeg. I used VirtualDub with the microsoft video 1 compression, which uses "msvidc32.dll" driver.

It works with all my videos so it is enough by now as I can keep working with OpenCV in windows.

enter image description here

like image 137
Jav_Rock Avatar answered Nov 15 '22 05:11

Jav_Rock


I had similar problem. I downloaded VirtualDub, but it did not open one of my avi video because of its FMP4 encode. So in the end, the solution that solved the problem was to install ffdshow, a decoder for windows. See this link: http://www.moviecodec.com/video-codecs/fmp4-codec-with-virtualdub-45814/

Then I do not need to use VirtualDub anymore to re-encode my video anymore!

like image 39
Dan Avatar answered Nov 15 '22 07:11

Dan