diff --git a/src/encoder_state-bitstream.c b/src/encoder_state-bitstream.c index b1451d4a..d58cc71c 100644 --- a/src/encoder_state-bitstream.c +++ b/src/encoder_state-bitstream.c @@ -738,7 +738,7 @@ static void encoder_state_write_bitstream_main(encoder_state_t * const state) { uint64_t newpos; int i; - curpos = bitstream_tell(stream) >> 3; + curpos = bitstream_tell(stream); // The first NAL unit of the access unit must use a long start code. bool first_nal_in_au = true; @@ -803,8 +803,12 @@ static void encoder_state_write_bitstream_main(encoder_state_t * const state) { assert(state->tile->frame->poc == state->global->poc); //Get bitstream length for stats - newpos = bitstream_tell(stream) >> 3; - state->stats_bitstream_length = newpos - curpos; + newpos = bitstream_tell(stream); + state->stats_bitstream_length = (newpos >> 3) - (curpos >> 3); + if (state->global->frame > 0) { + state->global->total_bits_coded = state->previous_encoder_state->global->total_bits_coded; + } + state->global->total_bits_coded += newpos - curpos; // Flush the output in case someone is reading the file on the other end. fflush(state->stream.file.output); diff --git a/src/encoder_state-ctors_dtors.c b/src/encoder_state-ctors_dtors.c index 96bc3446..bcb4d560 100644 --- a/src/encoder_state-ctors_dtors.c +++ b/src/encoder_state-ctors_dtors.c @@ -34,6 +34,7 @@ static int encoder_state_config_global_init(encoder_state_t * const state) { state->global->ref_list = REF_PIC_LIST_0; state->global->frame = 0; state->global->poc = 0; + state->global->total_bits_coded = 0; return 1; } diff --git a/src/encoderstate.h b/src/encoderstate.h index 86904e3f..bb1531a7 100644 --- a/src/encoderstate.h +++ b/src/encoderstate.h @@ -82,6 +82,9 @@ typedef struct { bool is_idr_frame; uint8_t pictype; uint8_t slicetype; + + //! Total number of bits written. + uint64_t total_bits_coded; } encoder_state_config_global_t;