]> granicus.if.org Git - libvpx/commitdiff
Increase active best quality linearly
authorRavi Chaudhary <ravi.chaudhary@ittiam.com>
Mon, 22 Apr 2019 13:25:12 +0000 (18:55 +0530)
committerRavi Chaudhary <ravi.chaudhary@ittiam.com>
Thu, 16 May 2019 11:30:55 +0000 (17:00 +0530)
The ARF frames in last few gf intervals, would be
used as a reference by fewer ARF frames in the same
kf interval. Also, the ARF frames in the last GF
group would not be used as a reference in future.
Hence the active best quality for these ARF frames
is increased based on their temporal distance from
the next key frame.

Change-Id: Ice7eaa8a25384104b1d9cc021eec588c03053fc2

vp9/encoder/vp9_firstpass.c
vp9/encoder/vp9_ratectrl.c
vp9/encoder/vp9_ratectrl.h

index 25b0b9d26252c42778bff72bbcb5f5e7e1e994fd..392d1088effbc4c5fbf6bef33e290e6a1694d39b 100644 (file)
@@ -2642,6 +2642,17 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
     rc->source_alt_ref_pending = 0;
   }
 
+#define LAST_ALR_ACTIVE_BEST_QUALITY_ADJUSTMENT_FACTOR 0.2
+  rc->arf_active_best_quality_adjustment_factor = 1.0;
+  if (rc->source_alt_ref_pending && !is_lossless_requested(&cpi->oxcf) &&
+      rc->frames_to_key <= rc->arf_active_best_quality_adjustment_window) {
+    rc->arf_active_best_quality_adjustment_factor =
+        LAST_ALR_ACTIVE_BEST_QUALITY_ADJUSTMENT_FACTOR +
+        (1.0 - LAST_ALR_ACTIVE_BEST_QUALITY_ADJUSTMENT_FACTOR) *
+            (rc->frames_to_key - i) /
+            VPXMAX(1, (rc->arf_active_best_quality_adjustment_window - i));
+  }
+
 #ifdef AGGRESSIVE_VBR
   // Limit maximum boost based on interval length.
   rc->gfu_boost = VPXMIN((int)rc->gfu_boost, i * 140);
@@ -3190,6 +3201,11 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
     // Default to normal-sized frame on keyframes.
     cpi->rc.next_frame_size_selector = UNSCALED;
   }
+#define ARF_ACTIVE_BEST_QUALITY_ADJUSTMENT_WINDOW_SIZE 64
+  // TODO(ravi.chaudhary@ittiam.com): Experiment without the below min
+  // condition. This might be helpful for small key frame intervals.
+  rc->arf_active_best_quality_adjustment_window =
+      VPXMIN(ARF_ACTIVE_BEST_QUALITY_ADJUSTMENT_WINDOW_SIZE, rc->frames_to_key);
 }
 
 static int is_skippable_frame(const VP9_COMP *cpi) {
index e764124922a07c8d7752e349044989d90a4c43a3..91df847338b21fb007dbd5dcd2d5bf0c2a7715be 100644 (file)
@@ -437,6 +437,7 @@ void vp9_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
   rc->last_post_encode_dropped_scene_change = 0;
   rc->use_post_encode_drop = 0;
   rc->ext_use_post_encode_drop = 0;
+  rc->arf_active_best_quality_adjustment_factor = 1.0;
 }
 
 static int check_buffer_above_thresh(VP9_COMP *cpi, int drop_mark) {
@@ -1417,6 +1418,8 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, int *bottom_index,
   int active_worst_quality = cpi->twopass.active_worst_quality;
   int q;
   int *inter_minq;
+  int arf_active_best_quality_adjustment, arf_active_best_quality_max;
+  int *arfgf_high_motion_minq;
   const int boost_frame =
       !rc->is_src_frame_alt_ref &&
       (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame);
@@ -1444,6 +1447,14 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, int *bottom_index,
     }
     active_best_quality = get_gf_active_quality(cpi, q, cm->bit_depth);
 
+    ASSIGN_MINQ_TABLE(cm->bit_depth, arfgf_high_motion_minq);
+    arf_active_best_quality_max = arfgf_high_motion_minq[q];
+    arf_active_best_quality_adjustment =
+        arf_active_best_quality_max - active_best_quality;
+    active_best_quality = arf_active_best_quality_max -
+                          (int)(arf_active_best_quality_adjustment *
+                                rc->arf_active_best_quality_adjustment_factor);
+
     // Modify best quality for second level arfs. For mode VPX_Q this
     // becomes the baseline frame q.
     if (gf_group->rf_level[gf_group_index] == GF_ARF_LOW) {
index a5c1f4cf0cdc97e8fe60622dcca61ad001bb1f28..2c2048edc57809806c52ed9c4417480d1556b1e8 100644 (file)
@@ -197,6 +197,8 @@ typedef struct {
   int ext_use_post_encode_drop;
 
   int damped_adjustment[RATE_FACTOR_LEVELS];
+  double arf_active_best_quality_adjustment_factor;
+  int arf_active_best_quality_adjustment_window;
 } RATE_CONTROL;
 
 struct VP9_COMP;