Add compile operator

This commit is contained in:
Karl Kroening 2018-01-07 02:28:13 -08:00
parent 940e3e7681
commit f818cffc55
2 changed files with 18 additions and 6 deletions

View File

@ -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',
]

View File

@ -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)