]> granicus.if.org Git - libvpx/commitdiff
Change to KF frame boost calculation.
authorpaulwilkins <paulwilkins@google.com>
Wed, 21 Feb 2018 11:18:09 +0000 (11:18 +0000)
committerYaowu Xu <yaowu@google.com>
Wed, 28 Feb 2018 20:56:53 +0000 (20:56 +0000)
This change is targeted mainly at higher resolutions where typically
the average error per MB is much smaller.  hence this patch replaces
a fixed error per MB factor with a tiered value.

It also adds in a fixed offset value that acts as a minimum return score.

Note also minor fix to debug stats output.

The results are overall beneficial (-ve) on our test sets, most notably for
higher definition formats (see below - overall psnr, ssim, psnr hvs)

low res:    0.184 -0.262 -0.166
mid res:   0.094   0.075   0.049
hd res:    -0.752 -0.300 -0.800
NF 2K:    -0.353  1.095 -0.302
NF 4K:    -1.245 -0.578 -1.205

The most notable negative case is pierseaside 2K which appears to be worse by
8-10% (which has a big impact on the overall gain for the NF 2K set). Closer
inspection reveals that the drop does not relate to the key frame boost
per se as in both cases the key frame substantially undershoots its target. Rather
this is a side effect relating to the initial Q range allowed for the key frame and
a poor initial complexity estimate. This will hopefully be improved in a later
patch.

Change-Id: I4773ebe554782f4024c047c3c392c763a3fe843b

vp9/encoder/vp9_firstpass.c

index f4fda096584ea91edc74d9cdcd7ddbd4245bf3b0..89348e666d34703bc52d47ef36c349b27c3e1536 100644 (file)
@@ -105,7 +105,7 @@ static void output_stats(FIRSTPASS_STATS *stats,
     fprintf(fpfile,
             "%12.0lf %12.4lf %12.2lf %12.2lf %12.2lf %12.0lf %12.4lf %12.4lf"
             "%12.4lf %12.4lf %12.4lf %12.4lf %12.4lf %12.4lf %12.4lf %12.4lf"
-            "%12.4lf %12.4lf %12.4lf %12.4lf %12.4lf %12.0lf %12.0lf %12.0lf"
+            "%12.4lf %12.4lf %12.4lf %12.4lf %12.4lf %12.0lf %12.4lf %12.0lf"
             "%12.4lf"
             "\n",
             stats->frame, stats->weight, stats->intra_error, stats->coded_error,
@@ -1970,7 +1970,20 @@ static double calc_frame_boost(VP9_COMP *cpi, const FIRSTPASS_STATS *this_frame,
   return VPXMIN(frame_boost, GF_MAX_BOOST * boost_q_correction);
 }
 
-#define KF_BASELINE_ERR_PER_MB 12500.0
+static double kf_err_per_mb(VP9_COMP *cpi) {
+  const VP9_COMMON *const cm = &cpi->common;
+  unsigned int screen_area = (cm->width * cm->height);
+
+  // Use a different error per mb factor for calculating boost for
+  //  different formats.
+  if (screen_area < 1280 * 720) {
+    return 2000.0;
+  } else if (screen_area < 1920 * 1080) {
+    return 500.0;
+  }
+  return 250.0;
+}
+
 static double calc_kf_frame_boost(VP9_COMP *cpi,
                                   const FIRSTPASS_STATS *this_frame,
                                   double *sr_accumulator,
@@ -1983,7 +1996,7 @@ static double calc_kf_frame_boost(VP9_COMP *cpi,
   const double active_area = calculate_active_area(cpi, this_frame);
 
   // Underlying boost factor is based on inter error ratio.
-  frame_boost = (KF_BASELINE_ERR_PER_MB * active_area) /
+  frame_boost = (kf_err_per_mb(cpi) * active_area) /
                 DOUBLE_DIVIDE_CHECK(this_frame->coded_error + *sr_accumulator);
 
   // Update the accumulator for second ref error difference.
@@ -1996,8 +2009,11 @@ static double calc_kf_frame_boost(VP9_COMP *cpi,
   if (this_frame_mv_in_out > 0.0)
     frame_boost += frame_boost * (this_frame_mv_in_out * 2.0);
 
-  // Q correction and scalling
-  frame_boost = frame_boost * boost_q_correction;
+  // Q correction and scaling
+  // The 40.0 value here is an experimentally derived baseline minimum.
+  // This value is in line with the minimum per frame boost in the alt_ref
+  // boost calculation.
+  frame_boost = ((frame_boost + 40.0) * boost_q_correction);
 
   return VPXMIN(frame_boost, max_boost * boost_q_correction);
 }