Skip to content

Commit

Permalink
[scene_manager] Fix warning when using timecode strings for duration/…
Browse files Browse the repository at this point in the history
…end_time

Fixes #346
  • Loading branch information
Breakthrough committed Jan 29, 2024
1 parent 0e7d16a commit 29d497d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 6 additions & 7 deletions scenedetect/scene_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,28 +810,27 @@ def detect_scenes(self,
video = frame_source
if video is None:
raise TypeError("detect_scenes() missing 1 required positional argument: 'video'")

if frame_skip > 0 and self.stats_manager is not None:
raise ValueError('frame_skip must be 0 when using a StatsManager.')
if duration is not None and end_time is not None:
raise ValueError('duration and end_time cannot be set at the same time!')
if duration is not None and duration < 0:
if duration is not None and isinstance(duration, (int, float)) and duration < 0:
raise ValueError('duration must be greater than or equal to 0!')
if end_time is not None and end_time < 0:
if end_time is not None and isinstance(end_time, (int, float)) and end_time < 0:
raise ValueError('end_time must be greater than or equal to 0!')

self._base_timecode = video.base_timecode

# TODO(v1.0): Fix this properly by making SceneManager create and own a StatsManager,
# and requiring the framerate to be passed to the StatsManager the constructor.
if self._stats_manager is not None:
self._stats_manager._base_timecode = self._base_timecode
start_frame_num: int = video.frame_number

if duration is not None:
end_time: Union[int, FrameTimecode] = duration + start_frame_num

if end_time is not None:
end_time: FrameTimecode = self._base_timecode + end_time
end_time = self._base_timecode + end_time
elif duration is not None:
end_time = (self._base_timecode + duration) + start_frame_num

# Can only calculate total number of frames we expect to process if the duration of
# the video is available.
Expand Down
6 changes: 5 additions & 1 deletion website/pages/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Releases

### 0.6.3 (In Development)

#### Release Notes

This release focuses on bugfixes and quality of life improvements. This has helped identify certain areas of focus for the next major release. Feedback is always welcome for command-line and API improvements.

**Program Changes:**

- [bugfix] Fix crash for some WebM videos when using `save-images` with `--backend pyav` [#355](https://github.com/Breakthrough/PySceneDetect/issues/355)
Expand All @@ -28,7 +32,7 @@ Releases
- The `StatsManager.register_metrics()` method no longer throws any exceptions
- Add `StatsManager.metric_keys` property to query registered metric keys
- Deprecate `FrameMetricRegistered` and `FrameMetricNotRegistered` exceptions (no longer used)

- [bugfix] Fix `SceneManager.detect_scenes` warning when `duration` or `end_time` are specified as timecode strings [#346](https://github.com/Breakthrough/PySceneDetect/issues/346)

### 0.6.2 (July 23, 2023)

Expand Down

0 comments on commit 29d497d

Please sign in to comment.