Commit 5ef54c15 authored by Paul Wilkins's avatar Paul Wilkins Committed by Gerrit Code Review

Merge "Adjustment calculation of active worst quality."

parents 7a586cad cd700e1a
...@@ -1248,13 +1248,14 @@ static double calc_correction_factor(double err_per_mb, ...@@ -1248,13 +1248,14 @@ static double calc_correction_factor(double err_per_mb,
} }
#define ERR_DIVISOR 100.0 #define ERR_DIVISOR 100.0
static int get_twopass_worst_quality(const VP9_COMP *cpi, static int get_twopass_worst_quality(VP9_COMP *cpi,
const double section_err, const double section_err,
double inactive_zone, double inactive_zone,
int section_target_bandwidth, int section_target_bandwidth) {
double group_weight_factor) {
const RATE_CONTROL *const rc = &cpi->rc; const RATE_CONTROL *const rc = &cpi->rc;
const VP9EncoderConfig *const oxcf = &cpi->oxcf; const VP9EncoderConfig *const oxcf = &cpi->oxcf;
TWO_PASS *const twopass = &cpi->twopass;
// Clamp the target rate to VBR min / max limts. // Clamp the target rate to VBR min / max limts.
const int target_rate = const int target_rate =
vp9_rc_clamp_pframe_target_size(cpi, section_target_bandwidth); vp9_rc_clamp_pframe_target_size(cpi, section_target_bandwidth);
...@@ -1270,6 +1271,7 @@ static int get_twopass_worst_quality(const VP9_COMP *cpi, ...@@ -1270,6 +1271,7 @@ static int get_twopass_worst_quality(const VP9_COMP *cpi,
const double av_err_per_mb = section_err / active_mbs; const double av_err_per_mb = section_err / active_mbs;
const double speed_term = 1.0 + 0.04 * oxcf->speed; const double speed_term = 1.0 + 0.04 * oxcf->speed;
double ediv_size_correction; double ediv_size_correction;
double last_group_rate_err;
const int target_norm_bits_per_mb = ((uint64_t)target_rate << const int target_norm_bits_per_mb = ((uint64_t)target_rate <<
BPER_MB_NORMBITS) / active_mbs; BPER_MB_NORMBITS) / active_mbs;
int q; int q;
...@@ -1289,6 +1291,15 @@ static int get_twopass_worst_quality(const VP9_COMP *cpi, ...@@ -1289,6 +1291,15 @@ static int get_twopass_worst_quality(const VP9_COMP *cpi,
ediv_size_correction = -(1.0 / ediv_size_correction); ediv_size_correction = -(1.0 / ediv_size_correction);
ediv_size_correction *= 4.0; ediv_size_correction *= 4.0;
// based on recent history adjust expectations of bits per macroblock.
last_group_rate_err = (double)twopass->rolling_arf_group_actual_bits /
DOUBLE_DIVIDE_CHECK((double)twopass->rolling_arf_group_target_bits);
last_group_rate_err =
VPXMAX(0.25, VPXMIN(4.0, last_group_rate_err));
twopass->bpm_factor *= (1.0 + last_group_rate_err) / 2.0;
twopass->bpm_factor =
VPXMAX(0.25, VPXMIN(4.0, twopass->bpm_factor));
// Try and pick a max Q that will be high enough to encode the // Try and pick a max Q that will be high enough to encode the
// content at the given rate. // content at the given rate.
for (q = rc->best_quality; q < rc->worst_quality; ++q) { for (q = rc->best_quality; q < rc->worst_quality; ++q) {
...@@ -1300,7 +1311,7 @@ static int get_twopass_worst_quality(const VP9_COMP *cpi, ...@@ -1300,7 +1311,7 @@ static int get_twopass_worst_quality(const VP9_COMP *cpi,
cpi->common.bit_depth); cpi->common.bit_depth);
const int bits_per_mb = const int bits_per_mb =
vp9_rc_bits_per_mb(INTER_FRAME, q, vp9_rc_bits_per_mb(INTER_FRAME, q,
factor * speed_term * group_weight_factor, factor * speed_term * cpi->twopass.bpm_factor,
cpi->common.bit_depth); cpi->common.bit_depth);
if (bits_per_mb <= target_norm_bits_per_mb) if (bits_per_mb <= target_norm_bits_per_mb)
break; break;
...@@ -2183,21 +2194,10 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { ...@@ -2183,21 +2194,10 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
((gf_group_inactive_zone_rows * 2) / ((gf_group_inactive_zone_rows * 2) /
(rc->baseline_gf_interval * (double)cm->mb_rows)); (rc->baseline_gf_interval * (double)cm->mb_rows));
int tmp_q; int tmp_q =
// rc factor is a weight factor that corrects for local rate control drift. get_twopass_worst_quality(cpi, group_av_err,
double rc_factor = 1.0; (group_av_skip_pct + group_av_inactive_zone),
if (rc->rate_error_estimate > 0) { vbr_group_bits_per_frame);
rc_factor = VPXMAX(RC_FACTOR_MIN,
(double)(100 - rc->rate_error_estimate) / 100.0);
} else {
rc_factor = VPXMIN(RC_FACTOR_MAX,
(double)(100 - rc->rate_error_estimate) / 100.0);
}
tmp_q =
get_twopass_worst_quality(cpi, group_av_err,
(group_av_skip_pct + group_av_inactive_zone),
vbr_group_bits_per_frame,
twopass->kfgroup_inter_fraction * rc_factor);
twopass->active_worst_quality = twopass->active_worst_quality =
VPXMAX(tmp_q, twopass->active_worst_quality >> 1); VPXMAX(tmp_q, twopass->active_worst_quality >> 1);
} }
...@@ -2241,6 +2241,10 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { ...@@ -2241,6 +2241,10 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// Default to starting GF groups at normal frame size. // Default to starting GF groups at normal frame size.
cpi->rc.next_frame_size_selector = UNSCALED; cpi->rc.next_frame_size_selector = UNSCALED;
} }
// Reset rolling actual and target bits counters for ARF groups.
twopass->rolling_arf_group_target_bits = 0;
twopass->rolling_arf_group_actual_bits = 0;
} }
// Threshold for use of the lagging second reference frame. High second ref // Threshold for use of the lagging second reference frame. High second ref
...@@ -2748,10 +2752,17 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { ...@@ -2748,10 +2752,17 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
const double section_inactive_zone = const double section_inactive_zone =
(twopass->total_left_stats.inactive_zone_rows * 2) / (twopass->total_left_stats.inactive_zone_rows * 2) /
((double)cm->mb_rows * section_length); ((double)cm->mb_rows * section_length);
const int tmp_q = int tmp_q;
get_twopass_worst_quality(cpi, section_error,
section_intra_skip + section_inactive_zone, // Initialize bits per macro_block estimate correction factor.
section_target_bandwidth, DEFAULT_GRP_WEIGHT); twopass->bpm_factor = 1.0;
// Initiallize actual and target bits counters for ARF groups so that
// at the start we have a neutral bpm adjustment.
twopass->rolling_arf_group_target_bits = 1;
twopass->rolling_arf_group_actual_bits = 1;
tmp_q = get_twopass_worst_quality(cpi, section_error,
section_intra_skip + section_inactive_zone, section_target_bandwidth);
twopass->active_worst_quality = tmp_q; twopass->active_worst_quality = tmp_q;
twopass->baseline_active_worst_quality = tmp_q; twopass->baseline_active_worst_quality = tmp_q;
...@@ -2869,6 +2880,10 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) { ...@@ -2869,6 +2880,10 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) {
rc->vbr_bits_off_target += rc->base_frame_target - rc->projected_frame_size; rc->vbr_bits_off_target += rc->base_frame_target - rc->projected_frame_size;
twopass->bits_left = VPXMAX(twopass->bits_left - bits_used, 0); twopass->bits_left = VPXMAX(twopass->bits_left - bits_used, 0);
// Target vs actual bits for this arf group.
twopass->rolling_arf_group_target_bits += rc->this_frame_target;
twopass->rolling_arf_group_actual_bits += rc->projected_frame_size;
// Calculate the pct rc error. // Calculate the pct rc error.
if (rc->total_actual_bits) { if (rc->total_actual_bits) {
rc->rate_error_estimate = rc->rate_error_estimate =
......
...@@ -125,8 +125,11 @@ typedef struct { ...@@ -125,8 +125,11 @@ typedef struct {
// The fraction for a kf groups total bits allocated to the inter frames // The fraction for a kf groups total bits allocated to the inter frames
double kfgroup_inter_fraction; double kfgroup_inter_fraction;
int sr_update_lag; double bpm_factor;
int rolling_arf_group_target_bits;
int rolling_arf_group_actual_bits;
int sr_update_lag;
int kf_zeromotion_pct; int kf_zeromotion_pct;
int last_kfgroup_zeromotion_pct; int last_kfgroup_zeromotion_pct;
int active_worst_quality; int active_worst_quality;
......
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