ref: 3caaf21c5be04d012426b3e6a1b58a5d2c9700a8
parent: d35541fe292fd8778d7212234a0bce633cda43af
parent: 9a7625652c94ab2d699cb1066ba6de24ceea3cfa
author: Paul Wilkins <paulwilkins@google.com>
date: Thu May 11 14:25:44 EDT 2017
Merge "Tuning of factor used to calculate Q range in two pass."
--- 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,