]> granicus.if.org Git - libvpx/commitdiff
Fix for max qindex calculation of a gf interval
authorRanjit Kumar Tulabandu <ranjit.tulabandu@ittiam.com>
Tue, 20 Dec 2016 12:38:41 +0000 (18:08 +0530)
committerYunqing Wang <yunqingwang@google.com>
Tue, 3 Jan 2017 18:24:02 +0000 (10:24 -0800)
Calculation of active_worst_quality of a gf interval is modified
for coherency

BUG=webm:1355

Change-Id: I84cc2b47a8713f102a69419fb33ab020cffa3e71

vp9/encoder/vp9_firstpass.c

index 72e9ac77e785a61f997bf220f9ee8e2d9bcdc1f1..cda821cc6279db1c0e5009ed067817e449b7d916 100644 (file)
@@ -1359,6 +1359,7 @@ static int get_twopass_worst_quality(VP9_COMP *cpi, const double section_err,
   const RATE_CONTROL *const rc = &cpi->rc;
   const VP9EncoderConfig *const oxcf = &cpi->oxcf;
   TWO_PASS *const twopass = &cpi->twopass;
+  double last_group_rate_err;
 
   // Clamp the target rate to VBR min / max limts.
   const int target_rate =
@@ -1367,6 +1368,14 @@ static int get_twopass_worst_quality(VP9_COMP *cpi, const double section_err,
   noise_factor = fclamp(noise_factor, NOISE_FACTOR_MIN, NOISE_FACTOR_MAX);
   inactive_zone = fclamp(inactive_zone, 0.0, 1.0);
 
+  // based on recent history adjust expectations of bits per macroblock.
+  last_group_rate_err =
+      (double)twopass->rolling_arf_group_actual_bits /
+      DOUBLE_DIVIDE_CHECK((double)twopass->rolling_arf_group_target_bits);
+  last_group_rate_err = VPXMAX(0.25, VPXMIN(4.0, last_group_rate_err));
+  twopass->bpm_factor *= (3.0 + last_group_rate_err) / 4.0;
+  twopass->bpm_factor = VPXMAX(0.25, VPXMIN(4.0, twopass->bpm_factor));
+
   if (target_rate <= 0) {
     return rc->worst_quality;  // Highest value allowed
   } else {
@@ -1376,7 +1385,6 @@ static int get_twopass_worst_quality(VP9_COMP *cpi, const double section_err,
     const int active_mbs = VPXMAX(1, num_mbs - (int)(num_mbs * inactive_zone));
     const double av_err_per_mb = section_err / active_mbs;
     const double speed_term = 1.0 + 0.04 * oxcf->speed;
-    double last_group_rate_err;
     const int target_norm_bits_per_mb =
         (int)(((uint64_t)target_rate << BPER_MB_NORMBITS) / active_mbs);
     int q;
@@ -1385,14 +1393,6 @@ static int get_twopass_worst_quality(VP9_COMP *cpi, const double section_err,
     if (is_two_pass_svc(cpi) && cpi->svc.spatial_layer_id > 0)
       is_svc_upper_layer = 1;
 
-    // based on recent history adjust expectations of bits per macroblock.
-    last_group_rate_err =
-        (double)twopass->rolling_arf_group_actual_bits /
-        DOUBLE_DIVIDE_CHECK((double)twopass->rolling_arf_group_target_bits);
-    last_group_rate_err = VPXMAX(0.25, VPXMIN(4.0, last_group_rate_err));
-    twopass->bpm_factor *= (3.0 + last_group_rate_err) / 4.0;
-    twopass->bpm_factor = VPXMAX(0.25, VPXMIN(4.0, twopass->bpm_factor));
-
     // Try and pick a max Q that will be high enough to encode the
     // content at the given rate.
     for (q = rc->best_quality; q < rc->worst_quality; ++q) {
@@ -2354,6 +2354,10 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
         group_av_noise, vbr_group_bits_per_frame);
     twopass->active_worst_quality =
         (tmp_q + (twopass->active_worst_quality * 3)) >> 2;
+
+    // Reset rolling actual and target bits counters for ARF groups.
+    twopass->rolling_arf_group_target_bits = 0;
+    twopass->rolling_arf_group_actual_bits = 0;
   }
 
   // Context Adjustment of ARNR filter strength
@@ -2388,10 +2392,6 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
     // Default to starting GF groups at normal frame size.
     cpi->rc.next_frame_size_selector = UNSCALED;
   }
-
-  // Reset rolling actual and target bits counters for ARF groups.
-  twopass->rolling_arf_group_target_bits = 0;
-  twopass->rolling_arf_group_actual_bits = 0;
 }
 
 // Threshold for use of the lagging second reference frame. High second ref