简体   繁体   中英

cvQueryFrame(capture) always returns null

Does anyone know why I keep getting null frames? I tried skipping the first five and still null.

int _tmain(int argc, char** argv)
{
CvCapture *capture  = cvCaptureFromFile(argv[1]);

int fps = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
IplImage* frame;
cvNamedWindow("video", CV_WINDOW_AUTOSIZE);
while(1)
{
    frame = cvQueryFrame(capture);
    if(!frame)
        break;
    cvShowImage("video", frame);
    char c = cvWaitKey(1000/fps);
    if(c == 33)
        break;
}
cvReleaseCapture( &capture);
cvDestroyWindow( "video" );

return 0;
}

Video file must UNCOMPRESSED avi! So actually I was getting null frames because cvCapture returned a null because my input video file was not uncompressed.

I use your code for test, then it run well with 'xvid' format video. I think OpenCV 'capture' function maybe process some popular and old format of videos. Video with format "H264" may be not work.

When cvCaptureFromFile() fails it returns NULL , and I suspect it is failing:

CvCapture *capture  = cvCaptureFromFile(argv[1]);
if (!capture)
{
    // print error, quit application
}

It usually fails for one of these reasons: either it can't find the file, or OpenCV doesn't know how to open it. For instance, .mkv files are not supported by OpenCV.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM