Improve q_high adjustment for large overshoot. In recode loop, when we get a large overshoot: - Adjust q_high only when current 'q' is already at 'q_high' - Also, and adaptively adjust q_high only as much as needed, instead of directly picking the worst quality. This is a: - Cherry-pick of VP9 commit: https://chromium-review.googlesource.com/c/webm/libvpx/+/424299 - And a single line change from: https://chromium-review.googlesource.com/c/webm/libvpx/+/544870 hdres/mobcal_720p50: -1.948% Other hdres clips: neutral lowres,midres,ugc360p: neutral STATS_CHANGED Change-Id: I2f3f0e292d0ccf184f36bedd85f7ab1e7de46518
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c index 707f9ea..4258eec 100644 --- a/av1/encoder/encoder.c +++ b/av1/encoder/encoder.c
@@ -4531,8 +4531,16 @@ // 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 (*q == *q_high && + rc->projected_frame_size >= rc->max_frame_bandwidth) { + const double q_val_high_current = + av1_convert_qindex_to_q(*q_high, cm->seq_params.bit_depth); + const double q_val_high_new = + q_val_high_current * + ((double)rc->projected_frame_size / rc->max_frame_bandwidth); + *q_high = av1_find_qindex(q_val_high_new, cm->seq_params.bit_depth, + rc->best_quality, rc->worst_quality); + } // Raise Qlow as to at least the current value *q_low = *q < *q_high ? *q + 1 : *q_high;