Skip to content

Commit 43a02d1

Browse files
committed
[cli] Fix type hints for some context fields
1 parent d1768e6 commit 43a02d1

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

scenedetect/_cli/context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ def __init__(self):
9090
self.video_stream: VideoStream = None
9191
self.load_scenes_input: str = None # load-scenes -i/--input
9292
self.load_scenes_column_name: str = None # load-scenes -c/--start-col-name
93-
self.start_time: FrameTimecode = None # time -s/--start
94-
self.end_time: FrameTimecode = None # time -e/--end
95-
self.duration: FrameTimecode = None # time -d/--duration
93+
self.start_time: ty.Optional[FrameTimecode] = None # time -s/--start
94+
self.end_time: ty.Optional[FrameTimecode] = None # time -e/--end
95+
self.duration: ty.Optional[FrameTimecode] = None # time -d/--duration
9696
self.frame_skip: int = None
9797

9898
# Options:

scenedetect/_cli/controller.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,16 @@ def _load_scenes(context: CliContext) -> ty.Tuple[SceneList, CutList]:
160160
csv_headers = next(file_reader)
161161
if context.load_scenes_column_name not in csv_headers:
162162
csv_headers = next(file_reader)
163-
# Check to make sure column headers are present
163+
# Check to make sure column headers are present and then load the data.
164164
if context.load_scenes_column_name not in csv_headers:
165165
raise ValueError("specified column header for scene start is not present")
166-
167166
col_idx = csv_headers.index(context.load_scenes_column_name)
168-
169167
cut_list = sorted(
170168
FrameTimecode(row[col_idx], fps=context.video_stream.frame_rate) - 1
171169
for row in file_reader
172170
)
173-
# `SceneDetector` works on cuts, so we have to skip the first scene and use the first frame
174-
# of the next scene as the cut point. This can be fixed if we used `SparseSceneDetector`
175-
# but this part of the API is being reworked and hasn't been used by any detectors yet.
171+
# `SceneDetector` works on cuts, so we have to skip the first scene and place the first
172+
# cut point where the next scenes starts.
176173
if cut_list:
177174
cut_list = cut_list[1:]
178175

@@ -182,14 +179,12 @@ def _load_scenes(context: CliContext) -> ty.Tuple[SceneList, CutList]:
182179
cut_list = [cut for cut in cut_list if cut > context.start_time]
183180

184181
end_time = context.video_stream.duration
185-
if context.end_time is not None or context.duration is not None:
186-
if context.end_time is not None:
187-
end_time = context.end_time
188-
elif context.duration is not None:
189-
end_time = start_time + context.duration
190-
end_time = min(end_time, context.video_stream.duration)
182+
if context.end_time is not None:
183+
end_time = min(context.end_time, context.video_stream.duration)
184+
elif context.duration is not None:
185+
end_time = min(start_time + context.duration, context.video_stream.duration)
186+
191187
cut_list = [cut for cut in cut_list if cut < end_time]
188+
scene_list = get_scenes_from_cuts(cut_list=cut_list, start_pos=start_time, end_pos=end_time)
192189

193-
return get_scenes_from_cuts(
194-
cut_list=cut_list, start_pos=start_time, end_pos=end_time
195-
), cut_list
190+
return (scene_list, cut_list)

0 commit comments

Comments
 (0)