Ash Ash - 29 days ago 10x
Python Question

What is the optimal fps to record an OpenCV video at?

I'm tinkering around with OpenCV and I'm having some trouble figuring out what fps I should be recording webcam footage. When I record it at

15 fps
the recorded footage goes much faster than "real life". I was wondering if there is an "optimal" fps at which I can record such that the recording will be exactly as long as the time it took to shoot the video?

Here's the program I'm running (though I think that's irrelevant to the question):

import cv2

cap = cv2.VideoCapture(0)

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
fps = 15.0 # Controls the fps of the video created: todo look up optimal fps for webcam
out = cv2.VideoWriter()

success ='../assets/output.mp4v',fourcc, fps, (1280,720),True)

ret, frame =
if ret==True:
frame = cv2.flip(frame,1)
# write the flipped frame

# If user presses escape key program terminates
userInput = cv2.waitKey(1)
if userInput == 27:

# Release everything if job is finished


Let's say your camera recording with 25 FPS. If you are capturing 15 FPS while your camera is recording with 25 FPS, the video will be approximately 1.6 times faster than real life.

You can find out frame rate with get(CAP_PROP_FPS) or get(CV_CAP_PROP_FPS) but it's invalid unless the source is a video file.

For cameras or webcams you have to calculate(estimate) FPS programmatically:

num_frames = 240; # Number of frames to capture

print "Capturing {0} frames".format(num_frames)

start = time.time()# Start time

# Grab a few frames
for i in xrange(0, num_frames) :
    ret, frame =

end = time.time() # End time

seconds = end - start # Time elapsed
print "Time taken : {0} seconds".format(seconds)

# Calculate frames per second
fps  = num_frames / seconds;
print "Estimated frames per second : {0}".format(fps);

So this program estimates frame rate of your video source by recording first 240 frames as sample and then calculates delta time. Lastly, the result of a simple division gives you the FPS.