Skip to content

Commit

Permalink
[cli] Fix type hints for some context fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Breakthrough committed Oct 20, 2024
1 parent d1768e6 commit 43a02d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
6 changes: 3 additions & 3 deletions scenedetect/_cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def __init__(self):
self.video_stream: VideoStream = None
self.load_scenes_input: str = None # load-scenes -i/--input
self.load_scenes_column_name: str = None # load-scenes -c/--start-col-name
self.start_time: FrameTimecode = None # time -s/--start
self.end_time: FrameTimecode = None # time -e/--end
self.duration: FrameTimecode = None # time -d/--duration
self.start_time: ty.Optional[FrameTimecode] = None # time -s/--start
self.end_time: ty.Optional[FrameTimecode] = None # time -e/--end
self.duration: ty.Optional[FrameTimecode] = None # time -d/--duration
self.frame_skip: int = None

# Options:
Expand Down
25 changes: 10 additions & 15 deletions scenedetect/_cli/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,16 @@ def _load_scenes(context: CliContext) -> ty.Tuple[SceneList, CutList]:
csv_headers = next(file_reader)
if context.load_scenes_column_name not in csv_headers:
csv_headers = next(file_reader)
# Check to make sure column headers are present
# Check to make sure column headers are present and then load the data.
if context.load_scenes_column_name not in csv_headers:
raise ValueError("specified column header for scene start is not present")

col_idx = csv_headers.index(context.load_scenes_column_name)

cut_list = sorted(
FrameTimecode(row[col_idx], fps=context.video_stream.frame_rate) - 1
for row in file_reader
)
# `SceneDetector` works on cuts, so we have to skip the first scene and use the first frame
# of the next scene as the cut point. This can be fixed if we used `SparseSceneDetector`
# but this part of the API is being reworked and hasn't been used by any detectors yet.
# `SceneDetector` works on cuts, so we have to skip the first scene and place the first
# cut point where the next scenes starts.
if cut_list:
cut_list = cut_list[1:]

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

end_time = context.video_stream.duration
if context.end_time is not None or context.duration is not None:
if context.end_time is not None:
end_time = context.end_time
elif context.duration is not None:
end_time = start_time + context.duration
end_time = min(end_time, context.video_stream.duration)
if context.end_time is not None:
end_time = min(context.end_time, context.video_stream.duration)
elif context.duration is not None:
end_time = min(start_time + context.duration, context.video_stream.duration)

cut_list = [cut for cut in cut_list if cut < end_time]
scene_list = get_scenes_from_cuts(cut_list=cut_list, start_pos=start_time, end_pos=end_time)

return get_scenes_from_cuts(
cut_list=cut_list, start_pos=start_time, end_pos=end_time
), cut_list
return (scene_list, cut_list)

0 comments on commit 43a02d1

Please sign in to comment.