From 3471e2470d49419acdd68d63b2a9ab3508dab469 Mon Sep 17 00:00:00 2001 From: Joose Sainio Date: Wed, 7 Nov 2018 08:17:39 +0200 Subject: [PATCH] Fix using uninitialized value for the first frame --- src/rate_control.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rate_control.c b/src/rate_control.c index 7235b2e3..0e18bdff 100644 --- a/src/rate_control.c +++ b/src/rate_control.c @@ -84,8 +84,15 @@ static double gop_allocate_bits(encoder_state_t * const state) { // With LP-GOP the bits coded is not always updated correctly so this is // a band-aid fix for getting a better bit allocation - uint64_t previous_bits = state->previous_encoder_state->frame->cur_pic_target_bits; - bits_coded = previous_bits > bits_coded ? 0 : bits_coded - previous_bits; + + 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; }