shithub: libvpx

Download patch

ref: 247a28c280677b92537951f61b218d3c79ed3800
parent: d6cd3b7ec001620922f52544a81ae84a694cafbb
author: Paul Wilkins <[email protected]>
date: Thu Mar 28 09:39:54 EDT 2019

Add GF group noise weighting in rd_variance_adjustment()

For film mode add a weighting to the thresholds used
in rd_variance_adjustment() based on noise measured in the
first pass.

Change-Id: I83ca669bb55aa52f1d34f03a2268b79fba890770

--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -3140,6 +3140,7 @@
   unsigned int absvar_diff = 0;
   unsigned int var_factor = 0;
   unsigned int adj_max;
+  unsigned int low_var_thresh = LOW_VAR_THRESH;
   const int bw = num_8x8_blocks_wide_lookup[bsize];
   const int bh = num_8x8_blocks_high_lookup[bsize];
   vp9e_tune_content content_type = cpi->oxcf.content;
@@ -3164,12 +3165,23 @@
   rec_variance /= (bw * bh);
   src_variance /= (bw * bh);
 
+  if (content_type == VP9E_CONTENT_FILM) {
+    if (cpi->oxcf.pass == 2) {
+      // Adjust low variance threshold based on estimated group noise enegry.
+      double noise_factor =
+          (double)cpi->twopass.gf_group.group_noise_energy / SECTION_NOISE_DEF;
+      low_var_thresh = (unsigned int)(low_var_thresh * noise_factor);
+    }
+  } else {
+    low_var_thresh = LOW_VAR_THRESH / 2;
+  }
+
   // Lower of source (raw per pixel value) and recon variance. Note that
   // if the source per pixel is 0 then the recon value here will not be per
   // pixel (see above) so will likely be much larger.
   src_rec_min = VPXMIN(src_variance, rec_variance);
 
-  if (src_rec_min > LOW_VAR_THRESH) return;
+  if (src_rec_min > low_var_thresh) return;
 
   absvar_diff = (src_variance > rec_variance) ? (src_variance - rec_variance)
                                               : (rec_variance - src_variance);
@@ -3183,7 +3195,7 @@
   *this_rd += (*this_rd * var_factor) / 100;
 
   if (content_type == VP9E_CONTENT_FILM) {
-    if (src_rec_min <= LOW_VAR_THRESH / 2) {
+    if (src_rec_min <= low_var_thresh / 2) {
       if (ref_frame == INTRA_FRAME) {
         if (this_mode == DC_PRED)
           *this_rd *= 2;