播放视频以校正速度

播放视频以校正速度

本文介绍了使用 OpenCV 播放视频以校正速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在播放视频文件时遇到问题,为什么它是慢动作?我怎样才能让它正常速度?

I have problem with plying video file, why it is slow motion ?How can I make it normal speed?

#include"opencv2/opencv.hpp"
using namespace cv;

int main(int, char**)
{
    VideoCapture cap("eye.mp4");
    // open the default camera
    if (!cap.isOpened())
        // check if we succeeded
        return -1;

    namedWindow("Video", 1);
    while (1)
    {
        Mat frame;
        cap >> frame;
        imshow("Video", frame);
        if (waitKey(10) == 'c')
            break;
    }
    return 0;
}

推荐答案

VideoCapture 不是为播放而构建的,它只是一种从视频文件或相机中抓取帧的方法.其他支持播放的库,例如 GStreamer 或 Directshow,它们设置了一个控制播放的时钟,以便可以将其配置为尽可能快地播放或使用原始帧率.

VideoCapture isn't built for playback, it's just a way to grab frames from video file or camera. Other libraries that supports playback, such as GStreamer or Directshow, they set a clock that control the playback, so that it can be configured to play as fastest as possible or use the original framerate.

在您的代码段中,帧之间的间隔来自读取帧所需的时间和 waitKey(10).尝试使用 waitKey(0),它至少应该播放得更快.理想情况下,您可以使用 waitKey(1/fps).

In your snippet, the interval between frames comes from the time it takes to read a frame and the waitKey(10). Try using waitKey(0), it should at least play faster. Ideally, you could use waitKey(1/fps).

这篇关于使用 OpenCV 播放视频以校正速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 00:25