From 3984fa8c9b23283ea4cf40eaebf35fe115ce9601 Mon Sep 17 00:00:00 2001 From: Zen <46526140+master-of-zen@users.noreply.github.com> Date: Wed, 26 May 2021 16:13:30 +0300 Subject: [PATCH] fix tests --- src/scenechange/mod.rs | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/scenechange/mod.rs b/src/scenechange/mod.rs index 7c8b1f31a3..2d07802925 100644 --- a/src/scenechange/mod.rs +++ b/src/scenechange/mod.rs @@ -136,11 +136,6 @@ impl SceneChangeDetector { return false; } - // Decrease deque offset if there is no more new frames - if self.deque_offset > frame_set.len() + 1 && self.lookahead_offset > 0 { - self.deque_offset = self.deque_offset - 1; - } - // Initially fill score deque with forward frames // ititiallization is different depending on frame set length if self.deque_offset > 0 @@ -164,6 +159,7 @@ impl SceneChangeDetector { self.deque_offset = frame_set.len() - 2; } // Running single frame comparison and adding it to deque + // Decrease deque offset if there is no new frames if frame_set.len() > self.deque_offset + 1 { self.run_comparison( frame_set[self.deque_offset].clone(), @@ -171,6 +167,8 @@ impl SceneChangeDetector { input_frameno, previous_keyframe, ); + } else { + self.deque_offset -= 1; } // Adaptive scenecut check @@ -237,12 +235,6 @@ impl SceneChangeDetector { let mut cloned_deque = self.score_deque.to_vec(); cloned_deque.remove(self.deque_offset); - let max_of_deque: f64 = cloned_deque - .iter() - .cloned() - .map(|(b, _)| b) - .fold(-1. / 0. /* -inf */, f64::max); - let scene_score = self.score_deque[self.deque_offset].0; let scene_threshold = self.score_deque[self.deque_offset].1; @@ -261,6 +253,7 @@ impl SceneChangeDetector { if !back_over_tr.is_empty() && forward_over_tr.is_empty() && back_deque.len() > 1 + && back_over_tr.len() > 1 { return true; } @@ -274,14 +267,13 @@ impl SceneChangeDetector { { return true; } + + if !back_over_tr.is_empty() || !forward_over_tr.is_empty() { + return false; + } } - let threshold = if self.fast_mode { - self.threshold as f64 + max_of_deque - } else { - scene_threshold - }; - scene_score >= threshold + scene_score >= scene_threshold } /// The fast algorithm detects fast cuts using a raw difference