Skip to content

Commit a0a473c

Browse files
committed
fixed bugs in pad labeling
1 parent 8e74c26 commit a0a473c

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

src/ffmpegio/filtergraph.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
from contextlib import contextmanager
100100
from functools import partial, reduce
101101
from copy import deepcopy
102+
import itertools
102103
from math import floor, log10
103104
import os
104105
import re
@@ -223,10 +224,13 @@ def _shift_labels(obj, label_type, args):
223224
return obj.add_labels(label_type, args)
224225

225226
if all(_is_label(arg) for arg in args):
226-
return obj.add_labels(label_type, [arg for arg in args])
227+
return obj.add_labels(label_type, args)
227228

228-
assert len(args) == 2 and _is_label(args[0])
229-
return obj.add_labels(label_type, {args[1]: args[0]})
229+
is_dst = label_type == "dst"
230+
assert len(args) == 2 and _is_label(args[0 if is_dst else 1])
231+
return obj.add_labels(
232+
label_type, {obj._resolve_index(is_dst, args[is_dst]): args[not is_dst]}
233+
)
230234

231235

232236
###################################################################################################
@@ -2543,9 +2547,16 @@ def add_labels(self, pad_type, labels):
25432547
pad = fg._resolve_index(is_input, None)
25442548
fg.add_label(label, **{pad_type: pad})
25452549
else:
2546-
for label in labels:
2547-
pad = fg._resolve_index(is_input, None)
2548-
fg.add_label(label, **{pad_type: pad})
2550+
pads = list(
2551+
itertools.islice(
2552+
fg.iter_input_pads(exclude_named=True)
2553+
if pad_type == "dst"
2554+
else fg.iter_output_pads(exclude_named=True),
2555+
len(labels),
2556+
)
2557+
)
2558+
for label, pad in zip(labels, pads):
2559+
fg.add_label(label, **{pad_type: pad[0]})
25492560
return fg
25502561

25512562
@contextmanager

0 commit comments

Comments
 (0)