Skip to content

Commit 1a0cefb

Browse files
committed
GraphLinks.update - merge same-src dsts
1 parent 908db8e commit 1a0cefb

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

src/ffmpegio/utils/fglinks.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -742,14 +742,30 @@ def prep_ids(dsts, src):
742742

743743
# process each input item
744744
def process_item(label, dsts, src):
745-
if auto_link and label in self.data:
746-
if dsts is None and self.data[label][1] is None:
747-
self.data[label] = (self.data[label][0], src)
748-
return label
749-
elif src is None and self.data[label][0] is None:
750-
self.data[label] = (dsts, self.data[label][1])
751-
return label
752-
label = self._register_label(label)
745+
new_label = True
746+
if label in self.data:
747+
dsts_self, src_self = self.data[label]
748+
if auto_link:
749+
# try to link matching input & output pads
750+
if dsts is None and src_self is None:
751+
self.data[label] = (dsts_self, src)
752+
return label
753+
elif src is None and dsts_self is None:
754+
self.data[label] = (dsts, src_self)
755+
return label
756+
757+
if src == src_self:
758+
# if links from the same source, merge
759+
dsts = tuple(
760+
(
761+
*self.iter_dst_ids(dsts_self, True),
762+
*self.iter_dst_ids(dsts, True),
763+
)
764+
)
765+
new_label = False
766+
767+
if new_label:
768+
label = self._register_label(label)
753769
self.data[label] = (dsts, src)
754770
return label
755771

0 commit comments

Comments
 (0)