zoomvtools 2.0.0

Video motion vector analysis utilities in pure Rust
Documentation
#[cfg(test)]
mod tests;

use anyhow::Result;

use crate::{analysis::MVAnalysisData, fake::group_of_planes::FakeGroupOfPlanes};

/// Scene-change detector backed by scaled MVTools thresholds.
#[derive(Debug, Clone)]
pub struct SCDetection {
    thscd1: u64,
    thscd2: u64,
}

impl SCDetection {
    /// Builds a detector from vector metadata and optional thresholds.
    ///
    /// # Errors
    /// Returns an error if threshold scaling fails for the supplied vector metadata.
    #[inline]
    pub fn new(
        vectors_data: MVAnalysisData,
        thscd1: Option<u64>,
        thscd2: Option<u64>,
    ) -> Result<Self> {
        let mut thscd1 = thscd1.unwrap_or(crate::params::MV_DEFAULT_SCD1);
        let mut thscd2 = thscd2.unwrap_or(crate::params::MV_DEFAULT_SCD2);
        vectors_data.scale_thscd(&mut thscd1, &mut thscd2, "SCDetection")?;
        Ok(Self { thscd1, thscd2 })
    }

    /// Returns `true` when `vectors` should be treated as a scene change.
    #[must_use]
    #[inline]
    pub fn scene_change(&self, vectors: &FakeGroupOfPlanes) -> bool {
        !vectors.is_usable(self.thscd1, self.thscd2)
    }
}