Skip to content

Commit a6bc5a7

Browse files
committed
[output] Move post processing into new scenedetect.output module
1 parent 6cdd489 commit a6bc5a7

21 files changed

+1088
-1156
lines changed

docs/api.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The `scenedetect` API is easy to integrate with most application workflows, whil
77

88
* :ref:`scenedetect 🎬 <scenedetect-functions>`: Includes the :func:`scenedetect.detect <scenedetect.detect>` function which takes a path and a :ref:`detector <scenedetect-detectors>` to find scene transitions (:ref:`example <scenedetect-quickstart>`), and :func:`scenedetect.open_video <scenedetect.open_video>` for video input
99

10-
* :ref:`scenedetect.scene_manager 🎞️ <scenedetect-scene_manager>`: The :class:`SceneManager <scenedetect.scene_manager.SceneManager>` acts as a way to coordinate detecting scenes (via `SceneDetector` instances) on video frames (via :ref:`VideoStream <scenedetect-video_stream>` instances). This module also contains functionality to export information about scenes in various formats: :func:`save_images <scenedetect.scene_manager.save_images>` to save images for each scene, :func:`write_scene_list <scenedetect.scene_manager.write_scene_list>` to save scene/cut info as CSV, and :func:`write_scene_list_html <scenedetect.scene_manager.write_scene_list_html>` to export scenes in viewable HTML format.
10+
* :ref:`scenedetect.scene_manager 🎞️ <scenedetect-scene_manager>`: The :class:`SceneManager <scenedetect.scene_manager.SceneManager>` acts as a way to coordinate detecting scenes (via `SceneDetector` instances) on video frames (via :ref:`VideoStream <scenedetect-video_stream>` instances).
1111

1212
* :ref:`scenedetect.detectors 🕵️ <scenedetect-detectors>`: Detection algorithms:
1313

@@ -27,7 +27,13 @@ The `scenedetect` API is easy to integrate with most application workflows, whil
2727
* PyAV: :class:`VideoStreamAv <scenedetect.backends.pyav.VideoStreamAv>`
2828
* MoviePy: :class:`VideoStreamMoviePy <scenedetect.backends.moviepy.VideoStreamMoviePy>`
2929

30-
* :ref:`scenedetect.video_splitter ✂️ <scenedetect-video_splitter>`: Contains :func:`split_video_ffmpeg <scenedetect.video_splitter.split_video_ffmpeg>` and :func:`split_video_mkvmerge <scenedetect.video_splitter.split_video_mkvmerge>` to split a video based on the detected scenes.
30+
* :ref:`scenedetect.output ✂️ <scenedetect-output>`: Output formats:
31+
32+
* :func:`split_video_ffmpeg <scenedetect.output.split_video_ffmpeg>` and :func:`split_video_mkvmerge <scenedetect.output.split_video_mkvmerge>` split a video based on the detected scenes
33+
34+
* :func:`save_images <scenedetect.scene_manager.save_images>` can save an arbitrary number of images from each scene
35+
36+
* :func:`write_scene_list <scenedetect.scene_manager.write_scene_list>` can be used to save scene/cut info as CSV, :func:`write_scene_list_html <scenedetect.scene_manager.write_scene_list_html>` for HTML
3137

3238
* :ref:`scenedetect.common ⏱️ <scenedetect-common>`: Contains common types such as :class:`FrameTimecode <scenedetect.common.FrameTimecode>` used for timecode handing.
3339

@@ -67,7 +73,7 @@ PySceneDetect makes it very easy to find scene transitions in a video with the :
6773
6874
``scenes`` now contains a list of :class:`FrameTimecode <scenedetect.common.FrameTimecode>` pairs representing the start/end of each scene. Note that you can set ``show_progress=True`` when calling :func:`detect <scenedetect.detect>` to display a progress bar with estimated time remaining.
6975

70-
Here, we use :mod:`ContentDetector <scenedetect.detectors.content_detector>` to detect fast cuts. There are :ref:`many detector types <scenedetect-detectors>` which can be used to find fast cuts and fades in/out. PySceneDetect can also export scene data in various formats, and can :ref:`split the input video <scenedetect-video_splitter>` automatically if `ffmpeg` is available:
76+
Here, we use :mod:`ContentDetector <scenedetect.detectors.content_detector>` to detect fast cuts. There are :ref:`many detector types <scenedetect-detectors>` which can be used to find fast cuts and fades in/out. PySceneDetect can also export scene data in various formats, and can :ref:`split the input video <scenedetect-output>` automatically if `ffmpeg` is available:
7177

7278
.. code:: python
7379
@@ -98,7 +104,7 @@ Module Reference
98104
api/detectors
99105
api/scene_manager
100106
api/common
101-
api/video_splitter
107+
api/output
102108
api/backends
103109
api/stats_manager
104110
api/detector

docs/api/migration_guide.rst

Lines changed: 0 additions & 136 deletions
This file was deleted.

docs/api/output.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
3+
.. _scenedetect-output:
4+
5+
---------------------------------------------------------------
6+
Ouptut
7+
---------------------------------------------------------------
8+
9+
.. automodule:: scenedetect.output
10+
:members:
11+
12+
.. autofunction:: scenedetect.output.image.save_images
13+
14+
---------------------------------------------------------------
15+
Video
16+
---------------------------------------------------------------
17+
18+
.. automodule:: scenedetect.output.video
19+
:members:

