Don't assume anything about bits spent

This commit is contained in:
Joose Sainio 2018-11-07 16:03:38 +02:00
parent 3471e2470d
commit 1c8a1f24e2

View file

@ -79,26 +79,8 @@ static double gop_allocate_bits(encoder_state_t * const state)
int pictures_coded = MAX(0, state->frame->num - encoder->cfg.owf);
int gop_offset = (state->frame->gop_offset - encoder->cfg.owf) % MAX(1, encoder->cfg.gop_len);
if(encoder->cfg.gop_lp_definition.d != 0 && encoder->cfg.gop_lp_definition.t != 0)
{
// With LP-GOP the bits coded is not always updated correctly so this is
// a band-aid fix for getting a better bit allocation
if (state->frame->num > 0) {
uint64_t previous_bits = state->previous_encoder_state->frame->cur_pic_target_bits;
bits_coded = previous_bits > bits_coded ? 0 : bits_coded - previous_bits;
}
else
{
bits_coded = 0;
}
// Subtract number of pictures in the partially coded GOP.
pictures_coded -= gop_offset + 1;
}
// Only take fully coded GOPs into account.
else if (encoder->cfg.gop_len > 0 && gop_offset != encoder->cfg.gop_len - 1) {
if (encoder->cfg.gop_len > 0 && gop_offset != encoder->cfg.gop_len - 1 && encoder->cfg.gop_lp_definition.d == 0) {
// Subtract number of bits in the partially coded GOP.
bits_coded -= state->frame->cur_gop_bits_coded;
// Subtract number of pictures in the partially coded GOP.