Skip to content

Commit

Permalink
[detectors] Fix not compensating for filter buffer length (#420)
Browse files Browse the repository at this point in the history
With the new flash filter, cuts may be placed behind the current frame.

This is similar to AdaptiveDetector, but when the new filter was landed,
the max look behind property of the detector wasn't updated. Fixes #416.
  • Loading branch information
Breakthrough authored Oct 6, 2024
1 parent 81e6a56 commit 08eb26e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions scenedetect/detectors/content_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,7 @@ def _detect_edges(self, lum: numpy.ndarray) -> numpy.ndarray:
# camera movement. Note that very large kernel sizes can negatively affect accuracy.
edges = cv2.Canny(lum, low, high)
return cv2.dilate(edges, self._kernel)

@property
def event_buffer_length(self) -> int:
return self._flash_filter.max_behind
7 changes: 6 additions & 1 deletion scenedetect/scene_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ def __init__(self, mode: Mode, length: int):
self._last_above = None # Last frame above threshold.
self._merge_enabled = False # Used to disable merging until at least one cut was found.
self._merge_triggered = False # True when the merge filter is active.
self._merge_start = None # Frame number where we started the merge filte.
self._merge_start = None # Frame number where we started the merge filter.

@property
def max_behind(self) -> int:
"""Maximum number of frames a filtered cut can be behind the current frame."""
return 0 if self._mode == FlashFilter.Mode.SUPPRESS else self._filter_length

def filter(self, frame_num: int, above_threshold: bool) -> ty.List[int]:
if not self._filter_length > 0:
Expand Down
3 changes: 2 additions & 1 deletion website/pages/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,4 +589,5 @@ Development
## PySceneDetect 0.6.5 (TBD)

- [bugfix] Fix new detectors not working with `default-detector` config option
- [bugfix] Fix SyntaxWarning due to incorrect escaping [#400](https://github.com/Breakthrough/PySceneDetect/issues/400)
- [bugfix] Fix `SyntaxWarning` due to incorrect escaping [#400](https://github.com/Breakthrough/PySceneDetect/issues/400)
- [bugfix] Fix `ContentDetector` crash when using callbacks [#416](https://github.com/Breakthrough/PySceneDetect/issues/416)

0 comments on commit 08eb26e

Please sign in to comment.