GitHub
github.com › opencv › opencv › issues › 24000
.get(cv2.CAP_PROP_FPS) returns incorrect FPS · Issue #24000 · opencv/opencv · GitHub
July 17, 2023 - System Information OpenCV Python version: 4.8.074 OS: Microsoft Windows 10 Enterprise , version 10.0.19045 Python version: 3.11.4 Detailed description This mp4 video (attached below) has a length of 24:22mins, and a frame rate of 14.9 fp...
GitHub
gist.github.com › barisx › 34f58b4010b0d86b3afe577f458e4788
Detect video fps with OpenCV - Python · GitHub
Detect video fps with OpenCV - Python. GitHub Gist: instantly share code, notes, and snippets.
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 · GitHub
January 6, 2020 - 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
GitHub
github.com › opencv › opencv › issues › 26250
Windows get camera cv2.CAP_PROP_FPS incorrect value for low fps. · Issue #26250 · opencv/opencv · GitHub
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@>:
GitHub
github.com › opencv › opencv › blob › master › samples › python › video_v4l2.py
opencv/samples/python/video_v4l2.py at master · opencv/opencv · GitHub
import cv2 as cv · · def main(): · def decode_fourcc(v): v = int(v) return "".join([chr((v >> 8 * i) & 0xFF) for i in range(4)]) · font = cv.FONT_HERSHEY_SIMPLEX · color = (0, 255, 0) · cap = cv.VideoCapture(0) cap.set(cv.CAP_PROP_AUTOFOCUS, 0) # Known bug: https://github.com/opencv/opencv/pull/5474 · · cv.namedWindow("Video") · convert_rgb = True · fps = int(cap.get(cv.CAP_PROP_FPS)) focus = int(min(cap.get(cv.CAP_PROP_FOCUS) * 100, 2**31-1)) # ceil focus to C_LONG as Python3 int can go to +inf ·
Author: opencv
GitHub
gist.github.com › anujonthemove › e879ef6e2bd3f0ee1743c4c48ef779c1
A handy list of VideoCapture object parameters taken from official OpenCV docs. · GitHub
""" # List of properties to demonstrate properties = { "CAP_PROP_POS_MSEC": cv2.CAP_PROP_POS_MSEC, "CAP_PROP_POS_FRAMES": cv2.CAP_PROP_POS_FRAMES, "CAP_PROP_POS_AVI_RATIO": cv2.CAP_PROP_POS_AVI_RATIO, "CAP_PROP_FRAME_WIDTH": cv2.CAP_PROP_FRAME_WIDTH, "CAP_PROP_FRAME_HEIGHT": cv2.CAP_PROP_FRAME_HEIGHT, "CAP_PROP_FPS": cv2.CAP_PROP_FPS, "CAP_PROP_FOURCC": cv2.CAP_PROP_FOURCC, "CAP_PROP_FRAME_COUNT": cv2.CAP_PROP_FRAME_COUNT, "CAP_PROP_BRIGHTNESS": cv2.CAP_PROP_BRIGHTNESS, "CAP_PROP_CONTRAST": cv2.CAP_PROP_CONTRAST, "CAP_PROP_SATURATION": cv2.CAP_PROP_SATURATION, "CAP_PROP_HUE": cv2.CAP_PROP_HUE,
GitHub
gist.github.com › realphongha › f8db807a9a0fc512ed146786e684cd43
Get FPS of a video using Python, OpenCV and Ffmpeg. · GitHub
Get FPS of a video using Python, OpenCV and Ffmpeg. - get_video_fps.py
GitHub
gist.github.com › renzhezizhi › 36d5493892c419a2e48fc65686ae5062
Open camera and show video stream with Python 2 + OpenCV 2 · GitHub
November 27, 2017 - Open camera and show video stream with Python 2 + OpenCV 2 - open_camera.py
GeeksforGeeks
geeksforgeeks.org › python › how-to-get-properties-of-python-cv2-videocapture-object
How to get properties of Python cv2.VideoCapture object ? - GeeksforGeeks
July 23, 2025 - By knowing the properties of the cv2.VideoCapture object facilitates to do Video Processing ultimately by doing processing on the frames. 1) Width: This property is used to get the width of the frames in the video stream. The measuring unit is in pixels. ... 2) Height: This property is used to get the height of the frames in the video stream. The measuring unit is in pixels. ... 4) Current Position: This property is used to find what is the current position of the video, its measuring unit is milliseconds.
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()
ProgramCreek
programcreek.com › python › example › 89372 › cv2.CAP_PROP_FPS
Python Examples of cv2.CAP_PROP_FPS
def clahe(filename): os.chdir(os.path.dirname(filename)) print('Applying CLAHE, this might take awhile...') currentVideo = os.path.basename(filename) fileName, fileEnding = currentVideo.split('.',2) saveName = str('CLAHE_') + str(fileName) + str('.avi') cap = cv2.VideoCapture(currentVideo) imageWidth = int(cap.get(3)) imageHeight = int(cap.get(4)) fps = cap.get(cv2.CAP_PROP_FPS) fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter(saveName, fourcc, fps, (imageWidth, imageHeight), 0) try: while True: ret, image = cap.read() if ret == True: im = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
GitHub
gist.github.com › megabudino › 6fae6ef5f46e3be5990947c95a41db61
Tiny library to get fps from cv2 video source - Python 3 · GitHub
Tiny library to get fps from cv2 video source - Python 3 · Raw · fps.py · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.