3

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; 
}
1
  • try adding cap.set(CAP_PROP_FPS, some_value); before the while loop. This should change the fps of the video (if supported) Commented Oct 21, 2015 at 12:58

1 Answer 1

2

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.

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).

Sign up to request clarification or add additional context in comments.

4 Comments

waitKey(0) waits until a key pressed.
You're right. It could be waitKey(1), because it needs to get the 'c' key. Otherwise just remove waitKey().
I have tried to remove waitKey and set it to (1) , but still very slow speed
Could it be something about the video file? Have you tried other videos, other formats and other resolutions? Also, did you check CPU/RAM usage? Isn't it saturating? Which OS are you on? OpenCV uses ffmpeg, try using ffplay to play the video, maybe there's something wrong with ffmpeg. Also, are you running debug or release (optimized) code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.