| 58 | return target_path |
| 59 | |
| 60 | def concat_videos(video_paths: list[Path]) -> Path: |
| 61 | if not video_paths: |
| 62 | raise ValueError("No video files to concatenate") |
| 63 | |
| 64 | video_paths = [Path(p).resolve() for p in video_paths] |
| 65 | output_path = video_paths[0].parent / "combined_video.mp4" |
| 66 | |
| 67 | with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) as f: |
| 68 | for p in video_paths: |
| 69 | f.write(f"file '{p.as_posix()}'\n") |
| 70 | list_file = f.name |
| 71 | |
| 72 | cmd = [ |
| 73 | "ffmpeg", |
| 74 | "-y", |
| 75 | "-f", "concat", |
| 76 | "-safe", "0", |
| 77 | "-i", list_file, |
| 78 | "-c", "copy", |
| 79 | str(output_path) |
| 80 | ] |
| 81 | |
| 82 | subprocess.run(cmd, check=True) |
| 83 | return output_path |
| 84 | |