浏览代码

refactor+fix: extract calls to run, fix args

Extract method _run_no_output for two calls to ffmpeg

Fix feature.path → feature.source.path after Feature API change
main
Rob Hallam 2 个月前
父节点
当前提交
0d2179d445
共有 1 个文件被更改,包括 11 次插入3 次删除
  1. +11
    -3
      pipeline/video_producers.py

+ 11
- 3
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):


正在加载...
取消
保存