Merge 8e9fc34242f62860f998b5e59f1eeec74ffdd87f into df129c7ba30aaa9ffffb81a48f53aa7253b0b4e6

This commit is contained in:
Artem Eltyshev 2022-07-21 03:02:13 +09:00 committed by GitHub
commit 9897f1beca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 6 deletions

View File

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

View File

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