#!/usr/bin/env python3 import argparse import sys from pathlib import Path import cv2 as cv parser = argparse.ArgumentParser(description="Capture frames from a recorded video.") parser.add_argument("video", type=Path, help="path to a recorded video file") parser.add_argument("--frames", type=int, default=60, help="number of frames to capture") args = parser.parse_args() if not args.video.is_file(): sys.exit(f"Video file not found: {args.video}") if args.frames < 1: sys.exit("Frame count must be at least 1") capture = cv.VideoCapture(str(args.video)) if not capture.isOpened(): sys.exit(f"Cannot open video: {args.video}") backend = capture.getBackendName() frames_captured = 0 frame_size = None try: while frames_captured < args.frames: ok, frame = capture.read() if not ok or frame is None: sys.exit( f"Cannot read frame {frames_captured + 1} from {args.video}" ) frames_captured += 1 frame_size = (frame.shape[1], frame.shape[0]) finally: capture.release() width, height = frame_size print(f"Video: {args.video}") print(f"Backend: {backend}") print(f"Frames captured: {frames_captured}") print(f"Frame size: {width}x{height}")