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

Method _ensure_fractional

scenedetect/common.py:453–464  ·  view source on GitHub ↗

Validate and convert an `fps` argument into a positive `Fraction`. NTSC-like frame rates are handled via :func:`framerate_to_fraction`.

(fps: "FrameRate | FrameTimecode")

Source from the content-addressed store, hash-verified

451
452 @staticmethod
453 def _ensure_fractional(fps: "FrameRate | FrameTimecode") -> Fraction:
454 """Validate and convert an `fps` argument into a positive `Fraction`. NTSC-like frame rates
455 are handled via :func:`framerate_to_fraction`."""
456 if isinstance(fps, FrameTimecode):
457 if fps._rate is None:
458 raise TypeError("FrameTimecode passed as fps must have a known rate.")
459 return fps._rate
460 if isinstance(fps, (float, Fraction)):
461 return framerate_to_fraction(fps)
462 raise TypeError(
463 f"Wrong type for fps: {type(fps)} - expected float, Fraction, or FrameTimecode"
464 )
465
466 def _seconds_to_frames(self, seconds: float) -> int:
467 """Convert `seconds` to the nearest number of frames using the current framerate.

Callers 1

__init__Method · 0.95

Calls 1

framerate_to_fractionFunction · 0.85

Tested by

no test coverage detected