Чтобы узнать частоту кадров видео с помощью OpenCV, вы можете использовать несколько методов. Вот несколько подходов:
Метод 1: использование свойства cv2.CAP_PROP_FPS
import cv2
video_path = "path/to/your/video"
# Open the video file
video = cv2.VideoCapture(video_path)
# Get the frame rate
frame_rate = video.get(cv2.CAP_PROP_FPS)
# Release the video file
video.release()
print("Frame rate:", frame_rate)
Метод 2: расчет частоты кадров вручную
import cv2
video_path = "path/to/your/video"
# Open the video file
video = cv2.VideoCapture(video_path)
# Get the total number of frames
total_frames = video.get(cv2.CAP_PROP_FRAME_COUNT)
# Get the duration of the video in seconds
duration = total_frames / frame_rate
# Calculate the frame rate
frame_rate = total_frames / duration
# Release the video file
video.release()
print("Frame rate:", frame_rate)
Метод 3: использование команды ffprobe(требуется FFmpeg)
import subprocess
video_path = "path/to/your/video"
# Run ffprobe command to get the frame rate
result = subprocess.check_output(['ffprobe', '-v', '0', '-of', 'csv=p=0', '-select_streams', 'v:0', '-show_entries', 'stream=r_frame_rate', video_path])
# Parse the output to get the frame rate
frame_rate = eval(result)
print("Frame rate:", frame_rate)