From 0d2179d445b4503e0685122324d3ed05b1d0d2ad Mon Sep 17 00:00:00 2001 From: Rob Hallam <0504004h@student.gla.ac.uk> Date: Thu, 22 Aug 2024 13:29:02 +0100 Subject: [PATCH] refactor+fix: extract calls to run, fix args MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract method _run_no_output for two calls to ffmpeg Fix feature.path → feature.source.path after Feature API change --- pipeline/video_producers.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pipeline/video_producers.py b/pipeline/video_producers.py index 298a3f7..8575719 100644 --- a/pipeline/video_producers.py +++ b/pipeline/video_producers.py @@ -29,6 +29,13 @@ class FfmpegVideoProducer(VideoProducer): """Produce videos using ffmpeg""" # TODO: consider output filename options + def _run_no_output(self, cmd: list, cwd:str=".") -> None: + """Run a command and return the output as a string + + Defined to be mocked out in tests via unittest.mock.patch + """ + subprocess.run(cmd, stdout=None, stderr=None, cwd=cwd) + def __init__(self, features): if not features: raise ValueError("No features provided") @@ -50,9 +57,10 @@ class FfmpegVideoProducer(VideoProducer): # TODO: adjustable encoding options seek = ["-ss", str(feature.interval.start)] duration = ["-t", str(feature.interval.duration)] - ffmpeg_args = ffmpeg_prefix + seek + ["-i"] + [feature.path] + duration + ffmpeg_suffix + [output_filepath] + ffmpeg_args = ffmpeg_prefix + seek + ["-i"] + [feature.source.path] +\ + duration + ffmpeg_suffix + [output_filepath] logging.info(f"ffmpeg_args: {ffmpeg_args}") - subprocess.run(ffmpeg_args, stdout=None, stderr=None) + self._run_no_output(ffmpeg_args) def _ffmpeg_concat_clips(self, clips=None, output_filepath=None): """use ffmpeg to concatenate clips into a single video""" @@ -78,7 +86,7 @@ class FfmpegVideoProducer(VideoProducer): ffmpeg_args = ffmpeg_prefix + [join_file.name] + ["-c", "copy", output_filepath] logging.info(f"ffmpeg_args: {ffmpeg_args}") - subprocess.run(ffmpeg_args, stdout=None, stderr=None) + self._run_no_output(ffmpeg_args) join_file.close() def produce(self):