Ask Your Question

Skipping frames in VideoCapture

asked 2013-11-28 14:49:36 -0500

mrzl gravatar image

updated 2016-01-01 14:30:30 -0500

I'm doing some motion detection on a video and while doing the processing, it sometimes is handy to simply skip a couple of frames in order to have a bigger impact on the e.g. optical flow detection. Currently I'm simply loading frames in a loop like that:

for( int i = 0; i < playbackSpeed; i++ )
    originalImage = videoReader.getNextImage();

Though I'd much rather just skip a couple of frames instead of just loading more, because doing this ends up in a little performance problem. Cheers for the help.


edit retag flag offensive close merge delete


What is your hardware and os? What implementation of cv::VideoCapture do you use?

Alexander Smorkalov gravatar imageAlexander Smorkalov ( 2013-11-29 00:56:29 -0500 )edit

I'm using Win8 64bit with the standard cv::VideoCapture implementation ( not sure what you mean ) with opencv version 2.4.7

mrzl gravatar imagemrzl ( 2013-12-13 09:55:52 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2013-11-28 18:40:58 -0500

Will Stewart gravatar image

updated 2014-01-23 05:32:38 -0500

Assuming you are using VideoCapture in HighGUI, you can do n number of frame grabs, without actually loading the images;

"The methods/functions grab the next frame from video file or camera and return true (non-zero) in the case of success."

This way you can quickly bypass however many frames you want. I do that in a loop with a parameter that I can pass in, in order to make adjustments during execution.

edit flag offensive delete link more

answered 2018-10-03 06:43:23 -0500

raghuk gravatar image

Again, assuming you are using VideoCapture in HighGUI, you can do set the CAP_PROP_POS_FRAMES property before grabbing/reading the frames. That way the next frame to be read will be from that frame onwards.

Using this method you can set the CV_CAP_PROP_POS_FRAMES property to the frame number you want to quickly bypass however many frames you want. For example, in python 3 you would do it as:

import cv2
cap = cv2.VideoCapture('path/to/video/file')
start_frame_number = 50
cap.set(cv2.CAP_PROP_POS_FRAMES, start_frame_number)

# Now when you read the frame, you will be reading the 50th frame
success, frame =
edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2013-11-28 14:49:36 -0500

Seen: 35,077 times

Last updated: Jan 23 '14