Skip to content

Commit

Permalink
rtc-vp9: Fix to overshoot for 1 pass VBR no lookahead
Browse files Browse the repository at this point in the history
Use the buffer_level to monitor the long-term bitrate
over/undershoot and avoid going to very low QP for
overshoot. This also required adding the
vp9_update_buffer_level_preencode() for the 1 pass VBR
encoding (as is done for CBR).

This reduces the overshoot in the issue below.

Bug: 376707227
Change-Id: Idae2bb0934543063e09ba7c32f80806cc9494f13
  • Loading branch information
marco99zz committed Dec 17, 2024
1 parent 6f0c446 commit a68a58b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions vp9/encoder/vp9_ratectrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,27 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
} else {
q = vp9_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality,
active_worst_quality);

// For no lookahead: if buffer_level indicates overshoot, then avoid going
// to very low QP. This reduces overshoot observed in Issue: 376707227.
// Note the buffer_level is updated for every encoded frame as:
// buffer_level - starting_buffer_level += (avg_frame_bandwidth -
// encoded_frame_size). So normalizing this with framerate and #encoded
// frames (current_video_frame) gives the difference/error between target
// and encoding bitrate. The additional avg_frame_bandwidth term is to
// compensate for the pre-encoded buffer update (in
// vp9_rc_get_one_pass_vbr_params).
const int bitrate_err =
(int)(cpi->framerate *
(rc->buffer_level - rc->starting_buffer_level -
rc->avg_frame_bandwidth) /
(cm->current_video_frame + 1));
// Threshold may be tuned, but for now condition this on low QP.
if (cpi->oxcf.lag_in_frames == 0 && bitrate_err / 1000 < -10 && q < 24) {
q = 24;
*top_index = VPXMAX(*top_index, q);
}

if (q > *top_index) {
// Special case when we are targeting the max allowed rate
if (rc->this_frame_target >= rc->max_frame_bandwidth)
Expand Down Expand Up @@ -2126,6 +2147,7 @@ void vp9_rc_get_one_pass_vbr_params(VP9_COMP *cpi) {
else
target = vp9_calc_pframe_target_size_one_pass_vbr(cpi);
vp9_rc_set_frame_target(cpi, target);
if (cm->show_frame) vp9_update_buffer_level_preencode(cpi);
if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cpi->oxcf.pass == 0)
vp9_cyclic_refresh_update_parameters(cpi);
}
Expand Down

0 comments on commit a68a58b

Please sign in to comment.