import subprocess from pathlib import Path def run_cmd(cmd: list[str]) -> None: proc = subprocess.run(cmd, capture_output=True, text=True) if proc.returncode != 0: raise RuntimeError(f"Command failed: {' '.join(cmd)}\nSTDOUT: {proc.stdout}\nSTDERR: {proc.stderr}") def frames_to_video(frames_pattern: str, fps: int, output_video_path: Path) -> None: output_video_path.parent.mkdir(parents=True, exist_ok=True) cmd = [ "ffmpeg", "-y", "-framerate", str(fps), "-i", frames_pattern, "-pix_fmt", "yuv420p", str(output_video_path), ] run_cmd(cmd) def extract_first_frame(video_path: Path, first_frame_path: Path) -> None: first_frame_path.parent.mkdir(parents=True, exist_ok=True) cmd = [ "ffmpeg", "-y", "-i", str(video_path), "-vf", "select=eq(n\\,0)", "-vframes", "1", str(first_frame_path), ] run_cmd(cmd)