From 422d7bc918386b81ce5487c13898b78db241cd06 Mon Sep 17 00:00:00 2001 From: Paul Wilkins Date: Tue, 28 Oct 2014 13:03:06 +0000 Subject: [PATCH] Relax maximum Q for extreme overshoot. Added code to relax the active maximum Q in response to extreme local overshoot to reduce bandwidth peaks. The impact is small in metrics terms, but it this helps reduce bandwidth spikes and overall overshoot in a number of clips in our tests sets (especially the YT test set). In particular this should help prevent very big spikes where a clip is mainly easy but has a short hard section. In such a case a choice of maximum Q for the clip as a whole may allow us to hit the overall target rate but give some extreme spikes. The chunked encoding in YT mitigates this problem but it can show up where a longer clip is coded as a single chunk. Change-Id: I213d09950ccb8489d10adf00fda1e53235b39203 --- vp9/encoder/vp9_firstpass.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index 5a67ef414..c8c784b73 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -2478,7 +2478,6 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { } #define MINQ_ADJ_LIMIT 32 -#define Q_LIMIT_STEP 1 void vp9_twopass_postencode_update(VP9_COMP *cpi) { TWO_PASS *const twopass = &cpi->twopass; RATE_CONTROL *const rc = &cpi->rc; @@ -2523,16 +2522,22 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) { if (rc->rate_error_estimate > cpi->oxcf.under_shoot_pct) { --twopass->extend_maxq; if (rc->rolling_target_bits >= rc->rolling_actual_bits) - twopass->extend_minq += Q_LIMIT_STEP; + ++twopass->extend_minq; // Overshoot. } else if (rc->rate_error_estimate < -cpi->oxcf.over_shoot_pct) { --twopass->extend_minq; if (rc->rolling_target_bits < rc->rolling_actual_bits) - twopass->extend_maxq += Q_LIMIT_STEP; + ++twopass->extend_maxq; } else { + // Adjustment for extreme local overshoot. + if (rc->projected_frame_size > (2 * rc->base_frame_target) && + rc->projected_frame_size > (2 * rc->avg_frame_bandwidth)) + ++twopass->extend_maxq; + + // Unwind undershoot or overshoot adjustment. if (rc->rolling_target_bits < rc->rolling_actual_bits) --twopass->extend_minq; - if (rc->rolling_target_bits > rc->rolling_actual_bits) + else if (rc->rolling_target_bits > rc->rolling_actual_bits) --twopass->extend_maxq; } twopass->extend_minq = clamp(twopass->extend_minq, 0, MINQ_ADJ_LIMIT); -- 2.40.0