Convert a full video to frames using ffmpeg.
(
in_path: Path,
out_path: Path,
limit_num_seconds: float | None,
)
| 68 | |
| 69 | |
| 70 | def video_to_frames( |
| 71 | in_path: Path, |
| 72 | out_path: Path, |
| 73 | limit_num_seconds: float | None, |
| 74 | ) -> None: |
| 75 | """Convert a full video to frames using ffmpeg.""" |
| 76 | out_path.mkdir(exist_ok=True, parents=True) |
| 77 | limit = None if limit_num_seconds is None else f"-t {limit_num_seconds}" |
| 78 | command = f"ffmpeg -i {in_path} {limit} {out_path}/frame_%06d.png" |
| 79 | if subprocess.run(command.split(" ")).returncode != 0: |
| 80 | raise ValueError("ffmpeg conversion failed") |
| 81 | |
| 82 | |
| 83 | def resize_to_resolution( |