From: Paul Wilkins Date: Thu, 9 Feb 2017 17:17:55 +0000 (+0000) Subject: Merge "Fix to avoid abrupt relaxation of max qindex in recode path" X-Git-Tag: v1.7.0~740 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3f095c8b3c6eac510e892a7624162da1a655593;p=libvpx Merge "Fix to avoid abrupt relaxation of max qindex in recode path" --- c3f095c8b3c6eac510e892a7624162da1a655593 diff --cc vp9/encoder/vp9_encoder.c index 323907fc3,1e283aac0..50fa8c682 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@@ -3507,14 -3792,17 +3507,20 @@@ static void encode_with_recode_loop(VP9 // Frame is too large if (rc->projected_frame_size > rc->this_frame_target) { // Special case if the projected size is > the max allowed. - if (rc->projected_frame_size >= rc->max_frame_bandwidth) - q_high = rc->worst_quality; + if (rc->projected_frame_size >= rc->max_frame_bandwidth) { + double q_val_high; + q_val_high = vp9_convert_qindex_to_q(q_high, cm->bit_depth); + q_val_high = q_val_high * ((double)rc->projected_frame_size / + rc->max_frame_bandwidth); + q_high = vp9_convert_q_to_qindex(q_val_high, cm->bit_depth); + q_high = clamp(q_high, rc->best_quality, rc->worst_quality); + } // Raise Qlow as to at least the current value - q_low = q < q_high ? q + 1 : q_high; + qstep = + get_qstep_adj(rc->projected_frame_size, rc->this_frame_target); + q_low = VPXMIN(q + qstep, q_high); + // q_low = q < q_high ? q + 1 : q_high; if (undershoot_seen || loop_at_this_size > 1) { // Update rate_correction_factor unless diff --cc vp9/encoder/vp9_ratectrl.c index 2013bf59e,bb95f7c31..03bc720a9 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@@ -166,8 -174,22 +166,21 @@@ double vp9_convert_qindex_to_q(int qind #endif } + int vp9_convert_q_to_qindex(double q_val, vpx_bit_depth_t bit_depth) { + int i; + + for (i = 0; i < QINDEX_RANGE; ++i) + if (vp9_convert_qindex_to_q(i, bit_depth) >= q_val) + break; + + if (i == QINDEX_RANGE) + i--; + + return i; + } + int vp9_rc_bits_per_mb(FRAME_TYPE frame_type, int qindex, - double correction_factor, - vpx_bit_depth_t bit_depth) { + double correction_factor, vpx_bit_depth_t bit_depth) { const double q = vp9_convert_qindex_to_q(qindex, bit_depth); int enumerator = frame_type == KEY_FRAME ? 2700000 : 1800000;