Ask Your Question
0

[SOLVED] Weird video file playback speed behaviour

asked 2013-07-17 09:25:21 -0600

Nghia gravatar image

updated 2013-07-19 20:21:40 -0600

Hi all,

I have this issue where I'm trying to read frames from a H.264 video as fast possible. The problem is that the read speed seems to be capped to the frame per second of the video (30fps), which I would not expect to be so. My machine is capable of playing the video much faster, tested it with mplayer -fps 120 and it ran fine.

The second is if I pause the frame grabbing for a few seconds and try again it reads much faster, as if it's trying to catch up for lost time, then returns back to the original frame rate. Here's the code I used for testing

VideoCapture vid("video.avi");
Mat img;

// First 300
chrono::time_point<std::chrono::system_clock> start, end;
start = chrono::system_clock::now();

for(int i=0; i < 300; i++) {
    vid.read(img);
}

end = std::chrono::system_clock::now();
int elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
cout << "First 300 frames - elapsed " << elapsed <<  " ms" << endl;

// Wait a bit ...
cout << "Sleep 10 seconds" << endl;
sleep(10);


// Next 300
start = std::chrono::system_clock::now();

for(int i=0; i < 300; i++) {
    vid.read(img);
}

end = chrono::system_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
cout << "Next 300 frames - elapsed " << elapsed << " ms" << endl;

The output is

First 300 frames - elapsed 9996 ms
Sleep 10 seconds
Next 300 frames - elapsed 592 ms
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-07-19 20:20:43 -0600

Nghia gravatar image

Solved, OpenCV wasn't using FFMPEG to handle the videos, probably using Gstreamer. Compiled the latest FFMPEG and OpenCV again. Now the video plays as fast as possible.

edit flag offensive delete link more

Comments

Feel free to accept your answer in stead of using the [SOLVED] brackets. This way the Q&A forum has a uniform structure!

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-20 03:20:34 -0600 )edit

Question Tools

Stats

Asked: 2013-07-17 09:25:21 -0600

Seen: 2,680 times

Last updated: Jul 19 '13