From be794539acd2804b7e0a036ce0fafbd260a71ab5 Mon Sep 17 00:00:00 2001 From: Viner Abubakirov Date: Thu, 2 Apr 2026 10:47:41 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D0=BB=20vi?= =?UTF-8?q?deo.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Команда выполняющейся при склейке видео по разному ввели в (sh, bash, zsh) --- src/utils/video.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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)