Skip to content

Commit

Permalink
Limit the number of bits allocated for the intra frame with --intra-bits
Browse files Browse the repository at this point in the history
Additionally fix a small issue with the dynamic sliding window when gop_len <= 1
  • Loading branch information
Jovasa committed Jul 17, 2023
1 parent 49dc5fc commit aab6aa9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/rate_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static double gop_allocate_bits(encoder_state_t * const state)
bits_coded -= state->frame->cur_gop_bits_coded;
}

smoothing_window = MAX(MIN_SMOOTHING_WINDOW, smoothing_window - encoder->cfg.gop_len / 2);
smoothing_window = MAX(MIN_SMOOTHING_WINDOW, smoothing_window - MAX(encoder->cfg.gop_len / 2, 1));
double gop_target_bits = -1;

while( gop_target_bits < 0 && smoothing_window < 150) {
Expand Down Expand Up @@ -375,7 +375,7 @@ static double pic_allocate_bits(encoder_state_t * const state)
else {
alpha = 0.3;
}
return MAX(100, alpha*pow(state->frame->icost * 4 / bits, beta)*bits);
return MIN(MAX(100, alpha*pow(state->frame->icost * 4 / bits, beta)*bits), encoder->cfg.gop_len >= 2 ? 0.85 * state->frame->cur_gop_target_bits : state->frame->cur_gop_target_bits);
}

if (encoder->cfg.gop_len <= 0) {
Expand Down

0 comments on commit aab6aa9

Please sign in to comment.