Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Weird video file playback speed behaviour

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("/home/nghia/Projects/Qt/100k/data/monash2.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

Weird video file playback speed behaviour

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("/home/nghia/Projects/Qt/100k/data/monash2.avi");
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

[SOLVED] Weird video file playback speed behaviour

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