Skip to content

Commit

Permalink
check fps with ffprobe
Browse files Browse the repository at this point in the history
  • Loading branch information
philipqueen committed Sep 23, 2024
1 parent c5de6a6 commit 39630cb
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion Cameras/test_scripts/file_explore.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import subprocess
import cv2

from pathlib import Path
Expand All @@ -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/"
Expand Down

0 comments on commit 39630cb

Please sign in to comment.