8000 #34: run non-interactively by default · yumyum-web/ffmpeg-python@d1a9ff8 · GitHub
[go: up one dir, main page]

Skip to content

Commit d1a9ff8

Browse files
committed
kkroening#34: run non-interactively by default
1 parent 7a44e54 commit d1a9ff8

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

ffmpeg/_ffmpeg.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from .nodes import (
44
filter_operator,
5-
GlobalNode,
65
InputNode,
76
MergeOutputsNode,
87
OutputNode,
@@ -24,15 +23,6 @@ def input(file 8000 name, **kwargs):
2423
return InputNode(input.__name__, kwargs=kwargs).stream()
2524

2625

27-
@output_operator()
28-
def overwrite_output(stream):
29-
"""Overwrite output files without asking (ffmpeg ``-y`` option)
30-
31-
Official documentation: `Main options <https://ffmpeg.org/ffmpeg.html#Main-options>`__
32-
"""
33-
return GlobalNode(stream, overwrite_output.__name__).stream()
34-
35-
3626
@output_operator()
3727
def merge_outputs(*streams):
3828
"""Include all given outputs in one ffmpeg command line
@@ -60,5 +50,4 @@ def output(stream, filename, **kwargs):
6050
'input',
6151
'merge_outputs',
6252
'output',
63-
'overwrite_output',
6453
]

ffmpeg/_run.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from ._ffmpeg import (
1111
input,
1212
output,
13-
overwrite_output,
1413
)
1514
from .nodes import (
1615
get_stream_spec_nodes,
@@ -83,10 +82,7 @@ def _get_filter_arg(filter_nodes, outgoing_edge_maps, stream_name_map):
8382

8483

8584
def _get_global_args(node):
86-
if node.name == overwrite_output.__name__:
87-
return ['-y']
88-
else:
89-
raise ValueError('Unsupported global node: {}'.format(node))
85+
raise ValueError('Unsupported global node: {}'.format(node))
9086

9187

9288
def _get_output_args(node, stream_name_map):
@@ -109,7 +105,7 @@ def _get_output_args(node, stream_name_map):
109105

110106

111107
@output_operator()
112-
def get_args(stream_spec, overwrite_output=False):
108+
def get_args(stream_spec, overwrite_output=True):
113109
"""Get command-line arguments for ffmpeg."""
114110
nodes = get_stream_spec_nodes(stream_spec)
115111
args = []
@@ -126,7 +122,9 @@ def get_args(stream_spec, overwrite_output=False):
126122
args += ['-filter_complex', filter_arg]
127123
args += reduce(operator.add, [_get_output_args(node, stream_name_map) for node in output_nodes])
128124
args += reduce(operator.add, [_get_global_args(node) for node in global_nodes], [])
129-
if overwrite_output:
125+
if overwrite_output is False:
126+
args += ['-n']
127+
elif overwrite_output is not None:
130128
args += ['-y']
131129
return args
132130

@@ -136,7 +134,7 @@ def run(stream_spec, cmd='ffmpeg', **kwargs):
136134
"""Run ffmpeg on node graph.
137135
138136
Args:
139-
**kwargs: keyword-arguments passed to ``get_args()`` (e.g. ``overwrite_output=True``).
137+
**kwargs: keyword-arguments passed to ``get_args()`` (e.g. ``overwrite_output=False``).
140138
"""
141139
if isinstance(cmd, basestring):
142140
cmd = [cmd]

ffmpeg/tests/test_ffmpeg.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_stream_repr():
101101

102102
def test_get_args_simple():
103103
out_file = ffmpeg.input('dummy.mp4').output('dummy2.mp4')
104-
assert out_file.get_args() == ['-i', 'dummy.mp4', 'dummy2.mp4']
104+
assert out_file.get_args() == ['-i', 'dummy.mp4', 'dummy2.mp4', '-y']
105105

106106

107107
def _get_complex_filter_example():
@@ -122,7 +122,6 @@ def _get_complex_filter_example():
122122
.overlay(overlay_file.hflip())
123123
.drawbox(50, 50, 120, 120, color='red', thickness=5)
124124
.output(TEST_OUTPUT_FILE1)
125-
.overwrite_output()
126125
)
127126

128127

@@ -156,7 +155,7 @@ def _get_drawtext_font_repr(font):
156155
.get_args()
157156
)
158157
assert args[:3] == ['-i', 'in', '-filter_complex']
159-
assert args[4:] == ['-map', '[s0]', 'out']
158+
assert args[4:] == ['-map', '[s0]', 'out', '-y']
160159
match = re.match(r'\[0\]drawtext=font=a((.|\n)*)b:text=test\[s0\]', args[3], re.MULTILINE)
161160
assert match is not None, 'Invalid -filter_complex arg: {!r}'.format(args[3])
162161
return match.group(1)
@@ -190,7 +189,7 @@ def _get_drawtext_text_repr(text):
190189
.get_args()
191190
)
192191
assert args[:3] == ['-i', 'in', '-filter_complex']
193-
assert args[4:] == ['-map', '[s0]', 'out']
192+
assert args[4:] == ['-map', '[s0]', 'out', '-y']
194193
match = re.match(r'\[0\]drawtext=text=a((.|\n)*)b\[s0\]', args[3], re.MULTILINE)
195194
assert match is not None, 'Invalid -filter_complex arg: {!r}'.format(args[3])
196195
return match.group(1)
@@ -226,7 +225,7 @@ def test_run_multi_output():
226225
in_ = ffmpeg.input(TEST_INPUT_FILE1)
227226
out1 = in_.output(TEST_OUTPUT_FILE1)
228227
out2 = in_.output(TEST_OUTPUT_FILE2)
229-
ffmpeg.run([out1, out2], overwrite_output=True)
228+
ffmpeg.run([out1, out2])
230229

231230

232231
def test_run_dummy_cmd():
@@ -253,7 +252,8 @@ def test_custom_filter():
253252
'-i', 'dummy.mp4',
254253
'-filter_complex', '[0]custom_filter=a:b:kwarg1=c[s0]',
255254
'-map', '[s0]',
256-
'dummy2.mp4'
255+
'dummy2.mp4',
256+
'-y',
257257
]
258258

259259

@@ -267,7 +267,8 @@ def test_custom_filter_fluent():
267267
'-i', 'dummy.mp4',
268268
'-filter_complex', '[0]custom_filter=a:b:kwarg1=c[s0]',
269269
'-map', '[s0]',
270-
'dummy2.mp4'
270+
'dummy2.mp4',
271+
'-y',
271272
]
272273

273274

@@ -276,10 +277,10 @@ def test_merge_outputs():
276277
out1 = in_.output('out1.mp4')
277278
out2 = in_.output('out2.mp4')
278279
assert ffmpeg.merge_outputs(out1, out2).get_args() == [
279-
'-i', 'in.mp4', 'out1.mp4', 'out2.mp4'
280+
'-i', 'in.mp4', 'out1.mp4', 'out2.mp4', '-y'
280281
]
281282
assert ffmpeg.get_args([out1, out2]) == [
282-
'-i', 'in.mp4', 'out2.mp4', 'out1.mp4'
283+
'-i', 'in.mp4', 'out2.mp4', 'out1.mp4', '-y'
283284
]
284285

285286

@@ -292,14 +293,16 @@ def test_multi_passthrough():
292293
'-i', 'in2.mp4',
293294
'out1.mp4',
294295
'-map', '[1]', # FIXME: this should not be here (see #23)
295-
'out2.mp4'
296+
'out2.mp4',
297+
'-y',
296298
]
297299
assert ffmpeg.get_args([out1, out2]) == [
298300
'-i', 'in2.mp4',
299301
'-i', 'in1.mp4',
300302
'out2.mp4',
301303
'-map', '[1]', # FIXME: this should not be here (see #23)
302-
'out1.mp4'
304+
'out1.mp4',
305+
'-y',
303306
]
304307

305308

@@ -327,7 +330,8 @@ def test_pipe():
327330
'[0]trim=start_frame=2[s0]',
328331
'-map', '[s0]',
329332
'-f', 'rawvideo',
330-
'pipe:1'
333+
'pipe:1',
334+
'-y',
331335
]
332336

333337
cmd = ['ffmpeg'] + args

0 commit comments

Comments
 (0)
0