10000 Add __getitem__ to Stream too, simplify selector syntax · Powercoder64/ffmpeg-python@f6d0145 · GitHub
[go: up one dir, main page]

Skip to content

Commit f6d0145

Browse files
committed
Add __getitem__ to Stream too, simplify selector syntax
* No need to have a split node in between, you can just do stream[:"a"] * Split nodes are still needed to do actual splitting.
1 parent 646a0dc commit f6d0145

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ffmpeg/nodes.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ def __repr__(self):
4343
out = '{}[{!r}{}] <{}>'.format(node_repr, self.label, selector, self.node.short_hash)
4444
return out
4545

46+
def __getitem__(self, item):
47+
"""
48+
Select a component of the stream. `stream[:X]` is analogous to `stream.node.stream(select=X)`.
49+
Please note that this can only be used to select a substream that already exist. If you want to split
50+
the stream, use the `split` filter.
51+
"""
52+
if item.start != None:
53+
raise ValueError("Invalid syntax. Use 'stream[:\"something\"]', not 'stream[\"something\"]'.")
54+
55+
return self.node.stream(select=item.stop)
56+
4657

4758
def get_stream_map(stream_spec):
4859
if stream_spec is None:
@@ -201,8 +212,8 @@ def short_repr(self):
201212

202213

203214
class OutputStream(Stream):
204-
def __init__(self, upstream_node, upstream_label):
205-
super(OutputStream, self).__init__(upstream_node, upstream_label, {OutputNode, GlobalNode, MergeOutputsNode})
215+
def __init__(self, upstream_node, upstream_label, upstream_selector=None):
216+
super(OutputStream, self).__init__(upstream_node, upstream_label, {OutputNode, GlobalNode, MergeOutputsNode}, upstream_selector=upstream_selector)
206217

207218

208219
class MergeOutputsNode(Node):

0 commit comments

Comments
 (0)
0