8000 Merge pull request #103 from kkroening/passthrough · Powercoder64/ffmpeg-python@71fb743 · GitHub
[go: up one dir, main page]

Skip to content

Commit 71fb743

Browse files
authored
Merge pull request kkroening#103 from kkroening/passthrough
Fix `-map` to not use brackets for passthroughs; fixes kkroening#102, kkroening#23
2 parents 5916891 + 217bd2b commit 71fb743

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

ffmpeg/_run.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,19 @@ def _get_input_args(input_node):
5757
return args
5858

5959

60-
def _format_input_stream_name(< 10000 span class="pl-s1">stream_name_map, edge):
60+
def _format_input_stream_name(stream_name_map, edge, is_final_arg=False):
6161
prefix = stream_name_map[edge.upstream_node, edge.upstream_label]
6262
if not edge.upstream_selector:
6363
suffix = ''
6464
else:
6565
suffix = ':{}'.format(edge.upstream_selector)
66-
return '[{}{}]'.format(prefix, suffix)
66+
if is_final_arg and isinstance(edge.upstream_node, InputNode):
67+
## Special case: `-map` args should not have brackets for input
68+
## nodes.
69+
fmt = '{}{}'
70+
else:
71+
fmt = '[{}{}]'
72+
return fmt.format(prefix, suffix)
6773

6874

6975
def _format_output_stream_name(stream_name_map, edge):
@@ -113,8 +119,8 @@ def _get_output_args(node, stream_name_map):
113119

114120
for edge in node.incoming_edges:
115121
# edge = node.incoming_edges[0]
116-
stream_name = _format_input_stream_name(stream_name_map, edge)
117-
if stream_name != '[0]' or len(node.incoming_edges) > 1:
122+
stream_name = _format_input_stream_name(stream_name_map, edge, is_final_arg=True)
123+
if stream_name != '0' or len(node.incoming_edges) > 1:
118124
args += ['-map', stream_name]
119125

120126
kwargs = copy.copy(node.kwargs)

ffmpeg/tests/test_ffmpeg.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ def test_combined_output():
165165
assert out.get_args() == [
166166
'-i', TEST_INPUT_FILE1,
167167
'-i', TEST_OVERLAY_FILE,
168-
'-map', '[0]',
169-
'-map', '[1]',
168+
'-map', '0',
169+
'-map', '1',
170170
TEST_OUTPUT_FILE1
171171
]
172172

@@ -186,6 +186,7 @@ def test_filter_with_selector():
186186
]
187187

188188

189+
189190
def test_get_item_with_bad_selectors():
190191
input = ffmpeg.input(TEST_INPUT_FILE1)
191192

@@ -532,18 +533,50 @@ def test_multi_passthrough():
532533
'-i', 'in1.mp4',
533534
'-i', 'in2.mp4',
534535
'out1.mp4',
535-
'-map', '[1]', # FIXME: this should not be here (see #23)
536+
'-map', '1',
536537
'out2.mp4'
537538
]
538539
assert ffmpeg.get_args([out1, out2]) == [
539540
'-i', 'in2.mp4',
540541
'-i', 'in1.mp4',
541542
'out2.mp4',
542-
'-map', '[1]', # FIXME: this should not be here (see #23)
543+
'-map', '1',
543544
'out1.mp4'
544545
]
545546

546547

548+
def test_passthrough_selectors():
549+
i1 = ffmpeg.input(TEST_INPUT_FILE1)
550+
args = (
551+
ffmpeg
552+
.output(i1['1'], i1['2'], TEST_OUTPUT_FILE1)
553+
.get_args()
554+
)
555+
assert args == [
556+
'-i', TEST_INPUT_FILE1,
557+
'-map', '0:1',
558+
'-map', '0:2',
559+
TEST_OUTPUT_FILE1,
560+
]
561+
562+
563+
def test_mixed_passthrough_selectors():
564+
i1 = ffmpeg.input(TEST_INPUT_FILE1)
565+
args = (
566+
ffmpeg
567+
.output(i1['1'].hflip(), i1['2'], TEST_OUTPUT_FILE1)
568+
.get_args()
569+
)
570+
assert args == [
571+
'-i', TEST_INPUT_FILE1,
572+
'-filter_complex',
573+
'[0:1]hflip[s0]',
574+
'-map', '[s0]',
575+
'-map', '0:2',
576+
TEST_OUTPUT_FILE1,
577+
]
578+
579+
547580
def test_pipe():
548581
width = 32
549582
height = 32

0 commit comments

Comments
 (0)
0