The problem maybe is with the codec of the camera stream and not with the FPS itself, for example, if your camera only supports YUYV it is probably that you could only work with some specific FPS, try with the app guvcview to check this in a GUI.

Try to change the codec to MJPG and then change the FPS using CAP_PROP_FPS. I'm using a Logitech C922 pro and this works for me to configure 1080p and 30fps, if you have other camera probably yu need to use a lower resolution to achieve 30fps:

import cv2 as cv
def decode_fourcc(v):
    v = int(v)
    return "".join([chr((v >> 8 * i) & 0xFF) for i in range(4)])

def setfourccmjpg(cap):
    oldfourcc = decode_fourcc(cap.get(cv.CAP_PROP_FOURCC))
    codec = cv.VideoWriter_fourcc(*'MJPG')
    res=cap.set(cv.CAP_PROP_FOURCC,codec)
    if res:
        print("codec in ",decode_fourcc(cap.get(cv.CAP_PROP_FOURCC)))
    else:
        print("error, codec in ",decode_fourcc(cap.get(cv.CAP_PROP_FOURCC)))
cap = cv.VideoCapture(CAMERANUM)
cu.setfourccmjpg(cap)
w=1920
h=1080
fps=30
res1=cap.set(cv.CAP_PROP_FRAME_WIDTH,w)
res2=cap.set(cv.CAP_PROP_FRAME_HEIGHT,h)
res3=cap.set(cv.CAP_PROP_FPS,fps)

then resume your normal video capture polling loop.

Answer from Francisco Carlos Calderon on Stack Overflow
🌐
GitHub
github.com › opencv › opencv › issues › 24000
.get(cv2.CAP_PROP_FPS) returns incorrect FPS · Issue #24000 · opencv/opencv
July 17, 2023 - video_capture = cv2.VideoCapture('C:\\Users\\AShetty12\\Downloads\\raw_videos\\MOV_2564.mp4') print(video_capture.isOpened()) # returns True print(video_capture.get(cv2.CAP_PROP_FPS)) # returns 30 total_frames = int(video_capture.get(cv2.CAP_PROP_FRAME_COUNT)) print(total_frames) # returns 21784 print(video_capture.set(cv2.CAP_PROP_POS_AVI_RATIO, 1)) # returns True _ = video_capture.read() time_msec = video_capture.get(cv2.CAP_PROP_POS_MSEC) print(time_msec/(1000*total_frames)) # returns 0.03335926980046518 video_capture.get(cv2.CAP_PROP_POS_FRAMES) # returns 21785.0 · MOV_2564.mp4 · EDIT: Slight change to add the 1000 in the denominator when dividing by total frames to manually calculate fps · I report the issue, it's not a question ·
Discussions

