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

Method _get_other_as_frames

scenedetect/common.py:521–542  ·  view source on GitHub ↗

Get the frame number from `other` for arithmetic operations.

(self, other: "TimecodeLike")

Source from the content-addressed store, hash-verified

519 return as_float
520
521 def _get_other_as_frames(self, other: "TimecodeLike") -> int:
522 """Get the frame number from `other` for arithmetic operations."""
523 if isinstance(other, int):
524 return other
525 if isinstance(other, float):
526 return self._seconds_to_frames(other)
527 if isinstance(other, str):
528 return self._seconds_to_frames(self._timecode_to_seconds(other))
529 if isinstance(other, Timecode):
530 return self._seconds_to_frames(other.seconds)
531 if isinstance(other, FrameTimecode):
532 # If comparing two FrameTimecodes, they must have the same framerate for frame-based
533 # operations.
534 if self._rate and other._rate and not self.equal_frame_rate(other._rate):
535 raise ValueError(
536 "FrameTimecode instances require equal frame rate for frame-based arithmetic."
537 )
538 if isinstance(other._time, _FrameNumber):
539 return other._time.value
540 # If other has no frame_num, it must have a timecode. Convert to frames.
541 return self._seconds_to_frames(other.seconds)
542 raise TypeError("Cannot obtain frame number for this timecode.")
543
544 def __eq__(self, other: "TimecodeLike") -> bool:
545 if other is None:

Callers 8

__eq__Method · 0.95
__ne__Method · 0.95
__lt__Method · 0.95
__le__Method · 0.95
__gt__Method · 0.95
__ge__Method · 0.95
__iadd__Method · 0.95
__isub__Method · 0.95

Calls 3

_seconds_to_framesMethod · 0.95
_timecode_to_secondsMethod · 0.95
equal_frame_rateMethod · 0.95

Tested by

no test coverage detected