Ask Your Question

Revision history [back]

Similar question then similar answer...

VideoCapture vRead;
vRead.open("G:/Lib/opencv/samples/data/Megamind.avi");
if (!vRead.isOpened())
{
    cout<<"File not found";
    return ;
}
double xFps;
xFps = vRead.get(CV_CAP_PROP_FPS);
cout << "FPS = " << xFps << "\n";
double x = vRead.get(CV_CAP_PROP_FRAME_COUNT);
cout << "# frame = " << x << "\n";
int fourcc = vRead.get(CV_CAP_PROP_FOURCC);
string fourcc_str = format("%c%c%c%c", fourcc & 255, (fourcc >> 8) & 255, (fourcc >> 16) & 255, (fourcc >> 24) & 255);
cout<<"Fourcc "<< fourcc_str<<endl;
cout<<"Time to play : "<< x/xFps<<" s\n";
TickMeter t;
t.start();
bool test=true;
Mat frame;
while (test)
{
    vRead>> frame;
    if (frame.empty())
        test=false;
    else
        imshow("video",frame);
    waitKey(1);
}
t.stop();
cout<<"Play video in "<<t.getTimeMilli()<<" ms\n";
vRead.set(CV_CAP_PROP_POS_FRAMES,0);
test = true;
int nbFrame=0;
t.reset();
t.start();
while (test)
{
    vRead >> frame;

    if (frame.empty())
        test = false;
    else
    {
        nbFrame++;
        imshow("video", frame);
        waitKey(1000 / xFps);
    }
}
t.stop();
cout << "Play video in " << t.getTimeMilli() << " ms\n";