Windows get camera cv2.CAP_PROP_FPS incorrect value for low fps.
System Information Self built Opencv 4.10 for windows with python. Detailed description OpenCV for Windows reports incorrect FPS if Camera was read before and low FPS was set. Steps to reproduce fr... More on github.com
🌐 github.com
1
October 4, 2024
Opencv Camera Properties : CAP_PROP_FOURCC Not working
One of my code related to Fiducial markers detection have following lines : codec = 0x47504A4D # MJPG cap.set(cv2.CAP_PROP_FPS, 30.0) cap.set(cv2.CAP_PROP_FOURCC, codec) cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080) This parameter setting is working fine in ... More on forums.developer.nvidia.com
🌐 forums.developer.nvidia.com
20
0
June 1, 2021
Speeding up frame capture in opencv
You're creating a new thread with every single frame. Just creating the threads, let alone doing something in them, is going to be enough to prevent you from getting to 60 fps. Capture frames in one thread, do your processing / motion detection / etc on another. Don't create them as data is coming in, they should be setup and running when you're pulling frames. More on reddit.com
🌐 r/computervision
17
2
January 15, 2020
set property of cv2.VideoCapture is returning false for cv2.CAP_PROP_FPS
Expected behaviour Write here how did you expect the library to function. if fps rate of a video file is 25 ,i need to read only 10 frames per second so i set fps as 10 using set property cv2.CAP_PROP_FPS , after setting capture.read() o... More on github.com
🌐 github.com
1
January 6, 2020
🌐
GitHub
github.com › opencv › opencv › issues › 21673
cv::VideoCapture set cv::CAP_PROP_FPS is not working · Issue #21673 · opencv/opencv
March 2, 2022 - Please try to use some sample code to setup the fps for web cameras, like: #include "opencv2/videoio.hpp" cv::VideoCapture capture; capture.open("/dev/video0"); bool success = capture.isOpened(); if (success) { capture.set(cv::CAP_PROP_FPS, 25); }
🌐
OpenCV Q&A Forum
answers.opencv.org › question › 219305 › setcv2cap_prop_fps-60-is-not-working-and-camera-feed-lagging
set(cv2.CAP_PROP_FPS, 60) is not working and camera feed lagging - OpenCV Q&A Forum
after set FPS, cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) will throw below error. OpenCV(4.1.1) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'. import cv2 import os toggle = True cap = cv2.VideoCapture(0) cap.set(cv2.CAP_PROP_FPS, 60) while True: ret, frame = cap.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.imshow("image", gray) if toggle: print("testing") os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''') toggle = False if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
🌐
GitHub
github.com › opencv › opencv › issues › 26250
Windows get camera cv2.CAP_PROP_FPS incorrect value for low fps. · Issue #26250 · opencv/opencv
October 4, 2024 - from datetime import datetime,timedelta import cv2 cap = cv2.VideoCapture(0) cap.grab() # Remove this line to get correct real FPS cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) cap.set(cv2.CAP_PROP_BUFFERSIZE, 1) cap.set(cv2.CAP_PROP_FPS, 2) # Set low FPS print("Real fps: ", cap.get(cv2.CAP_PROP_FPS)) for i in range(100): cv2.waitKey(1) cap.grab() # Grab a frame now = datetime.now() print(f'{now.strftime("%M:%S")} ') Typical output: Click to expand · python.exe : [ WARN:0@3.110] global cap_msmf.cpp:929 CvCapture_MSMF::initStream Failed to select stream 0 AB@>:
🌐
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 - The documentation says that get(CAP_PROP_FPS) gives the frames per second. Now that is true for video files, but not for webcams. For webcams and many other connected cameras, you have to calculate the frames per second manually. You can read a certain number of frames from the video and see how much time has elapsed to calculate frames per second. #!/usr/bin/env python import cv2 import time if __name__ == '__main__' : # Start default camera video = cv2.VideoCapture(0); # Find OpenCV version (major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.') # With webcam get(CAP_PROP_FPS) does not work.
🌐
NVIDIA Developer Forums
forums.developer.nvidia.com › robotics & edge computing › jetson systems › jetson nano
Opencv Camera Properties : CAP_PROP_FOURCC Not working - Jetson Nano - NVIDIA Developer Forums
June 1, 2021 - One of my code related to Fiducial markers detection have following lines : codec = 0x47504A4D # MJPG cap.set(cv2.CAP_PROP_FPS, 30.0) cap.set(cv2.CAP_PROP_FOURCC, codec) cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080) This parameter setting is working fine in other hardware platforms.
🌐
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

Find elsewhere
🌐
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?
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
Cannot get frame from cv2 - Raspberry Pi Forums
June 17, 2023 - <class 'cv2.VideoCapture'> True 640 Traceback (most recent call last): File "/home/pi/./bodycam.py", line 21, in <module> cv2.imwrite("/home/pi/test.png", img) cv2.error: OpenCV(4.7.0) /io/opencv/modules/imgcodecs/src/loadsave.cpp:783: error: (-215:Assertion failed) !_img.empty() in function 'imwrite' So it means that the camera is opend and works but the cap.read() fails. I get the same error from lokal or ssh console. What could this be? Thanks? Edit: if I try fps = int(cap.get(cv2.CAP_PROP_FPS)) it gives me an error it can not get camera fps.
🌐
GitHub
github.com › opencv › opencv › issues › 21006
VideoCapture.get(cv::CAP_PROP_FPS) is wrong for some special video · Issue #21006 · opencv/opencv
November 4, 2021 - System information (version) OpenCV => 4.5.0 Operating System / Platform => MacOS 12.0.1 Compiler => clang 12.0.5 Detailed description The FPS get from VideoCapture.get(cv::CAP_PROP_FPS) is wrong. The coding as following: cv::VideoCaptur...
Top answer
1 of 3
22

The get() for CAP_PROP_FRAME_COUNT is never supposed to be accurate! If you check the opencv source code. You can find this:

int64_t CvCapture_FFMPEG::get_total_frames() const
{
    int64_t nbf = ic->streams[video_stream]->nb_frames;

    if (nbf == 0)
    {
        nbf = (int64_t)floor(get_duration_sec() * get_fps() + 0.5);
    }
    return nbf;
}

This means it will first look into the stream header for nb_frames, which you can check with ffprobe. If there is no such field, then there is no better way to get frame number than directly decoding the video. The opencv did a rough estimation by get_duration_sec() * get_fps() + 0.5 which surely not mean for accuracy.

Thus, to obtain the correct frame number you have to decode and read through the entire stream, or you have to ask the video generator to generate correct stream header with nb_frames field.

It is unfortunately to see after almost 10 years opencv still does not correct the implementation: we should use av_read_frame(fmt_ctx, &pkt) to read and parse all packet without actual decode them.

I personally stopped relies on opencv for video decoding more than 10 years ago, but recently I have to collaborate with some project using opencv to do so. I have to call ffprobe in a subprocess to get the correct frame counts:

ffprobe -v error -select_streams v:0 -count_packets -show_entries stream=nb_read_packets -of csv=p=0 input.mp4
2 of 3
9

CV_CAP_PROP_FRAME_COUNT gives the property of 'number of frames', that comes from the video header. The other number is basically "How many frames can I read from this video file?".

If the video contains frames that cannot be read/decoded (e.g., due to being corrupted), OpenCV skips those frames (after trying to read them) and gives you the next valid frame. So the difference between your two numbers is the number of frames that couldn't be read.

Also, if your video header is corrupted and/or cannot be parsed by the underlying codecs that OpenCV uses, then those numbers can be different too.

🌐
ProgramCreek
programcreek.com › python › example › 89372 › cv2.CAP_PROP_FPS
Python Examples of cv2.CAP_PROP_FPS
def __init__(self, infile=0, fps=15.0): self.cam = cv2.VideoCapture(infile) self.cam.set(cv2.CAP_PROP_FPS, fps) self.cam.set(cv2.CAP_PROP_FRAME_WIDTH, IMAGE_WIDTH) self.cam.set(cv2.CAP_PROP_FRAME_HEIGHT, IMAGE_HEIGHT) ... def detect_video(yolo, video_path, output_path=""): import cv2 vid = cv2.VideoCapture(video_path) if not vid.isOpened(): raise IOError("Couldn't open webcam or video") video_FourCC = int(vid.get(cv2.CAP_PROP_FOURCC)) video_fps = vid.get(cv2.CAP_PROP_FPS) video_size = (int(vid.get(cv2.CAP_PROP_FRAME_WIDTH)), int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT))) isOutput = True if output_path != "" else False if isOutput: print("!!!
🌐
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 - # import modules import cv2 from google.colab import files from google.colab.patches import cv2_imshow # open file cap = cv2.VideoCapture('/content/video.mp4') # get FPS of input video fps = cap.get(cv2.CAP_PROP_FPS) # define output video and it's FPS output_file = 'output.mp4' output_fps = fps * 2 # define VideoWriter object fourcc = cv2.VideoWriter_fourcc(*'mp4v') out = cv2.VideoWriter(output_file, fourcc, output_fps, (int(cap.get(3)), int(cap.get(4)))) # read and write frams for output video while cap.isOpened(): ret, frame = cap.read() if not ret: break out.write(frame) # release resources cap.release() out.release() cv2.destroyAllWindows() # download output video on local machine files.download(output_file) Output: The video with faster FPS will be downloaded on your local machine.
🌐
NVIDIA Developer Forums
forums.developer.nvidia.com › robotics & edge computing › jetson systems › jetson nano
cv2.VideoCapture [gstreamer] issues - Jetson Nano - NVIDIA Developer Forums
March 3, 2021 - Hi there, I’m attempting to add a gstreamer capture and output to my python script utilising open CV but I’m struggling to find success. cap = cv2.VideoCapture('v4l2src device=“/dev/video0” ! “video/x-raw, width=640, height=480, format=(string)YUY2” ! videoconvert ! video/x-raw, format=(string)BGR ! appsink ', cv2.CAP_GSTREAMER) w = cap.get(cv2.CAP_PROP_FRAME_WIDTH) h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) fps = cap.get(cv2.CAP_PROP_FPS) print(‘Src opened, %dx%d @ %d fps’ % (w, h, fps)) gs...