From f818cffc557e032e5a61949ced8bcda96d616660 Mon Sep 17 00:00:00 2001 From: Karl Kroening Date: Sun, 7 Jan 2018 02:28:13 -0800 Subject: [PATCH] Add `compile` operator --- ffmpeg/_run.py | 18 ++++++++++++------ ffmpeg/tests/test_ffmpeg.py | 6 ++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ffmpeg/_run.py b/ffmpeg/_run.py index 91a1462..03e5a76 100644 --- a/ffmpeg/_run.py +++ b/ffmpeg/_run.py @@ -131,6 +131,16 @@ def get_args(stream_spec, overwrite_output=False): return args +@output_operator() +def compile(stream_spec, cmd='ffmpeg', **kwargs): + """Build command-line for ffmpeg.""" + if isinstance(cmd, basestring): + cmd = [cmd] + elif type(cmd) != list: + cmd = list(cmd) + return cmd + get_args(stream_spec, **kwargs) + + @output_operator() def run(stream_spec, cmd='ffmpeg', **kwargs): """Run ffmpeg on node graph. @@ -138,15 +148,11 @@ def run(stream_spec, cmd='ffmpeg', **kwargs): Args: **kwargs: keyword-arguments passed to ``get_args()`` (e.g. ``overwrite_output=True``). """ - if isinstance(cmd, basestring): - cmd = [cmd] - elif type(cmd) != list: - cmd = list(cmd) - args = cmd + get_args(stream_spec, **kwargs) - _subprocess.check_call(args) + _subprocess.check_call(compile(stream_spec, cmd, **kwargs)) __all__ = [ + 'compile', 'get_args', 'run', ] diff --git a/ffmpeg/tests/test_ffmpeg.py b/ffmpeg/tests/test_ffmpeg.py index 95e0042..7b2a6d7 100644 --- a/ffmpeg/tests/test_ffmpeg.py +++ b/ffmpeg/tests/test_ffmpeg.py @@ -219,6 +219,12 @@ def test_filter_text_arg_str_escape(): # subprocess.check_call(['ffmpeg', '-version']) +def test_compile(): + out_file = ffmpeg.input('dummy.mp4').output('dummy2.mp4') + assert out_file.compile() == ['ffmpeg', '-i', 'dummy.mp4', 'dummy2.mp4'] + assert out_file.compile(cmd='ffmpeg.old') == ['ffmpeg.old', '-i', 'dummy.mp4', 'dummy2.mp4'] + + def test_run(): stream = _get_complex_filter_example() ffmpeg.run(stream)