docs/api/video_splitter.rst

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Table of Contents
4949
api/scene_manager
5050
api/common
5151
api/backends
52-
api/video_splitter
52+
api/output
5353
api/stats_manager
5454
api/detector
5555
api/video_stream

scenedetect/__init__.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,27 @@
3232
# Commonly used classes/functions exported under the `scenedetect` namespace for brevity.
3333
# Note that order of importants is important!
3434
from scenedetect.platform import init_logger # noqa: I001
35-
from scenedetect.common import FrameTimecode, SceneList, CutList, CropRegion, TimecodePair
35+
from scenedetect.common import (
36+
FrameTimecode,
37+
SceneList,
38+
CutList,
39+
CropRegion,
40+
TimecodePair,
41+
Interpolation,
42+
)
3643
from scenedetect.video_stream import VideoStream, VideoOpenFailure
37-
from scenedetect.video_splitter import split_video_ffmpeg, split_video_mkvmerge
44+
from scenedetect.output import (
45+
save_images,
46+
split_video_ffmpeg,
47+
split_video_mkvmerge,
48+
is_ffmpeg_available,
49+
is_mkvmerge_available,
50+
write_scene_list,
51+
write_scene_list_html,
52+
PathFormatter,
53+
VideoMetadata,
54+
SceneMetadata,
55+
)
3856
from scenedetect.detector import SceneDetector
3957
from scenedetect.detectors import (
4058
ContentDetector,
@@ -51,7 +69,7 @@
5169
VideoCaptureAdapter,
5270
)
5371
from scenedetect.stats_manager import StatsManager, StatsFileCorrupt
54-
from scenedetect.scene_manager import SceneManager, save_images, Interpolation
72+
from scenedetect.scene_manager import SceneManager
5573

5674
# Used for module identification and when printing version & about info
5775
# (e.g. calling `scenedetect version` or `scenedetect about`).

scenedetect/_cli/commands.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@
3030
from scenedetect._cli.config import XmlFormat
3131
from scenedetect._cli.context import CliContext
3232
from scenedetect.common import FrameTimecode
33+
from scenedetect.output import save_images as save_images_impl
34+
from scenedetect.output import (
35+
split_video_ffmpeg,
36+
split_video_mkvmerge,
37+
write_scene_list,
38+
write_scene_list_html,
39+
)
3340
from scenedetect.platform import get_and_create_path
3441
from scenedetect.scene_manager import (
3542
CutList,
3643
Interpolation,
3744
SceneList,
38-
write_scene_list,
39-
write_scene_list_html,
4045
)
41-
from scenedetect.scene_manager import save_images as save_images_impl
42-
from scenedetect.video_splitter import split_video_ffmpeg, split_video_mkvmerge
4346

4447
logger = logging.getLogger("pyscenedetect")
4548

scenedetect/_cli/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
from scenedetect.common import FrameTimecode
2929
from scenedetect.detector import FlashFilter
3030
from scenedetect.detectors import ContentDetector
31+
from scenedetect.output.video import DEFAULT_FFMPEG_ARGS
3132
from scenedetect.scene_manager import Interpolation
32-
from scenedetect.video_splitter import DEFAULT_FFMPEG_ARGS
3333

3434
PYAV_THREADING_MODES = ["NONE", "SLICE", "FRAME", "AUTO"]
3535

scenedetect/_cli/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
HistogramDetector,
3434
ThresholdDetector,
3535
)
36+
from scenedetect.output import is_ffmpeg_available, is_mkvmerge_available
3637
from scenedetect.platform import init_logger
3738
from scenedetect.scene_manager import Interpolation, SceneManager
3839
from scenedetect.stats_manager import StatsManager
39-
from scenedetect.video_splitter import is_ffmpeg_available, is_mkvmerge_available
4040
from scenedetect.video_stream import FrameRateUnavailable, VideoOpenFailure, VideoStream
4141

4242
logger = logging.getLogger("pyscenedetect")

scenedetect/common.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@
6464
import math
6565
import typing as ty
6666
from dataclasses import dataclass
67+
from enum import Enum
6768
from fractions import Fraction
6869

70+
import cv2
71+
6972
_USE_PTS_IN_DEVELOPMENT = False
7073

7174
##
@@ -94,6 +97,21 @@
9497
_MINUTES_PER_HOUR = 60.0
9598

9699

100+
class Interpolation(Enum):
101+
"""Interpolation method used for image resizing. Based on constants defined in OpenCV."""
102+
103+
NEAREST = cv2.INTER_NEAREST
104+
"""Nearest neighbor interpolation."""
105+
LINEAR = cv2.INTER_LINEAR
106+
"""Bilinear interpolation."""
107+
CUBIC = cv2.INTER_CUBIC
108+
"""Bicubic interpolation."""
109+
AREA = cv2.INTER_AREA
110+
"""Pixel area relation resampling. Provides moire'-free downscaling."""
111+
LANCZOS4 = cv2.INTER_LANCZOS4
112+
"""Lanczos interpolation over 8x8 neighborhood."""
113+
114+
97115
# TODO(@Breakthrough): How should we deal with frame numbers when we have a `Timecode`?
98116
#
99117
# Each backend has slight nuances we have to take into account:

0 commit comments

Comments
 (0)