This comes a bit late, but I was wondering this with my Logitech C920 HD Pro USB-camera on Ubuntu 20.04 and OpenCV. I tried to command the capture session to run Full HD @ 30 FPS but the FPS was fluctuating between 4-5 FPS.

The capture format for my camera defaulted as "YUYV 4:2:2". No matter how I tried to alter the video capture settings, OpenCV did not magically change the video format to match e.g. the desired FPS setting.

When I listed the video formats for my Logitech C920, it revealed:

ubuntu:~$ v4l2-ctl --list-formats-ext

ioctl: VIDIOC_ENUM_FMT
    Type: Video Capture

    [0]: 'YUYV' (YUYV 4:2:2)
<clip>
        Size: Discrete 1600x896
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1920x1080
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 2304x1296
            Interval: Discrete 0.500s (2.000 fps)
    [1]: 'MJPG' (Motion-JPEG, compressed)
<clip>
        Size: Discrete 1920x1080
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)

The solution was to manually command the OpenCV capture device to use the compressed 'MJPG' format:

import numpy as np
import cv2

capture = cv2.VideoCapture(0)
W, H = 1920, 1080
capture.set(cv2.CAP_PROP_FRAME_WIDTH, W)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, H)
capture.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
capture.set(cv2.CAP_PROP_FPS, 30)
Answer from Ari J.R. on Stack Overflow
🌐
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 - (source: Wikipedia) Since the .read ... speedup simply by creating a separate thread from our main Python script that is solely responsible for reading frames from the video file and maintaining a queue....
🌐
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.
🌐
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

🌐
Reddit
reddit.com › r/opencv › [question] can you fast forward fps when doing work on video?
r/opencv on Reddit: [Question] Can you fast forward FPS when doing work on video?
September 15, 2020 -

Hey everyone!

I'm doing some work where I need to load in a video file. The work is simple enough, but it still takes a long time to complete due to the video being a long video.

For example if I wanted to work with a video that is 15 minutes long, my program goes through the whole video with a fixed framerate, and takes 15 minutes to complete. So I thought that there must be a better way of doing this. Maybe increasing the frame rate in the original video?

The captured frame rate varies, but is usually 30 fps.

I'm looping over each frame like this:

cap = cv2.VideoCapture("photos/football.mp4")
while(cap.isOpened()):
    ret, frame = cap.read()
    # Do work
vs.release()
cv2.destroyAllWindows()

I hope you understand what I mean, and have some tips that can help me !

Top answer
1 of 4
5

This comes a bit late, but I was wondering this with my Logitech C920 HD Pro USB-camera on Ubuntu 20.04 and OpenCV. I tried to command the capture session to run Full HD @ 30 FPS but the FPS was fluctuating between 4-5 FPS.

The capture format for my camera defaulted as "YUYV 4:2:2". No matter how I tried to alter the video capture settings, OpenCV did not magically change the video format to match e.g. the desired FPS setting.

When I listed the video formats for my Logitech C920, it revealed:

ubuntu:~$ v4l2-ctl --list-formats-ext

ioctl: VIDIOC_ENUM_FMT
    Type: Video Capture

    [0]: 'YUYV' (YUYV 4:2:2)
<clip>
        Size: Discrete 1600x896
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1920x1080
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 2304x1296
            Interval: Discrete 0.500s (2.000 fps)
    [1]: 'MJPG' (Motion-JPEG, compressed)
<clip>
        Size: Discrete 1920x1080
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.133s (7.500 fps)
            Interval: Discrete 0.200s (5.000 fps)

The solution was to manually command the OpenCV capture device to use the compressed 'MJPG' format:

import numpy as np
import cv2

capture = cv2.VideoCapture(0)
W, H = 1920, 1080
capture.set(cv2.CAP_PROP_FRAME_WIDTH, W)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, H)
capture.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
capture.set(cv2.CAP_PROP_FPS, 30)
2 of 4
2

In my case, I have set camera like this (in c++ code):

// cam is cv::VideoCapture object
cam.set(cv::CAP_PROP_BUFFERSIZE, 1);
cam.set(cv::CAP_PROP_FPS, 20); // set fps before set fourcc
cam.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'));

CAP_PROP_BUFFERSIZE doesn't matter, but CAP_PROP_FPS must be set before CAP_PROP_FOURCC.
By this setup, my camera fps increases from 5 to 20.

🌐
GitHub
github.com › kkdai › bookmarks › issues › 43
Faster video file FPS with cv2.VideoCapture and OpenCV · Issue #43 · kkdai/bookmarks
June 2, 2017 - Faster video file FPS with cv2.VideoCapture and OpenCV #43 · Copy link · Labels · Pythonopencv · kkdai · opened · on Jun 2, 2017 · Issue body actions · link build rtsp streaming server server using · No one assigned · Pythonopencv · No projects · No milestone ·
Author: kkdai
🌐
Stack Overflow
stackoverflow.com › questions › 69620079 › video-recording-is-too-fast-in-opencv
python - Video Recording is too fast in opencv - Stack Overflow
I'm capturing video from my video file using OpenCV on linux. It works fine but when I try to play my captured video it plays too fast. i.e. I capture from video for 10 seconds but when I play on the video is 8 seconds. ... def save_frames(video_file, path_in): cap = cv2.VideoCapture(video_file) length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) fps = cap.get(cv2.CAP_PROP_FPS) count = 1 while cap.isOpened(): ret, frame = cap.read() cv2.imwrite(path_in + "frame{}.jpg".format(str(count).zfill(5)), frame) if cv2.waitKey(1) & 0xFF == ord('q'): break count += 1 cap.release() cv2.destroyAllWindows() return fps
🌐
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.
Find elsewhere
🌐
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 ...
Top answer
1 of 1
1

