Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play any video with a fixed frame rate (fps) using OpenCV?

Is there any way or function in OpenCV that allows us to play any video with a fixed frame rate(fps)? Different videos may have different frame rates but by using OpenCV library can we play them by a fixed frame rate that we define?

Thanks in advance.

like image 800
Ruhi Akaboy Avatar asked Jun 07 '12 19:06

Ruhi Akaboy


People also ask

How do I check my video frame rate in OpenCV?

Find frame rate (frames per second-fps) in OpenCV (Python/C++) In OpenCV the class VideoCapture handles reading videos and grabbing frames from connected cameras. There is a lot of information you can find about the video file you are playing by using the get(PROPERTY_NAME) method in VideoCapture.

How do I increase FPS on cv2?

Use threading to obtain higher FPS The “secret” to obtaining higher FPS when processing video streams with OpenCV is to move the I/O (i.e., the reading of frames from the camera sensor) to a separate thread. You see, accessing your webcam/USB camera using the cv2.


2 Answers

Take a look at this article. It shows how to play back AVI files with OpenCV. Here, the frame rate is read using

int fps = ( int ) cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );

and the delay is set via

key = cvWaitKey( 1000 / fps );

Hence, by controlling the fps variable, you can get the play back rate you want.

like image 196
Gnosophilon Avatar answered Sep 27 '22 20:09

Gnosophilon


int fps = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
int delay = 1000 / fps;

while (true) {
    clock_t startTime = clock();

    capture.read(frame);
    process();

    imshow("video", frame);

    while (clock() - startTime < delay) {
        waitKey(1);
    }
}
like image 30
ajplockyer Avatar answered Sep 27 '22 20:09

ajplockyer