简体   繁体   中英

How to play a video using opencv?

I'm trying to play a video using opencv (the video is an avi file stored on the disk). However, the program stops execution on the following line in cap_ffmppeg.cpp :

if(!ffmpegCapture ||
   !icvRetrieveFrame_FFMPEG_p(ffmpegCapture,&data,&step,&width,&height,&cn))
   return 0;

The error is: Access violation reading location ... so a seg fault is occurring the first time capture >> frame is run.

Here is the program:

#include<iostream>
#include<fstream>
#include<cv.h>
#include<highgui.h>
#include<opencv2/nonfree/features2d.hpp>
using namespace std;
using namespace cv;


int main(int argc, char *argv[])
{
    if (argc <= 1)
    {
        printf("Usage: %s video\n", argv[0]);
        return -1;
    }

    VideoCapture capture(argv[1]);


    if(!capture.isOpened())
    {
        printf("Failed to open the video\n");
        return -1;
    }

    for(;;)
    {
        Mat frame;
        capture >> frame; // get a new frame from camera
    }

    return 0;
}

Any idea what I'm doing wrong?

if your using x64. Please use opencv_ffmpeg245_64.dll this solves may solve the problem. Or rename opencv_ffmpeg245_64.dll to opencv_ffmpeg245 may solve the problem.

Turned out that OpenCV couldn't play the uncompressed video. Compressed it and all is well... don't know why the original problem exists tho.

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