ref: 9a7625652c94ab2d699cb1066ba6de24ceea3cfa
parent: 8053dba5a1470a9ced7236f5b692b16f0d7b8a98
author: paulwilkins <[email protected]>
date: Wed May 10 12:07:13 EDT 2017
Tuning of factor used to calculate Q range in two pass. A more detailed explanation of the experimentation leading to this change can be found in:- https://docs.google.com/a/google.com/document/d/13lsYhxgPyxUHvEess6wg9nikaonIZKY9Ak_Lpafv5Mo/edit?usp=sharing This change gives gains across all our standard test sets for overall psnr, ssim, fast ssim and psnr-HVS. Values expressed as % reduction in bitrate. Low res set -0.257, -0.192, -0.173, -0.101 Mid res set -0.233, -0.336, -0.367, -0.139 High res set -0.999, -1.039, -1.111, -0.567 NetFlix 2K set -0.734, -0.174, -0.389, -0.820 Netflix 4K set -0.814, -0.485, -0.796, -0.839 Change-Id: Ie981fb3c895c9dfcfc8682640d201a86375db5c8
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -42,8 +42,6 @@
#define OUTPUT_FPF 0
#define ARF_STATS_OUTPUT 0
-#define FACTOR_PT_LOW 0.70
-#define FACTOR_PT_HIGH 0.90
#define FIRST_PASS_Q 10.0
#define GF_MAX_BOOST 96.0
#define INTRA_MODE_PENALTY 1024
@@ -50,7 +48,6 @@
#define MIN_ARF_GF_BOOST 240
#define MIN_DECAY_FACTOR 0.01
#define NEW_MV_MODE_PENALTY 32
-#define SVC_FACTOR_PT_LOW 0.45
#define DARK_THRESH 64
#define DEFAULT_GRP_WEIGHT 1.0
#define RC_FACTOR_MIN 0.75
@@ -1522,15 +1519,23 @@
if (cpi->use_svc) vp9_inc_frame_in_layer(cpi);
}
+static const double q_pow_term[(QINDEX_RANGE >> 5) + 1] = {
+ 0.65, 0.70, 0.75, 0.85, 0.90, 0.90, 0.90, 1.00, 1.25
+};
+
static double calc_correction_factor(double err_per_mb, double err_divisor,
- double pt_low, double pt_high, int q,
- vpx_bit_depth_t bit_depth) {
- const double error_term = err_per_mb / err_divisor;
+ int q) {
+ const double error_term = err_per_mb / DOUBLE_DIVIDE_CHECK(err_divisor);
+ const int index = q >> 5;
+ double power_term;
- // Adjustment based on actual quantizer to power term.
- const double power_term =
- VPXMIN(vp9_convert_qindex_to_q(q, bit_depth) * 0.01 + pt_low, pt_high);
+ assert((index >= 0) && (index < (QINDEX_RANGE >> 5)));
+ // Adjustment based on quantizer to the power term.
+ power_term =
+ q_pow_term[index] +
+ (((q_pow_term[index + 1] - q_pow_term[index]) * (q % 32)) / 32.0);
+
// Calculate correction factor.
if (power_term < 1.0) assert(error_term >= 0.0);
@@ -1567,11 +1572,7 @@
const int target_norm_bits_per_mb =
(int)(((uint64_t)target_rate << BPER_MB_NORMBITS) / active_mbs);
int q;
- int is_svc_upper_layer = 0;
- 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 /
@@ -1583,10 +1584,8 @@
// 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) {
- const double factor = calc_correction_factor(
- av_err_per_mb, ERR_DIVISOR,
- is_svc_upper_layer ? SVC_FACTOR_PT_LOW : FACTOR_PT_LOW,
- FACTOR_PT_HIGH, q, cpi->common.bit_depth);
+ const double factor =
+ calc_correction_factor(av_err_per_mb, ERR_DIVISOR, q);
const int bits_per_mb = vp9_rc_bits_per_mb(
INTER_FRAME, q,
factor * speed_term * cpi->twopass.bpm_factor * noise_factor,