1

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.

The_Doctor
  • 181
  • 5
  • 16
  • Please edit your question to show the [minimal](http://stackoverflow.com/help/mcve) amount of code that reproduces your problem. We can't answer why you're having slow playback until you show the code that produces it. – Aurelius Jun 05 '14 at 23:18
  • sorry, did not think it would be necessary, I am just using bare basics to play a video, no detection or recognition is going on. The frame rate is fine right now, but I mean to dramatically increase the playback using just the minimal amount of code. (almost like watching a video on fast forward)... I will update with a excerpt of my code when I get home. – The_Doctor Jun 05 '14 at 23:24

1 Answers1

1

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

Community
  • 1
  • 1
Ben
  • 441
  • 3
  • 10
  • +1 for mjpeg streaming and decoding, never considered Gstreamer – The_Doctor Jun 07 '14 at 20:22
  • Yes, `VideoCapture` seems to run at maximum speed, but it looks single-threaded, so you may see a speed close to real time and assume that the capture does produce the frames with this speed only. This is what happened in my case. – Tomasz Gandor Dec 16 '16 at 13:47