mirror of
https://github.com/kkroening/ffmpeg-python.git
synced 2025-04-05 04:22:51 +08:00
Merge 8e9fc34242f62860f998b5e59f1eeec74ffdd87f into df129c7ba30aaa9ffffb81a48f53aa7253b0b4e6
This commit is contained in:
commit
9897f1beca
@ -114,7 +114,7 @@ def _get_global_args(node):
|
|||||||
return list(node.args)
|
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__:
|
if node.name != output.__name__:
|
||||||
raise ValueError('Unsupported output node: {}'.format(node))
|
raise ValueError('Unsupported output node: {}'.format(node))
|
||||||
args = []
|
args = []
|
||||||
@ -127,7 +127,7 @@ def _get_output_args(node, stream_name_map):
|
|||||||
stream_name = _format_input_stream_name(
|
stream_name = _format_input_stream_name(
|
||||||
stream_name_map, edge, is_final_arg=True
|
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]
|
args += ['-map', stream_name]
|
||||||
|
|
||||||
kwargs = copy.copy(node.kwargs)
|
kwargs = copy.copy(node.kwargs)
|
||||||
@ -149,7 +149,7 @@ def _get_output_args(node, stream_name_map):
|
|||||||
|
|
||||||
|
|
||||||
@output_operator()
|
@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."""
|
"""Build command-line arguments to be passed to ffmpeg."""
|
||||||
nodes = get_stream_spec_nodes(stream_spec)
|
nodes = get_stream_spec_nodes(stream_spec)
|
||||||
args = []
|
args = []
|
||||||
@ -165,7 +165,7 @@ def get_args(stream_spec, overwrite_output=False):
|
|||||||
if filter_arg:
|
if filter_arg:
|
||||||
args += ['-filter_complex', filter_arg]
|
args += ['-filter_complex', filter_arg]
|
||||||
args += reduce(
|
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], [])
|
args += reduce(operator.add, [_get_global_args(node) for node in global_nodes], [])
|
||||||
if overwrite_output:
|
if overwrite_output:
|
||||||
@ -174,7 +174,7 @@ def get_args(stream_spec, overwrite_output=False):
|
|||||||
|
|
||||||
|
|
||||||
@output_operator()
|
@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.
|
"""Build command-line for invoking ffmpeg.
|
||||||
|
|
||||||
The :meth:`run` function uses this to build the command line
|
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]
|
cmd = [cmd]
|
||||||
elif type(cmd) != list:
|
elif type(cmd) != list:
|
||||||
cmd = list(cmd)
|
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()
|
@output_operator()
|
||||||
|
@ -611,6 +611,32 @@ def test__merge_outputs():
|
|||||||
assert ffmpeg.get_args([out1, out2]) == ['-i', 'in.mp4', 'out2.mp4', 'out1.mp4']
|
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():
|
def test__input__start_time():
|
||||||
assert ffmpeg.input('in', ss=10.5).output('out').get_args() == [
|
assert ffmpeg.input('in', ss=10.5).output('out').get_args() == [
|
||||||
'-ss',
|
'-ss',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user