简体   繁体   English

如何使用OpenCV以固定帧率(fps)播放任何视频?

[英]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)? OpenCV中是否有任何方式或功能允许我们以固定帧速率(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? 不同的视频可能有不同的帧速率,但通过使用OpenCV库我们可以按照我们定义的固定帧速率播放它们吗?

Thanks in advance. 提前致谢。

Take a look at this article . 看看这篇文章 It shows how to play back AVI files with OpenCV. 它显示了如何使用OpenCV播放AVI文件。 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. 因此,通过控制fps变量,您可以获得所需的回放率。

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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM