Commit e2b4ef13 authored by paulwilkins's avatar paulwilkins Committed by Gerrit Code Review
Browse files

Merge "Account for rate error in GF group Q calculation."

parents 3e1d14a6 8d7f53f0
...@@ -57,6 +57,8 @@ ...@@ -57,6 +57,8 @@
#define SVC_FACTOR_PT_LOW 0.45 #define SVC_FACTOR_PT_LOW 0.45
#define DARK_THRESH 64 #define DARK_THRESH 64
#define DEFAULT_GRP_WEIGHT 1.0 #define DEFAULT_GRP_WEIGHT 1.0
#define RC_FACTOR_MIN 0.75
#define RC_FACTOR_MAX 1.75
#define DOUBLE_DIVIDE_CHECK(x) ((x) < 0 ? (x) - 0.000001 : (x) + 0.000001) #define DOUBLE_DIVIDE_CHECK(x) ((x) < 0 ? (x) - 0.000001 : (x) + 0.000001)
...@@ -1960,16 +1962,21 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { ...@@ -1960,16 +1962,21 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
const int vbr_group_bits_per_frame = const int vbr_group_bits_per_frame =
(int)(gf_group_bits / rc->baseline_gf_interval); (int)(gf_group_bits / rc->baseline_gf_interval);
const double group_av_err = gf_group_raw_error / rc->baseline_gf_interval; const double group_av_err = gf_group_raw_error / rc->baseline_gf_interval;
const int tmp_q = int tmp_q;
get_twopass_worst_quality(cpi, group_av_err, vbr_group_bits_per_frame, // rc factor is a weight factor that corrects for local rate control drift.
twopass->kfgroup_inter_fraction); double rc_factor = 1.0;
if (rc->rate_error_estimate > 0) {
if (tmp_q < twopass->baseline_active_worst_quality) { rc_factor = MAX(RC_FACTOR_MIN,
twopass->active_worst_quality = (double)(100 - rc->rate_error_estimate) / 100.0);
(tmp_q + twopass->baseline_active_worst_quality + 1) / 2;
} else { } else {
twopass->active_worst_quality = tmp_q; rc_factor = MIN(RC_FACTOR_MAX,
(double)(100 - rc->rate_error_estimate) / 100.0);
} }
tmp_q =
get_twopass_worst_quality(cpi, group_av_err, vbr_group_bits_per_frame,
twopass->kfgroup_inter_fraction * rc_factor);
twopass->active_worst_quality =
MAX(tmp_q, twopass->active_worst_quality >> 1);
} }
#endif #endif
...@@ -2577,7 +2584,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { ...@@ -2577,7 +2584,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
subtract_stats(&twopass->total_left_stats, &this_frame); subtract_stats(&twopass->total_left_stats, &this_frame);
} }
#define MINQ_ADJ_LIMIT 32 #define MINQ_ADJ_LIMIT 48
void vp9_twopass_postencode_update(VP9_COMP *cpi) { void vp9_twopass_postencode_update(VP9_COMP *cpi) {
TWO_PASS *const twopass = &cpi->twopass; TWO_PASS *const twopass = &cpi->twopass;
RATE_CONTROL *const rc = &cpi->rc; RATE_CONTROL *const rc = &cpi->rc;
...@@ -2610,8 +2617,7 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) { ...@@ -2610,8 +2617,7 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) {
// Increment the gf group index ready for the next frame. // Increment the gf group index ready for the next frame.
++twopass->gf_group.index; ++twopass->gf_group.index;
// If the rate control is drifting consider adjustment ot min or maxq. // If the rate control is drifting consider adjustment to min or maxq.
// Only make adjustments on gf/arf
if ((cpi->oxcf.rc_mode == VPX_VBR) && if ((cpi->oxcf.rc_mode == VPX_VBR) &&
(cpi->twopass.gf_zeromotion_pct < VLOW_MOTION_THRESHOLD) && (cpi->twopass.gf_zeromotion_pct < VLOW_MOTION_THRESHOLD) &&
!cpi->rc.is_src_frame_alt_ref) { !cpi->rc.is_src_frame_alt_ref) {
...@@ -2640,6 +2646,7 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) { ...@@ -2640,6 +2646,7 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) {
else if (rc->rolling_target_bits > rc->rolling_actual_bits) else if (rc->rolling_target_bits > rc->rolling_actual_bits)
--twopass->extend_maxq; --twopass->extend_maxq;
} }
twopass->extend_minq = clamp(twopass->extend_minq, 0, MINQ_ADJ_LIMIT); twopass->extend_minq = clamp(twopass->extend_minq, 0, MINQ_ADJ_LIMIT);
twopass->extend_maxq = clamp(twopass->extend_maxq, 0, maxq_adj_limit); twopass->extend_maxq = clamp(twopass->extend_maxq, 0, maxq_adj_limit);
} }
......
...@@ -158,8 +158,8 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, ...@@ -158,8 +158,8 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
RANGE_CHECK_HI(cfg, g_threads, 64); RANGE_CHECK_HI(cfg, g_threads, 64);
RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS); RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS);
RANGE_CHECK(cfg, rc_end_usage, VPX_VBR, VPX_Q); RANGE_CHECK(cfg, rc_end_usage, VPX_VBR, VPX_Q);
RANGE_CHECK_HI(cfg, rc_undershoot_pct, 1000); RANGE_CHECK_HI(cfg, rc_undershoot_pct, 100);
RANGE_CHECK_HI(cfg, rc_overshoot_pct, 1000); RANGE_CHECK_HI(cfg, rc_overshoot_pct, 100);
RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100); RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100);
RANGE_CHECK(cfg, kf_mode, VPX_KF_DISABLED, VPX_KF_AUTO); RANGE_CHECK(cfg, kf_mode, VPX_KF_DISABLED, VPX_KF_AUTO);
RANGE_CHECK_BOOL(cfg, rc_resize_allowed); RANGE_CHECK_BOOL(cfg, rc_resize_allowed);
......
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