🌐
GitHub
gist.github.com › yoshi4869 › 30a9cf10dd600d2a197c38901001245e
撮影画像のFPSを表示しつつ,定期的に画像を保存する · GitHub
撮影画像のFPSを表示しつつ,定期的に画像を保存する. GitHub Gist: instantly share code, notes, and snippets.
🌐
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
🌐
Mike Polinowski
mpolinowski.github.io › development › python › python - video processing with opencv
Python - Video Processing with OpenCV | Mike Polinowski
Requirement already satisfied: ... has a 1440p resolution and consists of 451 frames that are displayed at a frame rate of 30 fps: python main.py ·...
🌐
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 › 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
Find elsewhere
🌐
GitHub
github.com › opencv › opencv › issues › 21673
cv::VideoCapture set cv::CAP_PROP_FPS is not working · Issue #21673 · opencv/opencv · GitHub
March 2, 2022 - I am using OpenCV library to capture the images from web cameras, and I am able to do that with different capture format (cv::CAP_PROP_FOURCC). But I am facing an issue with setting up frame per second value.
🌐
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 active backend determines how capture properties are obtained and what they mean. Calling video.get(cv2.CAP_PROP_FPS) in Python or video.get(cv::CAP_PROP_FPS) in C++ asks the backend for its FPS property.
🌐
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.
🌐
GitHub
github.com › awslabs › rekognition-video-utils › blob › master › opencv_utils.py
rekognition-video-utils/opencv_utils.py at master · awslabs/rekognition-video-utils · GitHub
fps = video.get(cv2.cv.CV_CAP_PROP_FPS) else: fps = video.get(cv2.CAP_PROP_FPS) print "Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps) · return fps · · def get_all_frames(video, path_output_dir): vidcap = cv2.VideoCapture(video) count = 0 ·
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
github.com › opencv › opencv-python › issues › 618
FPS returned as zero · Issue #618 · opencv/opencv-python · GitHub
January 30, 2022 - Expected behaviour I am working on colab and using a mp4 video (not a webcam stream) as test_video below: cap = cv2.VideoCapture(test_video) fps = cap.get(cv2.CAP_PROP_FPS) This is supposed to retu...
Author: opencv
🌐
FutureLearn
futurelearn.com › home › blog
Extracting video frames using OpenCV
October 25, 2022 - To get this information from a video in OpenCV we need to use the variable CAP_PROP_FPS and the function get as follows: fps = video.get(cv2.CAP_PROP_FPS) print('frames per second =',fps)
🌐
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.