Skip to main content

Module adaptive

Module adaptive 

Source
Available on crate features std or alloc only.
Expand description

Rolling-average / adaptive scene detector built on top of the content detector’s scores. Reduces false positives on fast camera motion. Adaptive (rolling-average) scene detector.

A thin layer built on top of content::Detector. Each frame is scored exactly as the content detector scores it (weighted HSV / optional edges); the adaptive detector maintains a sliding window of 1 + 2W scores around a target frame and decides whether the target is an outlier — specifically whether its score exceeds a multiple of the local average.

This is the algorithm PySceneDetect’s detect-adaptive uses. Its point: on fast camera motion the content score stays consistently high across neighbouring frames, so the ratio of the target score to the window average stays near 1. A real cut spikes the target score relative to its neighbours and the ratio jumps.

§Algorithm

For each incoming frame:

  1. Pass the frame to an inner content::Detector solely for its score; its own threshold is set to an unreachable value so it never emits cuts.
  2. Read the score and push (timestamp, score) onto a ring buffer of capacity 1 + 2 * window_width. While the buffer isn’t full yet, return None.
  3. Once full, the target is the middle element (index window_width). Compute average = mean(scores except target) and ratio = target_score / average (capped at 255).
  4. Emit a cut at the target’s timestamp iff:
    • ratio >= adaptive_threshold,
    • target_score >= min_content_val (guards against ratio noise in near-flat sequences),
    • at least min_duration has elapsed since the previous cut.

Because the target lags the current frame by window_width, emissions arrive window_width frames behind the real-time input. Cuts in the final window_width frames of a stream are not emitted (there’s no future context to evaluate them against) — mirrors PySceneDetect.

§Attribution

Ported from PySceneDetect’s detect-adaptive (BSD 3-Clause).

Structs§

Detector
Adaptive scene detector. See module documentation.
Options
Options for the adaptive scene detector. See the module documentation for how each parameter shapes the algorithm.

Enums§

Error
Error returned by Detector::try_new when the provided Options are inconsistent or the inner content::Options is invalid.