shithub: libvpx

Download patch

ref: fe2fd37bb2121cbbb95d826089d88357e70c87a8
parent: 60d192db04b23b386fe30059b807101867725896
author: Marco <marpan@google.com>
date: Fri Oct 24 05:31:38 EDT 2014

vp8: Updates to noise level estimate.

-Use full bandwidth (when temporal layers is on) for checking switching.
-Normalize metric wrt num_blocks.
-Rounding fix to update of average noise level metric.
-Make default internal denoiser mode == kDenoiserOnYUV (in denoiser set_parameters()).
-Adjust some thresholds.

Change-Id: Ib827512b25a7bf1f66c76d3045f3a68ce56b1cd2

--- a/vp8/encoder/denoising.c
+++ b/vp8/encoder/denoising.c
@@ -374,7 +374,7 @@
   } else if (mode == 3) {
     denoiser->denoiser_mode = kDenoiserOnYUVAggressive;
   } else {
-    denoiser->denoiser_mode = kDenoiserOnAdaptive;
+    denoiser->denoiser_mode = kDenoiserOnYUV;
   }
   if (denoiser->denoiser_mode != kDenoiserOnYUVAggressive) {
     denoiser->denoise_pars.scale_sse_thresh = 1;
@@ -393,7 +393,7 @@
     denoiser->denoise_pars.pickmode_mv_bias = 75;
     denoiser->denoise_pars.qp_thresh = 85;
     denoiser->denoise_pars.consec_zerolast = 15;
-    denoiser->denoise_pars.spatial_blur = 20;
+    denoiser->denoise_pars.spatial_blur = 0;
   }
 }
 
@@ -453,16 +453,16 @@
     // Bitrate thresholds and noise metric (nmse) thresholds for switching to
     // aggressive mode.
     // TODO(marpan): Adjust thresholds, including effect on resolution.
-    denoiser->bitrate_threshold = 300000;  // (bits/sec).
-    denoiser->threshold_aggressive_mode = 35;
+    denoiser->bitrate_threshold = 400000;  // (bits/sec).
+    denoiser->threshold_aggressive_mode = 80;
     if (width * height > 1280 * 720) {
-      denoiser->bitrate_threshold = 2000000;
-      denoiser->threshold_aggressive_mode = 1400;
+      denoiser->bitrate_threshold = 2500000;
+      denoiser->threshold_aggressive_mode = 180;
     } else if (width * height > 960 * 540) {
-      denoiser->bitrate_threshold = 800000;
-      denoiser->threshold_aggressive_mode = 150;
+      denoiser->bitrate_threshold = 1000000;
+      denoiser->threshold_aggressive_mode = 120;
     } else if (width * height > 640 * 480) {
-      denoiser->bitrate_threshold = 500000;
+      denoiser->bitrate_threshold = 600000;
       denoiser->threshold_aggressive_mode = 100;
     }
     return 0;
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -3305,12 +3305,12 @@
   // Only select blocks for computing nmse that have been encoded
   // as ZERO LAST min_consec_zero_last frames in a row.
   // Scale with number of temporal layers.
-  int min_consec_zero_last = 8 / cpi->oxcf.number_of_layers;
+  int min_consec_zero_last = 12 / cpi->oxcf.number_of_layers;
   // Decision is tested for changing the denoising mode every
   // num_mode_change times this function is called. Note that this
   // function called every 8 frames, so (8 * num_mode_change) is number
   // of frames where denoising mode change is tested for switch.
-  int num_mode_change = 15;
+  int num_mode_change = 20;
   // Framerate factor, to compensate for larger mse at lower framerates.
   // Use ref_framerate, which is full source framerate for temporal layers.
   // TODO(marpan): Adjust this factor.
@@ -3322,7 +3322,12 @@
   static const unsigned char const_source[16] = {
       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
       128, 128, 128};
-
+  int bandwidth = (int)(cpi->target_bandwidth);
+  // For temporal layers, use full bandwidth (top layer).
+  if (cpi->oxcf.number_of_layers > 1) {
+    LAYER_CONTEXT *lc = &cpi->layer_context[cpi->oxcf.number_of_layers - 1];
+    bandwidth = (int)(lc->target_bandwidth);
+  }
   // Loop through the Y plane, every skip blocks along rows and columns,
   // summing the normalized mean square error, only for blocks that have
   // been encoded as ZEROMV LAST at least min_consec_zero_last least frames in
@@ -3366,6 +3371,7 @@
   if (total > 0 &&
       (num_blocks > (tot_num_blocks >> 4))) {
     // Update the recursive mean square source_diff.
+    total = (total << 8) / num_blocks;
     if (cpi->denoiser.nmse_source_diff_count == 0) {
       // First sample in new interval.
       cpi->denoiser.nmse_source_diff = total;
@@ -3372,10 +3378,10 @@
       cpi->denoiser.qp_avg = cm->base_qindex;
     } else {
       // For subsequent samples, use average with weight ~1/4 for new sample.
-      cpi->denoiser.nmse_source_diff = (int)((total >> 2) +
-          3 * (cpi->denoiser.nmse_source_diff >> 2));
-      cpi->denoiser.qp_avg = (int)((cm->base_qindex >> 2) +
-          3 * (cpi->denoiser.qp_avg >> 2));
+      cpi->denoiser.nmse_source_diff = (int)((total +
+          3 * cpi->denoiser.nmse_source_diff) >> 2);
+      cpi->denoiser.qp_avg = (int)((cm->base_qindex +
+          3 * cpi->denoiser.qp_avg) >> 2);
     }
     cpi->denoiser.nmse_source_diff_count++;
   }
@@ -3387,7 +3393,7 @@
         (cpi->denoiser.nmse_source_diff >
         cpi->denoiser.threshold_aggressive_mode) &&
         (cpi->denoiser.qp_avg < cpi->denoiser.qp_threshold_up &&
-         cpi->target_bandwidth > cpi->denoiser.bitrate_threshold)) {
+         bandwidth > cpi->denoiser.bitrate_threshold)) {
       vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUVAggressive);
     } else {
       // Check for going down: from aggressive to normal mode.
@@ -3396,7 +3402,7 @@
           cpi->denoiser.threshold_aggressive_mode)) ||
           ((cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive) &&
           (cpi->denoiser.qp_avg > cpi->denoiser.qp_threshold_down ||
-           cpi->target_bandwidth < cpi->denoiser.bitrate_threshold))) {
+           bandwidth < cpi->denoiser.bitrate_threshold))) {
         vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUV);
       }
     }