Commit fe2fd37b authored by Marco's avatar Marco
Browse files

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
parent 60d192db
......@@ -374,7 +374,7 @@ void vp8_denoiser_set_parameters(VP8_DENOISER *denoiser, int mode) {
} 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 @@ void vp8_denoiser_set_parameters(VP8_DENOISER *denoiser, int mode) {
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 @@ int vp8_denoiser_allocate(VP8_DENOISER *denoiser, int width, int height,
// 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;
......
......@@ -3305,12 +3305,12 @@ static void process_denoiser_mode_change(VP8_COMP *cpi) {
// 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 void process_denoiser_mode_change(VP8_COMP *cpi) {
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,16 +3371,17 @@ static void process_denoiser_mode_change(VP8_COMP *cpi) {
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;
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 @@ static void process_denoiser_mode_change(VP8_COMP *cpi) {
(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 @@ static void process_denoiser_mode_change(VP8_COMP *cpi) {
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);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment