Performing pip install python-opencv fixed the problem and the FPS is correctly detected.

EDIT: tested with python 3.8 and indeed it is pip install opencv-python. Cannot remember two years ago what python I was using.

EDIT November 2022: please also check Perry's answer below, if you are using a newer opencv-python version

Answer from Tasos 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 - OpenCV Python version: 4.8.074 ... Python version: 3.11.4 · This mp4 video (attached below) has a length of 24:22mins, and a frame rate of 14.9 fps when checking the properties of the file in Windows. However, cv2 says that it has 30 fps as shown below. Additionally, when I try to find the length of the video in milliseconds (following this post) to calculate the fps manually, I get 0.033. ... video_capture = ...
🌐
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 - OpenCV for Windows reports incorrect FPS if Camera was read before and low FPS was set. 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_...
Discussions

python - Understanding the function CAP_PROP_FPS in cv2 - Stack Overflow
I am trying to understand the output frames I received using the code below. I am learning to use OpenCV and how it functions. My idea is to get one frame per second in a video. Here are some of the More on stackoverflow.com
🌐 stackoverflow.com
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_P... More on github.com
🌐 github.com
1
January 6, 2020
opencv - python cv2.CAP_PROP_FRAME_COUNT get wrong result, and also the cv2.CAP_PROP_FPS get wrong fps - Stack Overflow
I want to use cv2 to extract frames from a .mkv video file. The following is my code. I get wrong results for fps and frame count. I tried opencv versions 4.7.xx and 4.8.xx but still get the same p... More on stackoverflow.com
🌐 stackoverflow.com
python - OpenCV gives incorrect FPS and frame count of a video - Stack Overflow
I'm trying to read, do some processing and then save an .mp4 video using OpenCV in python, but cap.get(cv2.CAP_PROP_FPS) returns the wrong FPS for some videos. So I'm not gonna go in to the full d... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › opencv › opencv-python › issues › 281
set property of cv2.VideoCapture is returning false for cv2.CAP_PROP_FPS · Issue #281 · opencv/opencv-python
January 6, 2020 - Write here what went wrong. while using capture.set(cv2.CAP_PROP_FPS, 10) it returning false · example code · import cv2 video_url = "https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_5mb.mp4" capture = cv2.VideoCapture(video_url) fps = capture.get(cv2.CAP_PROP_FPS) capture.set(cv2.CAP_PROP_FPS, 10) operating system ubuntu 19.04 · architecture 64 bit · opencv-python version 4.1.2.30 ·
Author: opencv
🌐
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.
🌐
Stack Overflow
stackoverflow.com › questions › 77346241 › python-cv2-cap-prop-frame-count-get-wrong-result-and-also-the-cv2-cap-prop-fps
opencv - python cv2.CAP_PROP_FRAME_COUNT get wrong result, and also the cv2.CAP_PROP_FPS get wrong fps - Stack Overflow
import time import cv2 video_file_name = 'my_video_0.mkv' cap = cv2.VideoCapture(video_file_name) fps = cap.get(cv2.CAP_PROP_FPS) # 1000.0 frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) # -9223372036854775808 · Thank you all for helping me !!! python ·
Find elsewhere
🌐
OpenCV Q&A Forum
answers.opencv.org › question › 204632 › python-opencv-returns-wrong-fps
Python OpenCV returns wrong FPS - OpenCV Q&A Forum
December 3, 2018 - It returned 1000 fps and 60883 total frames. I used following code to find above two. import cv2 cap = cv2.VideoCapture(filename) frames_per_sec = cap.get(cv2.CAP_PROP_FPS) total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) While total number of frames correctly read by the following statement were around 1800.
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
:param cap: OpenCV capture :param time: delta time from launch to skip to :return: index of requested frame """ if thresh is None: thresh = self.extractor.image_dict[key][2] number_of_frames = int(cap.get(cv2.CAP_PROP_FPS) * time) + self.search_switch(cap, key, thresh) number_of_frames = max(number_of_frames, 0) number_of_frames = min(number_of_frames, cap.get(cv2.CAP_PROP_FRAME_COUNT)) cap.set(cv2.CAP_PROP_POS_FRAMES, number_of_frames) return number_of_frames
🌐
Stack Overflow
stackoverflow.com › questions › 70202515 › cv2-cap-getcv2-cap-prop-fps-returns-inf
python - cv2 cap.get(cv2.CAP_PROP_FPS) Returns 'inf' - Stack Overflow
Copyfps = cap.get(cv2.CAP_PROP_FPS) ... is 0x8000_0000_0000_0000 or a float of -0.0. could be a bug, or an error. -- OpenCV is the wrong library....
🌐
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?
🌐
Stack Overflow
stackoverflow.com › questions › 71326277 › opencv-return-fps-as-0-0
python - Opencv return fps as 0.0 - Stack Overflow
Python OpenCV video.get(cv2.CAP_PROP_FPS) returns 0.0 FPS · 1 · Set FPS in opencv 3.x · 4 · OpenCV gives incorrect FPS and frame count of a video · 3 · low fps by using cv2.VideoCapture · 2 · Trouble calculating fps on output video stream · 0 · What causes the measured fps to be different from the expected yet possible fps? 1 · Python/OpenCV - Wrong actual camera FPS or too slow routine ·
🌐
Stack Overflow
stackoverflow.com › questions › 53595354 › python-opencv-returns-wrong-fps
Python OpenCV returns wrong FPS - Stack Overflow
December 3, 2018 - ffmpeg FPS information mismatch with the video · 22 · Python OpenCV video.get(cv2.CAP_PROP_FPS) returns 0.0 FPS · 4 · OpenCV gives incorrect FPS and frame count of a video · 3 · low fps by using cv2.VideoCapture · 2 · Trouble calculating fps on output video stream ·
🌐
GitHub
github.com › opencv › opencv-python › issues › 618
FPS returned as zero · Issue #618 · opencv/opencv-python
January 30, 2022 - cap = cv2.VideoCapture(test_video) fps = cap.get(cv2.CAP_PROP_FPS) This is supposed to return the fps of the video. However the fps it returns it zero as is clear from the ss below · video link: https://drive.google.com/file/d/10zkHWb0OseC1-EBYgaVFLDKx-CKDtk3c/view?usp=sharing ·
Author: opencv
🌐
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 - Thus, the fps for this ts video file is 30, but VideoCapture.get(cv::CAP_PROP_FPS) return 2000.
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
Cannot get frame from cv2 - Raspberry Pi Forums
June 17, 2023 - Edit: if I try fps = int(cap.get(cv2.CAP_PROP_FPS)) it gives me an error it can not get camera fps. Edit2: I went in raspi-config and enabled legacy camera support. Now the python works but libcamera-hello cant find the camera any more. phillipwinter · Posts: 2 · Joined: Fri Aug 11, 2023 4:33 am · Fri Aug 11, 2023 9:20 pm · Hello, As I know, the error message you're encountering indicates that the cap.read() function call is not returning a valid image (_img.empty() is True), causing the imwrite function to fail.