Setting a frame rate doesn't always work like you expect. It depends on two things:

  1. What your camera is capable of outputting.
  2. Whether the current capture backend you're using supports changing frame rates.

So point (1). Your camera will have a list of formats which it is capable of delivering to a capture device (e.g. your computer). This might be 1920x1080 @ 30 fps or 1920x1080 @ 60 fps and it also specifies a pixel format. The vast majority of consumer cameras do not let you change their frame rates with any more granularity than that. And most capture libraries will refuse to change to a capture format that the camera isn't advertising.

Even machine vision cameras, which allow you much more control, typically only offer a selection of frame rates (e.g. 1, 2, 5, 10, 15, 25, 30, etc). If you want a non-supported frame rate at a hardware level, usually the only way to do it is to use hardware triggering.

And point (2). When you use cv.VideoCapture you're really calling a platform-specific library like DirectShow or V4L2. We call this a backend. You can specify exactly which backend is in use by using something like:

cv2.VideoCapture(0 + cv2.CAP_DSHOW)

There are lots of CAP_X's defined, but only some will apply to your platform (e.g CAP_V4L2 is for Linux only). On Windows, forcing the system to use DirectShow is a pretty good bet. However as above, if your camera only reports it can output 30fps and 60fps, requesting 10fps will be meaningless. Worse, a lot of settings simply report True in OpenCV when they're not actually implemented. You've seen that most of the time reading parameters will give you sensible results though, however if the parameter isn't implemented (e.g exposure is a common one that isn't) then you might get nonsense.

You're better off waiting for a period of time and then reading the last image.

Be careful with this strategy. Don't do this:

while capturing:
    res, image = cap.read()
    time.sleep(1)

you need to make sure you're continually purging the camera's frame buffer otherwise you will start to see lag in your videos. Something like the following should work:

frame_rate = 10
prev = 0

while capturing:

    time_elapsed = time.time() - prev
    res, image = cap.read()

    if time_elapsed > 1./frame_rate:
        prev = time.time()

        # Do something with your image here.
        process_image()

For an application like a hand detector, what works well is to have a thread capturing images and the detector running in another thread (which also controls the GUI). Your detector pulls the last image captured, runs and display the results (you may need to lock access to the image buffer while you're reading/writing it). That way your bottleneck is the detector, not the performance of the camera.

Answer from Josh on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › faster-video-file-fps-with-cv2-videocapture-and-opencv
Faster video file FPS with cv2.VideoCapture and OpenCV - GeeksforGeeks
July 23, 2025 - To increase the video FPS in Python, we will use cv2.VideoCapture function of the OpenCV library. This can be done by reading the frames of the input video at a certain FPS and writing them to an output video file at a higher FPS.
Top answer
1 of 6
47

Setting a frame rate doesn't always work like you expect. It depends on two things:

  1. What your camera is capable of outputting.
  2. Whether the current capture backend you're using supports changing frame rates.

So point (1). Your camera will have a list of formats which it is capable of delivering to a capture device (e.g. your computer). This might be 1920x1080 @ 30 fps or 1920x1080 @ 60 fps and it also specifies a pixel format. The vast majority of consumer cameras do not let you change their frame rates with any more granularity than that. And most capture libraries will refuse to change to a capture format that the camera isn't advertising.

Even machine vision cameras, which allow you much more control, typically only offer a selection of frame rates (e.g. 1, 2, 5, 10, 15, 25, 30, etc). If you want a non-supported frame rate at a hardware level, usually the only way to do it is to use hardware triggering.

And point (2). When you use cv.VideoCapture you're really calling a platform-specific library like DirectShow or V4L2. We call this a backend. You can specify exactly which backend is in use by using something like:

cv2.VideoCapture(0 + cv2.CAP_DSHOW)

There are lots of CAP_X's defined, but only some will apply to your platform (e.g CAP_V4L2 is for Linux only). On Windows, forcing the system to use DirectShow is a pretty good bet. However as above, if your camera only reports it can output 30fps and 60fps, requesting 10fps will be meaningless. Worse, a lot of settings simply report True in OpenCV when they're not actually implemented. You've seen that most of the time reading parameters will give you sensible results though, however if the parameter isn't implemented (e.g exposure is a common one that isn't) then you might get nonsense.

You're better off waiting for a period of time and then reading the last image.

Be careful with this strategy. Don't do this:

while capturing:
    res, image = cap.read()
    time.sleep(1)

you need to make sure you're continually purging the camera's frame buffer otherwise you will start to see lag in your videos. Something like the following should work:

frame_rate = 10
prev = 0

while capturing:

    time_elapsed = time.time() - prev
    res, image = cap.read()

    if time_elapsed > 1./frame_rate:
        prev = time.time()

        # Do something with your image here.
        process_image()

For an application like a hand detector, what works well is to have a thread capturing images and the detector running in another thread (which also controls the GUI). Your detector pulls the last image captured, runs and display the results (you may need to lock access to the image buffer while you're reading/writing it). That way your bottleneck is the detector, not the performance of the camera.

2 of 6
7

I could not set the FPS for my camera so I manage to limit the FPS based on time so that only 1 frame per second made it into the rest of my code. It is not exact, but I do not need exact, just a limiter instead of 30fps. HTH

import time

fpsLimit = 1 # throttle limit
startTime = time.time()
cv = cv2.VideoCapture(0)
While True:
    frame = cv.read
    nowTime = time.time()
    if (int(nowTime - startTime)) > fpsLimit:
        # do other cv2 stuff....
        startTime = time.time() # reset time
Discussions

python - Changing FPS in OpenCV - Stack Overflow
You set the FPS for the output ... to set the FPS for the input via the VideoCapture. In order to do that you can try to call cv2.VideoCapture, with the cv2.CAP_PROP_FPS property after you create cap. For example: ... However - note that the actual behavior is dependant on the specific capture device you are using. Some support only certain FPSs. See also this post regarding it: change frame rate in opencv ... More on stackoverflow.com
🌐 stackoverflow.com
Capture speed / framerate of cv2.VideoCapture - Python - OpenCV
Hi all, I’ve been playing around with python, opencv, a raspberry 4 and a “pi hq cam”. The thing is, the time it takes to capture is really long. The pi cam could, in theory, do 1920x1080@30fps. I’m not aiming for that but what I’m getting is more like 2-3 fps when using videocapture. More on forum.opencv.org
🌐 forum.opencv.org
0
October 16, 2021
How to modify the FPS of a video when using cv::VideoCapture to read frames - C++ - OpenCV
Using cv::VideoCapture to process videos. Wondering what the technique is for changing the frame rate when I write out a new video. I assume I could do something simple like drop every 2nd frame to cut from 60 FPS to 30 FPS. But is that the right way to do it? More on forum.opencv.org
🌐 forum.opencv.org
0
May 19, 2021
Increase Camera FPS OpenCV python
Hello intelligent people of FRC community! My team is trying to increase the camera fps using built in opencv python functions. The cameras should be able to get 60fps, but we are currently getting only 10fps sadly. T… More on chiefdelphi.com
🌐 chiefdelphi.com
1
0
February 14, 2024
🌐
LearnOpenCV
learnopencv.com › home › find frame rate (frames per second-fps) in opencv (python/c++)
Find frame rate (frames per second-fps) in OpenCV (Python/C++)
July 31, 2026 - This repair makes only the verified technical changes identified in the audit: Use current CAP_PROP_FPS, monotonic timing, warm-up, successful-frame counting, and invalid-metadata handling. In OpenCV the class VideoCapture handles reading videos and grabbing frames from connected cameras.
🌐
PyImageSearch
pyimagesearch.com › home › blog › faster video file fps with cv2.videocapture and opencv
Faster video file FPS with cv2.VideoCapture and OpenCV - PyImageSearch
April 17, 2021 - In the remainder of today’s blog post, I’ll demonstrate how to use threading and a queue data structure to improve your video file FPS rate by over 52%! ... When working with video files and OpenCV you are likely using the cv2.VideoCapture function.
Top answer
1 of 2
2

You set the FPS for the output via the VideoWriter,
but you didn't attempt to set the FPS for the input via the VideoCapture.

In order to do that you can try to call cv2.VideoCapture, with the cv2.CAP_PROP_FPS property after you create cap.
For example:

cap.set(cv2.CAP_PROP_FPS, 3)

However - note that the actual behavior is dependant on the specific capture device you are using. Some support only certain FPSs. See also this post regarding it: change frame rate in opencv 3.4.2.

If it does work you will be able to simplify your code a lot - just capture frames, process them and save (without any manual fps management).

2 of 2
1

This method programmatically sets frames per second. A 6.1mb file was created when frame rate was set for 30fps, and a 0.9mb file when set for 3fps.

#!/usr/bin/env python3

import cv2
import numpy as np
import time
import datetime
import pathlib
import imutils

cap = cv2.VideoCapture(0)

if (cap.isOpened() == False): 
  print("Unable to read camera feed")

capture_duration = 15
frame_per_sec = 30
prev = 0
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
out = cv2.VideoWriter('C:\\videoPy\\LZ\\'outpout.avi',cv2.VideoWriter_fourcc('m','j','p','g'),frame_per_sec, (frame_width,frame_height))
start_time = time.time()
while( int(time.time() - start_time) < capture_duration ): 
#start fps
  time_elapsed = time.time() - prev
  while(time_elapsed > 1./frame_per_sec):                   
        ret, frame = cap.read()
        if not ret:
            break
        if time_elapsed > 1./frame_per_sec:
          prev = time.time()
#end fps
        if ret==True:
          frame = imutils.resize(frame, width=frame_width)
          out.write(frame)
          cv2.imshow('frame',frame) 
        if cv2.waitKey(1) & 0xFF == ord('q'):
          break
        else:
           break

cap.release()
out.release()
 
cv2.destroyAllWindows()
🌐
ProgramCreek
programcreek.com › python › example › 89372 › cv2.CAP_PROP_FPS
Python Examples of cv2.CAP_PROP_FPS
def initialize(self): self.capture = cv2.VideoCapture(self.camera) if not self.capture.isOpened(): print("Error opening video camera") return # cap.set(cv2.CAP_PROP_FPS, 5) self.capture.set(cv2.CAP_PROP_FRAME_WIDTH, self.width) self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, self.height) if self.record: self.videowriter = cv2.VideoWriter(self.filename, cv2.VideoWriter_fourcc('m', 'p', '4', 'v'), 10, (self.width, self.height), isColor=True) Example #6 ·
🌐
Note.nkmk.me
note.nkmk.me › home › python › opencv
Capture video from camera/file with OpenCV in Python | note.nkmk.me
October 19, 2022 - For example, set() is used to change the FPS of a camera, but if the camera itself does not support that FPS, the value may not be changed even if set() returns True. You can get the frames of the video as a NumPy array ndarray with the read() ...
🌐
Quora
quora.com › How-do-I-decrease-the-frames-per-second-in-OpenCV-python
How to decrease the frames per second in OpenCV python - Quora
On Windows, Python sleep resolution and waitKey behavior can limit timing precision; consider multimedia timers or platform-specific APIs for sub-10ms accuracy. Choose the method that fits your needs: accurate pacing (sleep + timer), simplicity (waitKey), lower throughput without slowing capture (skip frames), or hardware-configured FPS (cap.set). ... Sales and solutions for every budget. Call now for a free onsite evaluation! ... Changing fps through opencv ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-displaying-real-time-fps-at-which-webcam-video-file-is-processed-using-opencv
Python - Displaying real time FPS at which webcam/video file is processed using OpenCV - GeeksforGeeks
July 15, 2025 - Now with the help cv2.putText() method we will be printing the FPS on this frame and then displaying this frame with the help of cv2.imshow() function . Code: Python code implementation of the above mentioned approach ... import numpy as np ...
🌐
PyImageSearch
pyimagesearch.com › home › blog › increasing webcam fps with python and opencv
Increasing webcam FPS with Python and OpenCV - PyImageSearch
February 20, 2023 - The “secret” to obtaining higher FPS when processing video streams with OpenCV is to move the I/O (i.e., the reading of frames from the camera sensor) to a separate thread. You see, accessing your webcam/USB camera using the cv2.VideoCapture ...
🌐
OpenCV Q&A Forum
answers.opencv.org › question › 214375 › changing-the-fps-of-a-video
changing the fps of a video? - OpenCV Q&A Forum
You are using two different flags cv2.CV_CAP_PROP_FPS and cv2.CAP_PROP_FPS. The correct flag is cv2.CAP_PROP_FPS and change it to so when setting your cap.
🌐
OpenCV
forum.opencv.org › python
Capture speed / framerate of cv2.VideoCapture - Python - OpenCV
October 16, 2021 - Hi all, I’ve been playing around with python, opencv, a raspberry 4 and a “pi hq cam”. The thing is, the time it takes to capture is really long. The pi cam could, in theory, do 1920x1080@30fps. I’m not aiming for that but what I’m getting is more like 2-3 fps when using videocapture.
🌐
OpenCV
forum.opencv.org › c++
How to modify the FPS of a video when using cv::VideoCapture to read frames - C++ - OpenCV
May 19, 2021 - Using cv::VideoCapture to process videos. Wondering what the technique is for changing the frame rate when I write out a new video. I assume I could do something simple like drop every 2nd frame to cut from 60 FPS to 3…
🌐
FutureLearn
futurelearn.com › home › blog
Extracting video frames using OpenCV
October 25, 2022 - If we want a frame from a particular ... or fps. To get this information from a video in OpenCV we need to use the variable CAP_PROP_FPS and the function get as follows:...
🌐
Chief Delphi
chiefdelphi.com › technical
Increase Camera FPS OpenCV python - Technical - Chief Delphi
February 14, 2024 - My team is trying to increase the camera fps using built in opencv python functions. The cameras should be able to get 60fps, but we are currently getting only 10fps sadly. This is what we’ve tried so far: while True: cap = cv.VideoCapture(path) cap:cv.VideoCapture cap.set(cv.CAP_PROP_FRAME_WIDTH, 1280) cap.set(cv.CAP_PROP_FRAME_HEIGHT, 720) cap.set(cv.CAP_PROP_FPS, 30) cap.set(cv.CAP_PROP_FOURCC, cv.VideoWriter_fourcc('M', 'J', 'P', 'G')) if cap.isOpened(): print("open") return cap else: sleep(0.001)
🌐
Reddit
reddit.com › r/computervision › speeding up frame capture in opencv
r/computervision on Reddit: Speeding up frame capture in opencv
January 15, 2020 -

I'm working on an application in python using opencv for use in athletic coaching. I'd like it to run at 60fps, but I can't seem to get it to that speed. I've determined that the part that is slowing everything down is the capture process; frames aren't getting from the camera to the cpu fast enough. All testing I've done so far indicates that the processing and the rendering are not the bottleneck; it's specifically the video input that is slowing everything down.

Now, I know it is possible for the camera to run at 60fps, because when I open up the same camera in guvcview (at the same resolution), I can get a full 60fps.

I don't want to share my entire project, but here's the part that manages frame capture: https://pastebin.com/nnx32rQK. My main app calls the get_frame() function in its own thread. I'm running this on an intel NUC6CAYH (celeron CPU, 2.3 ghz), running linux.

Any help would be welcome!

EDIT: I went into more detail below, but it looks like having the cap.read() within the Feed class is a whole lot slower than just accessing cap.read() directly..... and I have no idea why

Top answer
1 of 6
77

The following code can accomplish that:

import cv2
cap = cv2.VideoCapture(videopath)
cap.set(cv2.CAP_PROP_POS_FRAMES, frame_number-1)
res, frame = cap.read()

frame_number is an integer in the range 0 to the number of frames in the video.
Notice: you should set frame_number-1 to force reading frame frame_number. It's not documented well but that is how the VideoCapture module behaves.

One may obtain amount of frames by:

amount_of_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)
2 of 6
57

Thank you GPPK.

The video parameters should be given as integers. Each flag has its own value. See here for the code.

The correct solution is:

import numpy as np
import cv2

#Get video name from user
#Ginen video name must be in quotes, e.g. "pirkagia.avi" or "plaque.avi"
video_name = input("Please give the video name including its extension. E.g. \"pirkagia.avi\":\n")

#Open the video file
cap = cv2.VideoCapture(video_name)

#Set frame_no in range 0.0-1.0
#In this example we have a video of 30 seconds having 25 frames per seconds, thus we have 750 frames.
#The examined frame must get a value from 0 to 749.
#For more info about the video flags see here: https://stackoverflow.com/questions/11420748/setting-camera-parameters-in-opencv-python
#Here we select the last frame as frame sequence=749. In case you want to select other frame change value 749.
#BE CAREFUL! Each video has different time length and frame rate. 
#So make sure that you have the right parameters for the right video!
time_length = 30.0
fps=25
frame_seq = 749
frame_no = (frame_seq /(time_length*fps))

#The first argument of cap.set(), number 2 defines that parameter for setting the frame selection.
#Number 2 defines flag CV_CAP_PROP_POS_FRAMES which is a 0-based index of the frame to be decoded/captured next.
#The second argument defines the frame number in range 0.0-1.0
cap.set(2,frame_no);

#Read the next frame from the video. If you set frame 749 above then the code will return the last frame.
ret, frame = cap.read()

#Set grayscale colorspace for the frame. 
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

#Cut the video extension to have the name of the video
my_video_name = video_name.split(".")[0]

#Display the resulting frame
cv2.imshow(my_video_name+' frame '+ str(frame_seq),gray)

#Set waitKey 
cv2.waitKey()

#Store this frame to an image
cv2.imwrite(my_video_name+'_frame_'+str(frame_seq)+'.jpg',gray)

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
🌐
OpenCV
forum.opencv.org › python
When cap.read() is not as fast as the FPS of a camera - Python - OpenCV
October 12, 2021 - Hello everyone. I have a question regarding the OpenCV VideoCapture class. Any answer will be helpful. Suppose that we have the following code import cv2 import time cap = cv2.VideoCapture('/dev/video0', cv2.V4L2) cap.set(cv2.CAP_PROP_FPS, 30.0) while True: ret, frame = cap.read() time.sleep(0.1) My question is that, what is actually happening inside the camera when the cap.read() loop is way slower than the actual FPS?
🌐
OpenCV Q&A Forum
answers.opencv.org › question › 209635 › how-can-i-control-webcam-fps
how can i control webcam fps - OpenCV Q&A Forum
February 28, 2019 - I have difficulty handling fps in real-time webcam, not video file. Currently my code always give 30 fps in any resolution like 640 x 480 or 1280 x 720. And I'm using logitech c922 which says it supports 60 fps in 720p (1280 x 720) And I tried 'cap.set(cv2.CAP_PROP_FPS, 60)' where cap is, for example, 'cv2.VideoCapture(0)'. (it's written in python by the way).