diff --git a/ffmpeg/_run.py b/ffmpeg/_run.py index f42d1d7..fc714c1 100644 --- a/ffmpeg/_run.py +++ b/ffmpeg/_run.py @@ -114,7 +114,7 @@ def _get_global_args(node): return list(node.args) -def _get_output_args(node, stream_name_map): +def _get_output_args(node, stream_name_map, explicit_maps): if node.name != output.__name__: raise ValueError('Unsupported output node: {}'.format(node)) args = [] @@ -127,7 +127,7 @@ def _get_output_args(node, stream_name_map): stream_name = _format_input_stream_name( stream_name_map, edge, is_final_arg=True ) - if stream_name != '0' or len(node.incoming_edges) > 1: + if explicit_maps or stream_name != '0' or len(node.incoming_edges) > 1: args += ['-map', stream_name] kwargs = copy.copy(node.kwargs) @@ -149,7 +149,7 @@ def _get_output_args(node, stream_name_map): @output_operator() -def get_args(stream_spec, overwrite_output=False): +def get_args(stream_spec, overwrite_output=False, explicit_maps=False): """Build command-line arguments to be passed to ffmpeg.""" nodes = get_stream_spec_nodes(stream_spec) args = [] @@ -165,7 +165,7 @@ def get_args(stream_spec, overwrite_output=False): if filter_arg: args += ['-filter_complex', filter_arg] args += reduce( - operator.add, [_get_output_args(node, stream_name_map) for node in output_nodes] + operator.add, [_get_output_args(node, stream_name_map, explicit_maps) for node in output_nodes] ) args += reduce(operator.add, [_get_global_args(node) for node in global_nodes], []) if overwrite_output: @@ -174,7 +174,7 @@ def get_args(stream_spec, overwrite_output=False): @output_operator() -def compile(stream_spec, cmd='ffmpeg', overwrite_output=False): +def compile(stream_spec, cmd='ffmpeg', overwrite_output=False, explicit_maps=False): """Build command-line for invoking ffmpeg. The :meth:`run` function uses this to build the command line @@ -189,7 +189,7 @@ def compile(stream_spec, cmd='ffmpeg', overwrite_output=False): cmd = [cmd] elif type(cmd) != list: cmd = list(cmd) - return cmd + get_args(stream_spec, overwrite_output=overwrite_output) + return cmd + get_args(stream_spec, overwrite_output=overwrite_output, explicit_maps=explicit_maps) @output_operator() diff --git a/ffmpeg/tests/test_ffmpeg.py b/ffmpeg/tests/test_ffmpeg.py index 8dbc271..e795120 100644 --- a/ffmpeg/tests/test_ffmpeg.py +++ b/ffmpeg/tests/test_ffmpeg.py @@ -611,6 +611,32 @@ def test__merge_outputs(): assert ffmpeg.get_args([out1, out2]) == ['-i', 'in.mp4', 'out2.mp4', 'out1.mp4'] +def test__explicit_maps(): + in_ = ffmpeg.input('in.mp4') + out1 = in_.output('out1.mp4') + out2 = in_.output('out2.mp4') + assert ffmpeg.merge_outputs(out1, out2).get_args(explicit_maps=True) == [ + '-i', + 'in.mp4', + '-map', + '0', + 'out1.mp4', + '-map', + '0', + 'out2.mp4', + ] + assert ffmpeg.get_args([out1, out2], explicit_maps=True) == [ + '-i', + 'in.mp4', + '-map', + '0', + 'out2.mp4', + '-map', + '0', + 'out1.mp4' + ] + + def test__input__start_time(): assert ffmpeg.input('in', ss=10.5).output('out').get_args() == [ '-ss',