Skip to content

Commit 08e5ba0

Browse files
committed
[project] Create new common module
Remove timecode module and move contents into common.
1 parent 4b9edcc commit 08e5ba0

File tree

6 files changed

+31
-24
lines changed

6 files changed

+31
-24
lines changed

scenedetect/backends/opencv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import cv2
2727
import numpy as np
2828

29+
from scenedetect.common import Timecode
2930
from scenedetect.frame_timecode import MAX_FPS_DELTA, FrameTimecode
3031
from scenedetect.platform import get_file_name
31-
from scenedetect.timecode import Timecode
3232
from scenedetect.video_stream import (
3333
FrameRateUnavailable,
3434
SeekError,

scenedetect/backends/pyav.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import av
1818
import numpy as np
1919

20+
from scenedetect.common import Timecode
2021
from scenedetect.frame_timecode import MAX_FPS_DELTA, FrameTimecode
2122
from scenedetect.platform import get_file_name
22-
from scenedetect.timecode import Timecode
2323
from scenedetect.video_stream import FrameRateUnavailable, VideoFrame, VideoOpenFailure, VideoStream
2424

2525
logger = getLogger("pyscenedetect")
Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,38 @@
99
# PySceneDetect is licensed under the BSD 3-Clause License; see the
1010
# included LICENSE file, or visit one of the above pages for details.
1111
#
12-
"""``scenedetect.timecode`` Module
12+
"""``scenedetect.common`` Module
1313
14-
This module contains types and functions for handling video timecodes, including parsing user input
15-
and timecode format conversion.
16-
"""
14+
This module contains common types and functions used throughout PySceneDetect."""
1715

16+
import typing as ty
1817
from dataclasses import dataclass
1918
from fractions import Fraction
2019

20+
# TODO(v0.7): We should move frame_timecode into this file.
21+
from scenedetect.frame_timecode import FrameTimecode
22+
23+
##
24+
## Type Aliases
25+
##
26+
27+
SceneList = ty.List[ty.Tuple[FrameTimecode, FrameTimecode]]
28+
"""Type hint for a list of scenes in the form (start time, end time)."""
29+
30+
CutList = ty.List[FrameTimecode]
31+
"""Type hint for a list of cuts, where each timecode represents the first frame of a new shot."""
32+
33+
CropRegion = ty.Tuple[int, int, int, int]
34+
"""Type hint for rectangle of the form X0 Y0 X1 Y1 for cropping frames. Coordinates are relative
35+
to source frame without downscaling.
36+
"""
37+
38+
TimecodePair = ty.Tuple[FrameTimecode, FrameTimecode]
39+
"""Named type for pairs of timecodes, which typically represents the start/end of a scene."""
40+
2141

22-
# TODO(@Breakthrough): Add conversion from Timecode -> FrameTimecode for backwards compatibility.
42+
# TODO(@Breakthrough): Figure out interop with FrameTimecode. We can probably just store this inside
43+
# of FrameTimecode.
2344
# TODO(@Breakthrough): How should we deal with frame numbers? We might need to detect if a video is
2445
# VFR or not, and if so, either omit them or always start them from 0 regardless of the start seek.
2546
# With PyAV we can probably assume the video is VFR if the guessed rate of the stream differs
@@ -33,8 +54,6 @@
3354
# This is probably sufficient, since we could just use 1ms as a timebase.
3455
# - MoviePy: Assumes fixed framerate and doesn't include timing information. Fixing this is
3556
# probably not feasible, so we should make sure the docs warn users about this.
36-
#
37-
#
3857
@dataclass
3958
class Timecode:
4059
"""Timing information associated with a given frame."""

scenedetect/scene_manager.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def on_new_scene(frame_img: numpy.ndarray, frame_num: int):
100100
SimpleTableImage,
101101
SimpleTableRow,
102102
)
103+
from scenedetect.common import CropRegion, CutList, SceneList
103104
from scenedetect.frame_timecode import FrameTimecode
104105
from scenedetect.platform import get_and_create_path, get_cv2_imwrite_params, tqdm
105106
from scenedetect.scene_detector import SceneDetector, SparseSceneDetector
@@ -108,17 +109,6 @@ def on_new_scene(frame_img: numpy.ndarray, frame_num: int):
108109

109110
logger = logging.getLogger("pyscenedetect")
110111

111-
SceneList = ty.List[ty.Tuple[FrameTimecode, FrameTimecode]]
112-
"""Type hint for a list of scenes in the form (start time, end time)."""
113-
114-
CutList = ty.List[FrameTimecode]
115-
"""Type hint for a list of cuts, where each timecode represents the first frame of a new shot."""
116-
117-
CropRegion = ty.Tuple[int, int, int, int]
118-
"""Type hint for rectangle of the form X0 Y0 X1 Y1 for cropping frames. Coordinates are relative
119-
to source frame without downscaling.
120-
"""
121-
122112
# TODO: This value can and should be tuned for performance improvements as much as possible,
123113
# until accuracy falls, on a large enough dataset. This has yet to be done, but the current
124114
# value doesn't seem to have caused any issues at least.

scenedetect/video_splitter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@
4040
from dataclasses import dataclass
4141
from pathlib import Path
4242

43+
from scenedetect.common import TimecodePair
4344
from scenedetect.frame_timecode import FrameTimecode
4445
from scenedetect.platform import CommandTooLong, Template, get_ffmpeg_path, invoke_command, tqdm
4546

4647
logger = logging.getLogger("pyscenedetect")
4748

48-
TimecodePair = ty.Tuple[FrameTimecode, FrameTimecode]
49-
"""Named type for pairs of timecodes, which typically represents the start/end of a scene."""
50-
5149
COMMAND_TOO_LONG_STRING = """
5250
Cannot split video due to too many scenes (resulting command
5351
is too large to process). To work around this issue, you can

scenedetect/video_stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737

3838
import numpy as np
3939

40+
from scenedetect.common import Timecode
4041
from scenedetect.frame_timecode import FrameTimecode
41-
from scenedetect.timecode import Timecode
4242

4343

4444
class SeekError(Exception):

0 commit comments

Comments
 (0)