10000 Merge pull request #51 from kkroening/compile · Powercoder64/ffmpeg-python@5b813cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 5b813cd

Browse files
authored
Merge pull request kkroening#51 from kkroening/compile
Add `compile` operator
2 parents 940e3e7 + f818cff commit 5b813cd

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

ffmpeg/_run.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,28 @@ def get_args(stream_spec, overwrite_output=False):
131131
return args
132132

133133

134+
@output_operator()
135+
def compile(stream_spec, cmd='ffmpeg', **kwargs):
136+
"""Build command-line for ffmpeg."""
137+
if isinstance(cmd, basestring):
138+
cmd = [cmd]
139+
elif type(cmd) != list:
140+
cmd = list(cmd)
141+
return cmd + get_args(stream_spec, **kwargs)
142+
143+
134144
@output_operator()
135145
def run(stream_spec, cmd='ffmpeg', **kwargs):
136146
"""Run ffmpeg on node graph.
137147
138148
Args:
139149
**kwargs: keyword-arguments passed to ``get_args()`` (e.g. ``overwrite_output=True``).
140150
"""
141-
if isinstance(cmd, basestring):
142-
cmd = [cmd]
143-
elif type(cmd) != list:
144-
cmd = list(cmd)
145-
args = cmd + get_args(stream_spec, **kwargs)
146-
_subprocess.check_call(args)
151+
_subprocess.check_call(compile(stream_spec, cmd, **kwargs))
147152

148153

149154
__all__ = [
155+
'compile',
150156
'get_args',
151157
'run',
152158
]

ffmpeg/tests/test_ffmpeg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ def _get_drawtext_text_repr(text):
219219
# subprocess.check_call(['ffmpeg', '-version'])
220220

221221

222+
def test_compile():
223+
out_file = ffmpeg.input('dummy.mp4').output('dummy2.mp4')
224+
assert out_file.compile() == ['ffmpeg', '-i', 'dummy.mp4', 'dummy2.mp4']
225+
assert out_file.compile(cmd='ffmpeg.old') == ['ffmpeg.old', '-i', 'dummy.mp4', 'dummy2.mp4']
226+
227+
222228
def test_run():
223229
stream = _get_complex_filter_example()
224230
ffmpeg.run(stream)

0 commit comments

Comments
 (0)
0