8000 Merge pull request #83 from kkroening/feature-30 · Powercoder64/ffmpeg-python@2a2d5a4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a2d5a4

Browse files
authored
Merge pull request kkroening#83 from kkroening/feature-30
kkroening#30: add `global_args` operator
2 parents 7077eaa + 84355d4 commit 2a2d5a4

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

ffmpeg/_ffmpeg.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import unicode_literals
22

3+
from past.builtins import basestring
34
from ._utils import basestring
45

56
from .nodes import (
@@ -26,13 +27,20 @@ def input(filename, **kwargs):
2627
return InputNode(input.__name__, kwargs=kwargs).stream()
2728

2829

30+
@output_operator()
31+
def global_args(stream, *args):
32+
"""Add extra global command-line argument(s), e.g. ``-progress``.
33+
"""
34+
return GlobalNode(stream, global_args.__name__, args).stream()
35+
36+
2937
@output_operator()
3038
def overwrite_output(stream):
3139
"""Overwrite output files without asking (ffmpeg ``-y`` option)
3240
3341
Official documentation: `Main options <https://ffmpeg.org/ffmpeg.html#Main-options>`__
3442
"""
35-
return GlobalNode(stream, overwrite_output.__name__).stream()
43+
return GlobalNode(stream, overwrite_output.__name__, ['-y']).stream()
3644

3745

3846
@output_operator()

ffmpeg/_run.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import unicode_literals
22

3+
from builtins import str
4+
from past.builtins import basestring
35
from .dag import get_outgoing_edges, topo_sort
46
from functools import reduce
57
from ._utils import basestring
@@ -10,7 +12,6 @@
1012
from ._ffmpeg import (
1113
input,
1214
output,
13-
overwrite_output,
1415
)
1516
from .nodes import (
1617
get_stream_spec_nodes,
@@ -92,10 +93,7 @@ def _get_filter_arg(filter_nodes, outgoing_edge_maps, stream_name_map):
9293

9394

9495
def _get_global_args(node):
95-
if node.name == overwrite_output.__name__:
96-
return ['-y']
97-
else:
98-
raise ValueError('Unsupported global node: {}'.format(node))
96+
return list(node.args)
9997

10098

10199
def _get_output_args(node, stream_name_map):

ffmpeg/_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from __future__ import unicode_literals
2+
from builtins import str
3+
from past.builtins import basestring
24
import hashlib
35
import sys
46

57
if sys.version_info.major == 2:
68
# noinspection PyUnresolvedReferences,PyShadowingBuiltins
7-
str = unicode
9+
str = str
810

911

1012
# `past.builtins.basestring` module can't be imported on Python3 in some environments (Ubuntu).

ffmpeg/dag.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def incoming_edge_map(self):
7575

7676
def get_incoming_edges(downstream_node, incoming_edge_map):
7777
edges = []
78-
for downstream_label, upstream_info in incoming_edge_map.items():
78+
for downstream_label, upstream_info in list(incoming_edge_map.items()):
7979
upstream_node, upstream_label, upstream_selector = upstream_info
8080
edges += [DagEdge(downstream_node, downstream_label, upstream_node, upstream_label, upstream_selector)]
8181
return edges
@@ -97,7 +97,7 @@ class KwargReprNode(DagNode):
9797
@property
9898
def __upstream_hashes(self):
9999
hashes = []
100-
for downstream_label, upstream_info in self.incoming_edge_map.items():
100+
for downstream_label, upstream_info in list(self.incoming_edge_map.items()):
101101
upstream_node, upstream_label, upstream_selector = upstream_info
102102
hashes += [hash(x) for x in [downstream_label, upstream_node, upstream_label, upstream_selector]]
103103
return hashes

ffmpeg/nodes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import unicode_literals
22

3+
from past.builtins import basestring
34
from .dag import KwargReprNode
45
from ._utils import escape_chars, get_hash_int
56
from builtins import object

ffmpeg/tests/test_ffmpeg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import unicode_literals
22

3+
from builtins import str
34
from builtins import bytes
45
from builtins import range
56
import ffmpeg
@@ -105,6 +106,11 @@ def test_get_args_simple():
105106
assert out_file.get_args() == ['-i', 'dummy.mp4', 'dummy2.mp4']
106107

107108

109+
def test_global_args():
110+
out_file = ffmpeg.input('dummy.mp4').output('dummy2.mp4').global_args('-progress', 'someurl')
111+
assert out_file.get_args() == ['-i', 'dummy.mp4', 'dummy2.mp4', '-progress', 'someurl']
112+
113+
108114
def _get_complex_filter_example():
109115
split = (ffmpeg
110116
.input(TEST_INPUT_FILE1)

0 commit comments

Comments
 (0)
0