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

Class SceneDetector

scenedetect/detector.py:37–103  ·  view source on GitHub ↗

Base class to inherit from when implementing a scene detection algorithm. This API is not yet stable and subject to change.

Source from the content-addressed store, hash-verified

35
36
37class SceneDetector(ABC):
38 """Base class to inherit from when implementing a scene detection algorithm.
39
40 This API is not yet stable and subject to change.
41 """
42
43 def __init__(self):
44 self._stats_manager: StatsManager | None = None
45
46 # Required Methods
47
48 @abstractmethod
49 def process_frame(
50 self, timecode: FrameTimecode, frame_img: numpy.ndarray
51 ) -> list[FrameTimecode]:
52 """Process the next frame. `timecode` is assumed to be sequential.
53
54 Args:
55 timecode: Timecode corresponding to the frame being processed.
56 frame_img: Video frame as a 24-bit BGR image.
57
58 Returns:
59 List of timecodes where scene cuts have been detected, if any.
60 """
61
62 # Optional Methods
63
64 def post_process(self, timecode: FrameTimecode) -> list[FrameTimecode]:
65 """Called after there are no more frames to process.
66
67 Args:
68 timecode: The last position in the video which was read.
69
70 Returns:
71 List of timecodes where scene cuts have been detected, if any.
72 """
73 return []
74
75 @property
76 def event_buffer_length(self) -> int:
77 """The amount of frames a given event can be buffered for, in time. This must be set to the
78 amount of frames a detector might emit an event in the past."""
79 return 0
80
81 # Frame Stats/Metrics
82
83 @property
84 def stats_manager(self) -> StatsManager | None:
85 """Optional :class:`StatsManager <scenedetect.stats_manager.StatsManager>` to use for
86 storing frame metrics. When this detector is added to a parent
87 :class:`SceneManager <scenedetect.scene_manager.SceneManager>`, then this is set to the
88 same :class:`StatsManager <scenedetect.stats_manager.StatsManager>` of the parent - but
89 only if it has one itself."""
90 return self._stats_manager
91
92 @stats_manager.setter
93 def stats_manager(self, value: StatsManager | None):
94 self._stats_manager = value

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected