Skip to main content

SceneChangeDetector

Struct SceneChangeDetector 

Source
pub struct SceneChangeDetector<T: Pixel> {
Show 18 fields scene_detection_mode: SceneDetectionSpeed, lookahead_offset: usize, min_key_frame_interval: usize, max_key_frame_interval: usize, cpu_feature_level: CpuFeatureLevel, threshold: f64, resolution: (usize, usize), bit_depth: usize, frame_rate: Rational32, chroma_sampling: ChromaSampling, scaled_pixels: usize, scale_func: Option<ScaleFunction<T>>, deque_offset: usize, downscaled_frame_buffer: Option<[Plane<T>; 2]>, score_deque: Vec<ScenecutResult>, temp_plane: Option<Plane<T>>, frame_me_stats_buffer: Option<Arc<RwLock<[FrameMEStats; 8]>>>, pub intra_costs: Option<BTreeMap<usize, Box<[u32]>>>,
}
Expand description

Runs keyframe detection on frames from the lookahead queue.

This struct is intended for advanced users who need the ability to analyze a small subset of frames at a time, for example in a streaming fashion. Most users will prefer to use new_detector and detect_scene_changes at the top level of this crate.

Fields§

§scene_detection_mode: SceneDetectionSpeed

Scenecut detection mode

§lookahead_offset: usize

Deque offset for current

§min_key_frame_interval: usize

Minimum number of frames between two scenecuts

§max_key_frame_interval: usize

Maximum number of frames between two scenecuts

§cpu_feature_level: CpuFeatureLevel

The CPU feature level to be used.

§threshold: f64

Minimum average difference between YUV deltas that will trigger a scene change.

§resolution: (usize, usize)

Width and height of the unscaled frame

§bit_depth: usize

The bit depth of the video.

§frame_rate: Rational32

The frame rate of the video.

§chroma_sampling: ChromaSampling

The chroma subsampling of the video.

§scaled_pixels: usize

Number of pixels in scaled frame for fast mode

§scale_func: Option<ScaleFunction<T>>

Downscaling function for fast scene detection

§deque_offset: usize

Start deque offset based on lookahead

§downscaled_frame_buffer: Option<[Plane<T>; 2]>

Frame buffer for scaled frames

§score_deque: Vec<ScenecutResult>

Scenechange results for adaptive threshold

§temp_plane: Option<Plane<T>>

Temporary buffer used by estimate_intra_costs. We store it on the struct so we only need to allocate it once.

§frame_me_stats_buffer: Option<Arc<RwLock<[FrameMEStats; 8]>>>

Buffer for FrameMEStats for cost scenecut

§intra_costs: Option<BTreeMap<usize, Box<[u32]>>>

Calculated intra costs for each input frame. These can be cached for reuse by advanced API users. Caching will occur if this is not None.

Implementations§

Source§

impl<T: Pixel> SceneChangeDetector<T>

Source

pub(super) fn fast_scenecut( &mut self, frame1: Arc<Frame<T>>, frame2: Arc<Frame<T>>, ) -> ScenecutResult

The fast algorithm detects fast cuts using a raw difference in pixel values between the scaled frames.

Source

fn delta_in_planes(&self, plane1: &Plane<T>, plane2: &Plane<T>) -> f64

Calculates the average sum of absolute difference (SAD) per pixel between 2 planes

Source§

impl<T: Pixel> SceneChangeDetector<T>

Source

pub(super) fn cost_scenecut( &mut self, frame1: Arc<Frame<T>>, frame2: Arc<Frame<T>>, input_frameno: usize, ) -> ScenecutResult

Run a comparison between two frames to determine if they qualify for a scenecut.

We gather both intra and inter costs for the frames, as well as an importance-block-based difference, and use all three metrics.

Source§

impl<T: Pixel> SceneChangeDetector<T>

Source

pub fn new( resolution: (usize, usize), bit_depth: usize, frame_rate: Rational32, chroma_sampling: ChromaSampling, lookahead_distance: usize, scene_detection_mode: SceneDetectionSpeed, min_key_frame_interval: usize, max_key_frame_interval: usize, cpu_feature_level: CpuFeatureLevel, ) -> Self

Creates a new instance of the SceneChangeDetector.

Source

pub fn enable_cache(&mut self)

Enables caching of intra costs. For advanced API users.

Source

pub fn analyze_next_frame( &mut self, frame_set: &[&Arc<Frame<T>>], input_frameno: usize, previous_keyframe: usize, ) -> bool

Runs keyframe detection on the next frame in the lookahead queue.

This function requires that a subset of input frames is passed to it in order, and that keyframes is only updated from this method. input_frameno should correspond to the second frame in frame_set.

This will gracefully handle the first frame in the video as well.

Source

fn handle_min_max_intervals(&mut self, distance: usize) -> Option<bool>

Source

fn initialize_score_deque( &mut self, frame_set: &[&Arc<Frame<T>>], input_frameno: usize, init_len: usize, )

Source

fn run_comparison( &mut self, frame1: Arc<Frame<T>>, frame2: Arc<Frame<T>>, input_frameno: usize, )

Runs scene change comparison between 2 given frames Insert result to start of score deque

Source

fn adaptive_scenecut(&mut self) -> (bool, ScenecutResult)

Compares current scene score to adapted threshold based on previous scores

Value of current frame is offset by lookahead, if lookahead >=5

Returns true if current scene score is higher than adapted threshold

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.