From 39630cba187d6889529d58ff69b6b5a79760e745 Mon Sep 17 00:00:00 2001 From: philipqueen Date: Mon, 23 Sep 2024 11:10:01 -0700 Subject: [PATCH] check fps with ffprobe --- Cameras/test_scripts/file_explore.py | 50 +++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/Cameras/test_scripts/file_explore.py b/Cameras/test_scripts/file_explore.py index 3889d24..432d2c2 100644 --- a/Cameras/test_scripts/file_explore.py +++ b/Cameras/test_scripts/file_explore.py @@ -1,3 +1,4 @@ +import subprocess import cv2 from pathlib import Path @@ -14,10 +15,57 @@ def print_video_info(videos_path: Path): print(f"starting datetime: {starting_datetime}") cap = cv2.VideoCapture(str(video_path)) print(f"frame count: {cap.get(cv2.CAP_PROP_FRAME_COUNT)}") - print(f"fps: {cap.get(cv2.CAP_PROP_FPS)}") + print(f"reported fps: {cap.get(cv2.CAP_PROP_FPS)}") + ffprobe_fps = get_ffprobe_fps( + video_path + ) + print(f"ffprobe fps: {ffprobe_fps}") cap.release() +def get_ffprobe_fps(video_path: Path) -> float: + duration_subprocess = subprocess.run( + [ + "ffprobe", + "-v", + "error", + "-show_entries", + "format=duration", + "-of", + "default=noprint_wrappers=1:nokey=1", + f"{video_path}", + ], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + duration = duration_subprocess.stdout + print(f"duration from ffprobe: {float(duration)} seconds") + + frame_count_subprocess = subprocess.run( + [ + "ffprobe", + "-v", + "error", + "-select_streams", + "v:0", + "-count_frames", + "-show_entries", + "stream=nb_read_frames", + "-of", + "csv=p=0", + f"{video_path}", + ], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + + frame_count = int(frame_count_subprocess.stdout) + + print(f"frame count from ffprobe: {frame_count}") + + return frame_count / float(duration) + + if __name__ == "__main__": # folder_path = Path( # "/Users/philipqueen/Documents/Humon Research Lab/Basler Stuff/calibration_attempt/"