Perform scene detection on the given video using the added SceneDetectors, returning the number of frames processed. Results can be obtained by calling :meth:`get_scene_list` or :meth:`get_cut_list`. Video decoding is performed in a background thread to allow scene detection
(
self,
video: VideoStream | None = None,
duration: TimecodeLike | None = None,
end_time: TimecodeLike | None = None,
frame_skip: int = 0,
show_progress: bool = False,
callback: ty.Callable[[np.ndarray, FrameTimecode], None] | None = None,
frame_source: VideoStream | None = None,
)
| 416 | self._stop.set() |
| 417 | |
| 418 | def detect_scenes( |
| 419 | self, |
| 420 | video: VideoStream | None = None, |
| 421 | duration: TimecodeLike | None = None, |
| 422 | end_time: TimecodeLike | None = None, |
| 423 | frame_skip: int = 0, |
| 424 | show_progress: bool = False, |
| 425 | callback: ty.Callable[[np.ndarray, FrameTimecode], None] | None = None, |
| 426 | frame_source: VideoStream | None = None, |
| 427 | ) -> int: |
| 428 | """Perform scene detection on the given video using the added SceneDetectors, returning the |
| 429 | number of frames processed. Results can be obtained by calling :meth:`get_scene_list` or |
| 430 | :meth:`get_cut_list`. |
| 431 | |
| 432 | Video decoding is performed in a background thread to allow scene detection and frame |
| 433 | decoding to happen in parallel. Detection will continue until no more frames are left, |
| 434 | the specified duration or end time has been reached, or :meth:`stop` was called. |
| 435 | |
| 436 | Arguments: |
| 437 | video: VideoStream obtained from either `scenedetect.open_video`, or by creating |
| 438 | one directly (e.g. `scenedetect.backends.opencv.VideoStreamCv2`). |
| 439 | duration: Amount of time to detect from current video position. Cannot be |
| 440 | specified if `end_time` is set. |
| 441 | end_time: Time to stop processing at. Cannot be specified if `duration` is set. |
| 442 | frame_skip: Not recommended except for extremely high framerate videos. |
| 443 | Number of frames to skip (i.e. process every 1 in N+1 frames, |
| 444 | where N is frame_skip, processing only 1/N+1 percent of the video, |
| 445 | speeding up the detection time at the expense of accuracy). |
| 446 | `frame_skip` **must** be 0 (the default) when using a StatsManager. |
| 447 | show_progress: If True, and the ``tqdm`` module is available, displays |
| 448 | a progress bar with the progress, framerate, and expected time to |
| 449 | complete processing the video frame source. |
| 450 | callback: If set, called after each scene/event detected. |
| 451 | frame_source: [DEPRECATED] DO NOT USE. For compatibility with previous version. |
| 452 | :meta private: |
| 453 | Returns: |
| 454 | int: Number of frames read and processed from the frame source. |
| 455 | Raises: |
| 456 | ValueError: `frame_skip` **must** be 0 (the default) if the SceneManager |
| 457 | was constructed with a StatsManager object. |
| 458 | """ |
| 459 | # TODO(v0.8): Remove `frame_source` entirely; the `DeprecationWarning` below has shipped. |
| 460 | if frame_source is not None: |
| 461 | warnings.warn( |
| 462 | "The `frame_source` argument is deprecated, use `video` instead.", |
| 463 | DeprecationWarning, |
| 464 | stacklevel=2, |
| 465 | ) |
| 466 | video = frame_source |
| 467 | # TODO(v0.8): Remove default value for `video` after `frame_source` is removed. |
| 468 | if video is None: |
| 469 | raise TypeError("detect_scenes() missing 1 required positional argument: 'video'") |
| 470 | if frame_skip > 0 and self.stats_manager is not None: |
| 471 | raise ValueError("frame_skip must be 0 when using a StatsManager.") |
| 472 | if duration is not None and end_time is not None: |
| 473 | raise ValueError("duration and end_time cannot be set at the same time!") |
| 474 | # TODO: These checks should be handled by the FrameTimecode constructor. |
| 475 | if duration is not None and isinstance(duration, (int, float)) and duration < 0: |