TL;DR FPS is irrelevant to the problem, probably a performance issue

What FPS is used for? Before you can display a single frame of video, you have to read the data (from an HDD, DVD, Network, Internet or whatever) and decode it. Both of these operations take time, the amount of which differs from system to system, depending on the speed of HDD/Internet, processor speed etc. If we just display each frame as soon as it's ready, the resulting movie speed will, therefore, vary from system to system. That is usually not what we want, so along with the sequence of video frames we get the "frames per second" value (a. k. a. FPS), which tells us how soon we shall display each consecutive frame (once every 1/30-th of a second for 30 FPS, once every 1/60-th of a second for 60 FPS, etc.) If the frame is ready to be displayed but it's too early, we can wait till its time comes. If it's time to display a frame but it's not ready (on an underpowered/too busy system), there's not much we can do (maybe drop frames in some situations). To see the effect for yourself, try changing the FPS value for x2, saving the file and display it with VLC: for the same amount of data and same number of frame, you will notice that the speed of your video has doubled and the time - halved. Try writing each frame twice for your x2 FPS - you will see that the playback speed is back to normal (with double the number of frames and meaningless increase of the file size).

What FPS is not used for? When processing (not displaying) a video, we are not limited by the original FPS, and the processing goes as fast as it can. If your PC can process 1000 frames per second - good, if 1500 - even better. Needless to say, changing the FPS value in the file won't improve your CPU/HDD speed, so if you were only able to process 54 frames per second, you are still going to be able to only process 54 frames per second.

But how can VLC display faster? Assuming you didn't forget to switch from Debug to Release build before measuring time, there are still a number of possibilities: VLC is probably better optimized for the particular task of video playback (OpenCV is not really that fast at some tasks, plus it has to convert each frame to a more general Mat/UMat structure), multithreading (including "double buffering", as mentioned in the comments) is another possible reason, maybe caching as well (e. g. reading a block of data containing many frames from the HDD at once instead of reading and processing frames one by one).

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
🌐
NVIDIA Developer Forums
forums.developer.nvidia.com › robotics & edge computing › jetson systems › jetson tx2
How to increase the speed of Opencv "capture >> frame" - Jetson TX2 - NVIDIA Developer Forums
July 9, 2017 - Hi folks, I am testing the TX2’s onboard CSI camera using Opencv3.2 with Gstreamer pipeline. Here is part of the code: ... src_selection = "nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)I420, framerate=(fraction)60/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink"; VideoCapture capture; capture.open(src_selection); CV_Assert(capture.isOpened()); Mat frame_cpu; clock_t t1; wh...
🌐
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…
🌐
Stack Overflow
stackoverflow.com › questions › 67374788 › why-is-opencv-videocapture-reading-frames-4-times-faster-than-fps-for-my-hls-str
python - Why is OpenCV VideoCapture reading frames 4 times faster than FPS for my HLS stream - Stack Overflow
... OpenCV reads the frames as fast as possible. Example: when reading video frames from a local video file, the reading rate does not depend on the FPS of the video file (reading at 100fps from 1fps video file is normal).
🌐
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
How do I get the aspect ratio of a pixel using OpenCV? ... Use cv2.waitKey(delayTime) in the loop where you are capturing the frames. This delayTime is in Mili seconds. More the delayTime less will be the fps.
🌐
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 - In OpenCV the class VideoCapture handles reading videos and grabbing frames from connected cameras. There is a lot of information you can find about the video file you are playing by using the get(PROPERTY_NAME) method in VideoCapture. One of the common properties you may want to know is to find frame rate or frames per second.
🌐
GeeksforGeeks
geeksforgeeks.org › 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
January 4, 2023 - import numpy as np import cv2 import time # creating the videocapture object # and reading from the input file # Change it to 0 if reading from webcam cap = cv2.VideoCapture('vid.mp4') # used to record the time when we processed last frame prev_frame_time = 0 # used to record the time at which we processed current frame new_frame_time = 0 # Reading the video file until finished while(cap.isOpened()): # Capture frame-by-frame ret, frame = cap.read() # if video finished or no Video Input if not ret: break # Our operations on the frame come here gray = frame # resizing the frame size according to
🌐
OpenCV
forum.opencv.org › python
OpenCV VideoCapture recording is sped up - Python - OpenCV
September 29, 2024 - My webcam supports compressed (MJPG) ... due to the faster fps. I have simplified my code (below) and have reproduced the issue. import cv2 from datetime import datetime, timedelta fourcc = cv2.VideoWriter_fourcc(*'avc1') fn = "out.mp4" cap = cv2.VideoCapture(0, cv2.CAP_V4L2) ...