----------------------- ``scenedetect`` Package ----------------------- .. seealso:: For the ``scenedetect`` command, see the :doc:`CLI reference `. The ``scenedetect`` API integrates into Python applications and supports custom detectors and video backends. See `Usage`_ below for common examples. The ``scenedetect`` package is organized into these submodules: * :ref:`Functions `: high-level functions such as :func:`scenedetect.detect() ` to analyze a video with any :ref:`detector ` (:ref:`example `) and return a list of timecode pairs * :doc:`api/detectors`: built-in detectors: * :class:`AdaptiveDetector `: finds fast cuts using a rolling average of HSV content changes * :class:`ContentDetector `: finds fast cuts using a weighted average of HSV color and optional edge changes * :class:`HashDetector `: finds fast cuts using perceptual image hashing * :class:`HistogramDetector `: finds fast cuts using Y-channel (brightness) histogram changes in YUV * :class:`ThresholdDetector `: finds fades in and out using average RGB pixel brightness * :doc:`api/output`: output helpers: * :func:`split_video_ffmpeg ` and :func:`split_video_mkvmerge ` split a video into clips for each detected scene * :func:`save_images ` saves still frames from each scene * :func:`write_scene_list ` writes scene lists as CSV, :func:`write_scene_list_html ` writes HTML reports, and additional helpers export EDL, Final Cut Pro XML, OpenTimelineIO, and FFmetadata chapters * :doc:`api/backends`: modular video input backends: * OpenCV: :class:`VideoStreamCv2 ` * PyAV: :class:`VideoStreamAv ` * MoviePy: :class:`VideoStreamMoviePy ` * Multiple videos can be read as one continuous stream with :class:`VideoStreamConcat ` (for example, ``open_video(["part1.mp4", "part2.mp4"])``) * :doc:`api/common`: common types such as :class:`FrameTimecode ` for timecode handling * :doc:`api/scene_manager`: :class:`SceneManager ` runs scene detection on a video with one or more detectors * :doc:`api/detector`: the :class:`SceneDetector ` base class for custom detectors * :doc:`api/video_stream`: the :class:`VideoStream ` base class for custom video backends * :doc:`api/stats_manager`: :class:`StatsManager ` stores per-frame detection metrics and writes them to a CSV stats file * :doc:`api/platform`: logging and utility functions Most common types and functions can be imported directly from the top-level ``scenedetect`` package. .. warning:: The PySceneDetect API may change before v1.0. Pin ``scenedetect`` to a minor release in your dependencies: .. code:: python scenedetect~=0.7.0 .. _scenedetect-usage: Usage ----- Find scene cuts in a video with :func:`scenedetect.detect`: .. code:: python from scenedetect import detect, ContentDetector path = "video.mp4" scenes = detect(path, ContentDetector()) for (scene_start, scene_end) in scenes: print(f"{scene_start}-{scene_end}") ``scenes`` is a list of :class:`FrameTimecode ` pairs giving the start and end of each scene. Pass ``show_progress=True`` to :func:`detect ` to show a progress bar with estimated time remaining. This example uses :class:`ContentDetector ` to find fast cuts. You can choose from several :ref:`detectors ` for fast cuts and fades. PySceneDetect can also export scene lists in several formats and :ref:`split the input video ` when ``ffmpeg`` is installed: .. code:: python from scenedetect import detect, ContentDetector, split_video_ffmpeg scene_list = detect("my_video.mp4", ContentDetector()) split_video_ffmpeg("my_video.mp4", scene_list) See :doc:`examples` for more tasks shown as both CLI commands and Python code. For advanced workflows, start with :ref:`SceneManager `. Logging is covered under :ref:`Platform & Logging `. .. _scenedetect-functions: Functions --------- .. automodule:: scenedetect :members: