diff --git a/src/utils/video.py b/src/utils/video.py index cd295fe..e9f11c7 100644 --- a/src/utils/video.py +++ b/src/utils/video.py @@ -1,3 +1,4 @@ +import os import logging from pathlib import Path @@ -27,11 +28,18 @@ class VideoMaker: video_numerator: str = "video_%08d.mp4", ): """Concatenates a sequence of videos using ffmpeg.""" - cmd = f"ffmpeg -f concat -safe 0 -i <(for f in {videos_path / video_numerator}; do echo \"file '$f'\"; done) -c copy {output_path}" + + videos = sorted(videos_path.glob("*.mp4")) + file = "file.txt" + with open(file, "w") as f: + for video in videos: + f.write(f"file '{video}'\n") + cmd = f"ffmpeg -f concat -safe 0 -i {file} -c copy {output_path}" logging.info(f"Running command: {cmd}") result = self.run_command(cmd) if result != 0: logging.error(f"Failed to concatenate videos. Command returned {result}") + os.remove(file) def get_fps(self, video_path: Path) -> float: """Gets the frames per second (FPS) of a video.""" @@ -65,7 +73,9 @@ class VideoMaker: logging.error(f"Command failed with error: {e}") return e.returncode - def video_to_frames_generator(self, video_path: Path, output_dir: Path, chunk_seconds: int = 10) -> Generator[tuple[Path, ...], None, None]: + def video_to_frames_generator( + self, video_path: Path, output_dir: Path, chunk_seconds: int = 10 + ) -> Generator[tuple[Path, ...], None, None]: """Extracts frames from a video and saves them to disk, yielding paths to the saved frames.""" cap = cv2.VideoCapture(str(video_path)) @@ -93,4 +103,4 @@ class VideoMaker: paths.append(frame_path) frame_index += 1 - yield tuple(paths) \ No newline at end of file + yield tuple(paths)