mirror of
https://github.com/kkroening/ffmpeg-python.git
synced 2025-04-06 04:15:44 +08:00
Merge pull request #83 from kkroening/feature-30
#30: add `global_args` operator
This commit is contained in:
commit
2a2d5a43f1
@ -1,5 +1,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from past.builtins import basestring
|
||||||
from ._utils import basestring
|
from ._utils import basestring
|
||||||
|
|
||||||
from .nodes import (
|
from .nodes import (
|
||||||
@ -26,13 +27,20 @@ def input(filename, **kwargs):
|
|||||||
return InputNode(input.__name__, kwargs=kwargs).stream()
|
return InputNode(input.__name__, kwargs=kwargs).stream()
|
||||||
|
|
||||||
|
|
||||||
|
@output_operator()
|
||||||
|
def global_args(stream, *args):
|
||||||
|
"""Add extra global command-line argument(s), e.g. ``-progress``.
|
||||||
|
"""
|
||||||
|
return GlobalNode(stream, global_args.__name__, args).stream()
|
||||||
|
|
||||||
|
|
||||||
@output_operator()
|
@output_operator()
|
||||||
def overwrite_output(stream):
|
def overwrite_output(stream):
|
||||||
"""Overwrite output files without asking (ffmpeg ``-y`` option)
|
"""Overwrite output files without asking (ffmpeg ``-y`` option)
|
||||||
|
|
||||||
Official documentation: `Main options <https://ffmpeg.org/ffmpeg.html#Main-options>`__
|
Official documentation: `Main options <https://ffmpeg.org/ffmpeg.html#Main-options>`__
|
||||||
"""
|
"""
|
||||||
return GlobalNode(stream, overwrite_output.__name__).stream()
|
return GlobalNode(stream, overwrite_output.__name__, ['-y']).stream()
|
||||||
|
|
||||||
|
|
||||||
@output_operator()
|
@output_operator()
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from builtins import str
|
||||||
|
from past.builtins import basestring
|
||||||
from .dag import get_outgoing_edges, topo_sort
|
from .dag import get_outgoing_edges, topo_sort
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from ._utils import basestring
|
from ._utils import basestring
|
||||||
@ -10,7 +12,6 @@ import subprocess as _subprocess
|
|||||||
from ._ffmpeg import (
|
from ._ffmpeg import (
|
||||||
input,
|
input,
|
||||||
output,
|
output,
|
||||||
overwrite_output,
|
|
||||||
)
|
)
|
||||||
from .nodes import (
|
from .nodes import (
|
||||||
get_stream_spec_nodes,
|
get_stream_spec_nodes,
|
||||||
@ -92,10 +93,7 @@ def _get_filter_arg(filter_nodes, outgoing_edge_maps, stream_name_map):
|
|||||||
|
|
||||||
|
|
||||||
def _get_global_args(node):
|
def _get_global_args(node):
|
||||||
if node.name == overwrite_output.__name__:
|
return list(node.args)
|
||||||
return ['-y']
|
|
||||||
else:
|
|
||||||
raise ValueError('Unsupported global node: {}'.format(node))
|
|
||||||
|
|
||||||
|
|
||||||
def _get_output_args(node, stream_name_map):
|
def _get_output_args(node, stream_name_map):
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
from builtins import str
|
||||||
|
from past.builtins import basestring
|
||||||
import hashlib
|
import hashlib
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if sys.version_info.major == 2:
|
if sys.version_info.major == 2:
|
||||||
# noinspection PyUnresolvedReferences,PyShadowingBuiltins
|
# noinspection PyUnresolvedReferences,PyShadowingBuiltins
|
||||||
str = unicode
|
str = str
|
||||||
|
|
||||||
|
|
||||||
# `past.builtins.basestring` module can't be imported on Python3 in some environments (Ubuntu).
|
# `past.builtins.basestring` module can't be imported on Python3 in some environments (Ubuntu).
|
||||||
|
@ -75,7 +75,7 @@ DagEdge = namedtuple('DagEdge', ['downstream_node', 'downstream_label', 'upstrea
|
|||||||
|
|
||||||
def get_incoming_edges(downstream_node, incoming_edge_map):
|
def get_incoming_edges(downstream_node, incoming_edge_map):
|
||||||
edges = []
|
edges = []
|
||||||
for downstream_label, upstream_info in incoming_edge_map.items():
|
for downstream_label, upstream_info in list(incoming_edge_map.items()):
|
||||||
upstream_node, upstream_label, upstream_selector = upstream_info
|
upstream_node, upstream_label, upstream_selector = upstream_info
|
||||||
edges += [DagEdge(downstream_node, downstream_label, upstream_node, upstream_label, upstream_selector)]
|
edges += [DagEdge(downstream_node, downstream_label, upstream_node, upstream_label, upstream_selector)]
|
||||||
return edges
|
return edges
|
||||||
@ -97,7 +97,7 @@ class KwargReprNode(DagNode):
|
|||||||
@property
|
@property
|
||||||
def __upstream_hashes(self):
|
def __upstream_hashes(self):
|
||||||
hashes = []
|
hashes = []
|
||||||
for downstream_label, upstream_info in self.incoming_edge_map.items():
|
for downstream_label, upstream_info in list(self.incoming_edge_map.items()):
|
||||||
upstream_node, upstream_label, upstream_selector = upstream_info
|
upstream_node, upstream_label, upstream_selector = upstream_info
|
||||||
hashes += [hash(x) for x in [downstream_label, upstream_node, upstream_label, upstream_selector]]
|
hashes += [hash(x) for x in [downstream_label, upstream_node, upstream_label, upstream_selector]]
|
||||||
return hashes
|
return hashes
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from past.builtins import basestring
|
||||||
from .dag import KwargReprNode
|
from .dag import KwargReprNode
|
||||||
from ._utils import escape_chars, get_hash_int
|
from ._utils import escape_chars, get_hash_int
|
||||||
from builtins import object
|
from builtins import object
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from builtins import str
|
||||||
from builtins import bytes
|
from builtins import bytes
|
||||||
from builtins import range
|
from builtins import range
|
||||||
import ffmpeg
|
import ffmpeg
|
||||||
@ -105,6 +106,11 @@ def test_get_args_simple():
|
|||||||
assert out_file.get_args() == ['-i', 'dummy.mp4', 'dummy2.mp4']
|
assert out_file.get_args() == ['-i', 'dummy.mp4', 'dummy2.mp4']
|
||||||
|
|
||||||
|
|
||||||
|
def test_global_args():
|
||||||
|
out_file = ffmpeg.input('dummy.mp4').output('dummy2.mp4').global_args('-progress', 'someurl')
|
||||||
|
assert out_file.get_args() == ['-i', 'dummy.mp4', 'dummy2.mp4', '-progress', 'someurl']
|
||||||
|
|
||||||
|
|
||||||
def _get_complex_filter_example():
|
def _get_complex_filter_example():
|
||||||
split = (ffmpeg
|
split = (ffmpeg
|
||||||
.input(TEST_INPUT_FILE1)
|
.input(TEST_INPUT_FILE1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user