Perform scene detection on a given video `path` using the specified `detector`. Arguments: video_path: Path to input video (absolute or relative to working directory). detector: A `SceneDetector` instance (see :mod:`scenedetect.detectors` for a full list of detectors
(
video_path: StrPath,
detector: SceneDetector,
stats_file_path: StrPath | None = None,
show_progress: bool = False,
start_time: TimecodeLike | None = None,
end_time: TimecodeLike | None = None,
start_in_scene: bool = False,
)
| 142 | |
| 143 | |
| 144 | def detect( |
| 145 | video_path: StrPath, |
| 146 | detector: SceneDetector, |
| 147 | stats_file_path: StrPath | None = None, |
| 148 | show_progress: bool = False, |
| 149 | start_time: TimecodeLike | None = None, |
| 150 | end_time: TimecodeLike | None = None, |
| 151 | start_in_scene: bool = False, |
| 152 | ) -> SceneList: |
| 153 | """Perform scene detection on a given video `path` using the specified `detector`. |
| 154 | |
| 155 | Arguments: |
| 156 | video_path: Path to input video (absolute or relative to working directory). |
| 157 | detector: A `SceneDetector` instance (see :mod:`scenedetect.detectors` for a full list |
| 158 | of detectors). |
| 159 | stats_file_path: Path to save per-frame metrics to for statistical analysis or to |
| 160 | determine a better threshold value. |
| 161 | show_progress: Show a progress bar with estimated time remaining. Default is False. |
| 162 | start_time: Starting point in video, in the form of a timecode ``HH:MM:SS[.nnn]`` (`str`), |
| 163 | number of seconds ``123.45`` (`float`), or number of frames ``200`` (`int`). |
| 164 | end_time: Starting point in video, in the form of a timecode ``HH:MM:SS[.nnn]`` (`str`), |
| 165 | number of seconds ``123.45`` (`float`), or number of frames ``200`` (`int`). |
| 166 | start_in_scene: Assume the video begins in a scene. This means that when detecting |
| 167 | fast cuts with `ContentDetector`, if no cuts are found, the resulting scene list |
| 168 | will contain a single scene spanning the entire video (instead of no scenes). |
| 169 | When detecting fades with `ThresholdDetector`, the beginning portion of the video |
| 170 | will always be included until the first fade-out event is detected. |
| 171 | |
| 172 | Returns: |
| 173 | List of scenes as pairs of (start, end) :class:`FrameTimecode` objects. |
| 174 | |
| 175 | Raises: |
| 176 | :class:`VideoOpenFailure`: `video_path` could not be opened. |
| 177 | :class:`StatsFileCorrupt`: `stats_file_path` is an invalid stats file |
| 178 | ValueError: `start_time` or `end_time` are incorrectly formatted. |
| 179 | TypeError: `start_time` or `end_time` are invalid types. |
| 180 | """ |
| 181 | video = open_video(video_path) |
| 182 | if start_time is not None: |
| 183 | video.seek(FrameTimecode(start_time, video.frame_rate)) |
| 184 | end_timecode = FrameTimecode(end_time, video.frame_rate) if end_time is not None else None |
| 185 | # To reduce memory consumption when not required, we only add a StatsManager if we |
| 186 | # need to save frame metrics to disk. |
| 187 | scene_manager = SceneManager(StatsManager() if stats_file_path else None) |
| 188 | scene_manager.add_detector(detector) |
| 189 | scene_manager.detect_scenes( |
| 190 | video=video, |
| 191 | show_progress=show_progress, |
| 192 | end_time=end_timecode, |
| 193 | ) |
| 194 | if scene_manager.stats_manager is not None and stats_file_path is not None: |
| 195 | scene_manager.stats_manager.save_to_csv(csv_file=stats_file_path) |
| 196 | return scene_manager.get_scene_list(start_in_scene=start_in_scene) |