MCPcopy Create free account
hub / github.com/Breakthrough/PySceneDetect / __iadd__

Method __iadd__

scenedetect/common.py:608–661  ·  view source on GitHub ↗
(self, other: "TimecodeLike")

Source from the content-addressed store, hash-verified

606 return self.frame_num >= self._get_other_as_frames(other)
607
608 def __iadd__(self, other: "TimecodeLike") -> "FrameTimecode":
609 # Narrow `other`'s internal time once so pyright can track it through the dispatch below.
610 # A bare `Timecode` is treated as its own internal time.
611 if isinstance(other, FrameTimecode):
612 other_inner = other._time
613 elif isinstance(other, Timecode):
614 other_inner = other
615 else:
616 other_inner = None
617
618 if isinstance(self._time, Timecode) and isinstance(other_inner, Timecode):
619 if self._time.time_base == other_inner.time_base:
620 self._time = Timecode(
621 pts=max(0, self._time.pts + other_inner.pts),
622 time_base=self._time.time_base,
623 )
624 return self
625 # Different time bases: use the finer (smaller) one for better precision.
626 time_base = min(self._time.time_base, other_inner.time_base)
627 self_pts = round(Fraction(self._time.pts) * self._time.time_base / time_base)
628 other_pts = round(Fraction(other_inner.pts) * other_inner.time_base / time_base)
629 self._time = Timecode(pts=max(0, self_pts + other_pts), time_base=time_base)
630 return self
631
632 # If either input is a timecode, the output shall also be one. The input which isn't a
633 # timecode is converted into seconds, after which the equivalent timecode is computed.
634 if isinstance(self._time, Timecode):
635 seconds = self._get_other_as_seconds(other)
636 self._time = Timecode(
637 pts=max(0, self._time.pts + round(seconds / self._time.time_base)),
638 time_base=self._time.time_base,
639 )
640 if self._rate is None and isinstance(other, FrameTimecode):
641 self._rate = other._rate
642 return self
643 if isinstance(other_inner, Timecode):
644 self._time = Timecode(
645 pts=max(0, other_inner.pts + round(self.seconds / other_inner.time_base)),
646 time_base=other_inner.time_base,
647 )
648 if self._rate is None and isinstance(other, FrameTimecode):
649 self._rate = other._rate
650 return self
651
652 if isinstance(self._time, _Seconds) and isinstance(other_inner, _Seconds):
653 self._time = _Seconds(max(0.0, self._time.value + other_inner.value))
654 return self
655
656 if isinstance(self._time, _Seconds):
657 self._time = _Seconds(max(0.0, self._time.value + self._get_other_as_seconds(other)))
658 return self
659
660 self._time = _FrameNumber(max(0, self._time.value + self._get_other_as_frames(other)))
661 return self
662
663 def __add__(self, other: "TimecodeLike") -> "FrameTimecode":
664 to_return = FrameTimecode(timecode=self)

Callers

nothing calls this directly

Calls 5

_get_other_as_secondsMethod · 0.95
_get_other_as_framesMethod · 0.95
TimecodeClass · 0.85
_SecondsClass · 0.85
_FrameNumberClass · 0.85

Tested by

no test coverage detected