shithub: libvpx

Download patch

ref: 1bd337b1d82de60971eff41bcec8eece91171530
parent: b2e498000ff52b27a62cd14a5b586ba0fefc9914
author: angiebird <angiebird@google.com>
date: Mon Oct 21 12:51:27 EDT 2019

Change the interface of find_next_key_frame

Change-Id: I9c25cbac2953755efa9fd72f59149f26513d1977

--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -3055,8 +3055,7 @@
 #define MAX_KF_TOT_BOOST 5400
 #endif
 
-static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame,
-                                int kf_show_idx) {
+static void find_next_key_frame(VP9_COMP *cpi, int kf_show_idx) {
   int i, j;
   RATE_CONTROL *const rc = &cpi->rc;
   TWO_PASS *const twopass = &cpi->twopass;
@@ -3065,8 +3064,9 @@
   const FIRST_PASS_INFO *first_pass_info = &twopass->first_pass_info;
   const FRAME_INFO *frame_info = &cpi->frame_info;
   const FIRSTPASS_STATS *const start_position = twopass->stats_in;
+  const FIRSTPASS_STATS *keyframe_stats =
+      fps_get_frame_stats(first_pass_info, kf_show_idx);
   FIRSTPASS_STATS next_frame;
-  FIRSTPASS_STATS last_frame;
   int kf_bits = 0;
   int64_t max_kf_bits;
   double decay_accumulator = 1.0;
@@ -3109,9 +3109,9 @@
   twopass->kf_group_bits = 0;          // Total bits available to kf group
   twopass->kf_group_error_left = 0.0;  // Group modified error score.
 
-  kf_raw_err = this_frame->intra_error;
-  kf_mod_err =
-      calculate_norm_frame_score(cpi, twopass, oxcf, this_frame, av_err);
+  kf_raw_err = keyframe_stats->intra_error;
+  kf_mod_err = calc_norm_frame_score(oxcf, frame_info, keyframe_stats,
+                                     mean_mod_score, av_err);
 
   // Initialize the decay rates for the recent frames to check
   for (j = 0; j < FRAMES_TO_CHECK_DECAY; ++j) recent_loop_decay[j] = 1.0;
@@ -3121,8 +3121,10 @@
   while (twopass->stats_in < twopass->stats_in_end &&
          rc->frames_to_key < cpi->oxcf.key_freq) {
     // Load the next frame's stats.
-    last_frame = *this_frame;
-    input_stats(twopass, this_frame);
+    const FIRSTPASS_STATS *last_frame =
+        fps_get_frame_stats(first_pass_info, kf_show_idx + i);
+    FIRSTPASS_STATS this_frame;
+    input_stats(twopass, &this_frame);
 
     // Provided that we are not at the end of the file...
     if (cpi->oxcf.auto_key && twopass->stats_in < twopass->stats_in_end) {
@@ -3129,7 +3131,7 @@
       double loop_decay_rate;
 
       // Check for a scene cut.
-      if (test_candidate_kf(twopass, &last_frame, this_frame,
+      if (test_candidate_kf(twopass, last_frame, &this_frame,
                             twopass->stats_in))
         break;
 
@@ -3434,11 +3436,8 @@
 
   // Keyframe and section processing.
   if (rc->frames_to_key == 0 || (cpi->frame_flags & FRAMEFLAGS_KEY)) {
-    FIRSTPASS_STATS this_frame_copy;
-    this_frame_copy = this_frame;
     // Define next KF group and assign bits to it.
-    find_next_key_frame(cpi, &this_frame, show_idx);
-    this_frame = this_frame_copy;
+    find_next_key_frame(cpi, show_idx);
   } else {
     cm->frame_type = INTER_FRAME;
   }