av1/encoder/ratectrl.c
// For VBR...adjustment to the frame target based on error from previous frames
For VBR...adjustment to the frame target based on error from previous frames
For VBR ... adjustment to the frame target based on error from previous frames
static void vbr_rate_correction(AV1_COMP *cpi, int *this_frame_target) {
  RATE_CONTROL *const rc = &cpi->rc;
  int64_t vbr_bits_off_target = rc->vbr_bits_off_target;
  const int stats_count = cpi->twopass.total_stats != NULL
                              ? (int)cpi->twopass.total_stats->count
                              : 0;
  const int frame_window = AOMMIN(
      16, (int)(stats_count - (int)cpi->common.current_frame.frame_number));
  if (frame_window > 0) {
    const int max_delta =
        AOMMIN(abs((int)(vbr_bits_off_target / frame_window)),
               (*this_frame_target * VBR_PCT_ADJUSTMENT_LIMIT) / 100);
    *this_frame_target += (vbr_bits_off_target >= 0) ? max_delta : -max_delta;
  }
  if (!frame_is_kf_gf_arf(cpi) && !rc->is_src_frame_alt_ref &&
      rc->vbr_bits_off_target_fast) {
    int one_frame_bits = AOMMAX(rc->avg_frame_bandwidth, *this_frame_target);
    int fast_extra_bits;
    fast_extra_bits = (int)AOMMIN(rc->vbr_bits_off_target_fast, one_frame_bits);
    fast_extra_bits = (int)AOMMIN(
        fast_extra_bits,
        AOMMAX(one_frame_bits / 8, rc->vbr_bits_off_target_fast / 8));
    *this_frame_target += (int)fast_extra_bits;
    rc->vbr_bits_off_target_fast -= fast_extra_bits;
  }
}
static void vbr_rate_correction ( AV1_COMP * cpi , int * this_frame_target ) { RATE_CONTROL * const rc = & cpi -> rc ; int64_t vbr_bits_off_target = rc -> vbr_bits_off_target ; const int stats_count = cpi -> twopass . total_stats != NULL ? ( int ) cpi -> twopass . total_stats -> count : 0 ; const int frame_window = AOMMIN ( 16 , ( int ) ( stats_count - ( int ) cpi -> common . current_frame . frame_number ) ) ; if ( frame_window > 0 ) { const int max_delta = AOMMIN ( abs ( ( int ) ( vbr_bits_off_target / frame_window ) ) , ( * this_frame_target * VBR_PCT_ADJUSTMENT_LIMIT ) / 100 ) ; * this_frame_target += ( vbr_bits_off_target >= 0 ) ? max_delta : - max_delta ; } if ( ! frame_is_kf_gf_arf ( cpi ) && ! rc -> is_src_frame_alt_ref && rc -> vbr_bits_off_target_fast ) { int one_frame_bits = AOMMAX ( rc -> avg_frame_bandwidth , * this_frame_target ) ; int fast_extra_bits ; fast_extra_bits = ( int ) AOMMIN ( rc -> vbr_bits_off_target_fast , one_frame_bits ) ; fast_extra_bits = ( int ) AOMMIN ( fast_extra_bits , AOMMAX ( one_frame_bits / 8 , rc -> vbr_bits_off_target_fast / 8 ) ) ; * this_frame_target += ( int ) fast_extra_bits ; rc -> vbr_bits_off_target_fast -= fast_extra_bits ; } }
For VBR...adjustment to the frame target based on error from previous frames
For VBR ... adjustment to the frame target based on error from previous frames
// vbr_bits_off_target > 0 means we have extra bits to spend // vbr_bits_off_target < 0 we are currently overshooting // Fast redistribution of bits arising from massive local undershoot. // Dont do it for kf,arf,gf or overlay frames.