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

Class ThresholdDetector

scenedetect/detectors/threshold_detector.py:31–191  ·  view source on GitHub ↗

Detects fast cuts/slow fades in from and out to a given threshold level. Detects both fast cuts and slow fades so long as an appropriate threshold is chosen (especially taking into account the minimum grey/black level).

Source from the content-addressed store, hash-verified

29
30
31class ThresholdDetector(SceneDetector):
32 """Detects fast cuts/slow fades in from and out to a given threshold level.
33
34 Detects both fast cuts and slow fades so long as an appropriate threshold
35 is chosen (especially taking into account the minimum grey/black level).
36 """
37
38 class Method(Enum):
39 """Method for ThresholdDetector to use when comparing frame brightness to the threshold."""
40
41 FLOOR = 0
42 """Fade out happens when frame brightness falls below threshold."""
43 CEILING = 1
44 """Fade out happens when frame brightness rises above threshold."""
45
46 THRESHOLD_VALUE_KEY = "average_rgb"
47
48 def __init__(
49 self,
50 threshold: float = 12,
51 min_scene_len: TimecodeLike = 15,
52 fade_bias: float = 0.0,
53 add_final_scene: bool = False,
54 method: Method = Method.FLOOR,
55 block_size=None,
56 ):
57 """
58 Arguments:
59 threshold: 8-bit intensity value that each pixel value (R, G, and B)
60 must be <= to in order to trigger a fade in/out.
61 min_scene_len: Once a cut is detected, this much time must pass before a new one can
62 be added to the scene list. Accepts an int (frames), float (seconds), or
63 str (e.g. ``"0.6s"``, ``"00:00:00.600"``).
64 fade_bias: Float between -1.0 and +1.0 representing the percentage of
65 timecode skew for the start of a scene (-1.0 causing a cut at the
66 fade-to-black, 0.0 in the middle, and +1.0 causing the cut to be
67 right at the position where the threshold is passed).
68 add_final_scene: Boolean indicating if the video ends on a fade-out to
69 generate an additional scene at this timecode.
70 method: How to treat `threshold` when detecting fade events.
71 block_size: [DEPRECATED] DO NOT USE. For backwards compatibility.
72 """
73 if block_size is not None:
74 warnings.warn(
75 "The `block_size` argument is deprecated and will be removed in v0.8.",
76 DeprecationWarning,
77 stacklevel=2,
78 )
79
80 super().__init__()
81 self.threshold = int(threshold)
82 self.method = ThresholdDetector.Method(method)
83 self.fade_bias = fade_bias
84 self.min_scene_len = min_scene_len
85 self.processed_frame = False
86 self.last_scene_cut: FrameTimecode | None = None
87 # Whether to add an additional scene or not when ending on a fade out
88 # (as cuts are only added on fade ins; see post_process() for details).

Calls

no outgoing calls