简体   繁体   中英

OpenCV - Dramatically increase frame rate from playback

In OpenCV is there a way to dramatically increase the frame rate of a video (.mp4). I have tried to methods to increase the playback of a video including :

Increasing the frame rate:

cv.SetCaptureProperty(cap, cv.CV_CAP_PROP_FPS, int XFRAMES)

Skipping frames:

for( int i = 0; i < playbackSpeed; i++ ){originalImage = frame.grab();}

&

video.set (CV_CAP_PROP_POS_FRAMES, (double)nextFrameNumber);

is there another way to achieve the desired results? Any suggestions would be greatly appreciated.

Update Just to clarify, the play back speed is NOT slow, I am just searching for a way to make it much faster.

You're using the old API (cv.CaptureFromFile) to capture from a video file.

If you use the new C++ API, you can grab frames at the rate you want. Here is a very simple sample code :

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**)
{
    VideoCapture cap("filename"); // put your filename here

    namedWindow("Playback",1);

    int delay = 15; // 15 ms between frame acquisitions = 2x fast-forward

    while(true)
    {
        Mat frame;
        cap >> frame; 
        imshow("Playback", frame);
        if(waitKey(delay) >= 0) break;
    }

    return 0;
}

Basically, you just grab a frame at each loop and wait between frames using cvWaitKey() . The number of milliseconds that you wait between each frame will set your speedup. Here, I put 15 ms, so this example will play a 30 fps video at approx. twice the speed (minus the time necessary to grab a frame).

Another option, if you really want control about how and what you grab from video files, is to use the GStreamer API to grab the images, and then convert to OpenCV for image tratment. You can find some info about this on this post : MJPEG streaming and decoding

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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