diff --git a/src/encmain.c b/src/encmain.c index 94281a84..5f95abf9 100644 --- a/src/encmain.c +++ b/src/encmain.c @@ -355,6 +355,13 @@ int main(int argc, char *argv[]) //Clear encoder encoder_next_frame(&encoder_states[current_encoder_state]); + //Abort if enough frames + if (cfg->frames && encoder_states[current_encoder_state].global->frame >= cfg->frames) { + //Ignore this frame, which is not valid... + encoder_states[current_encoder_state].stats_done = 1; + break; + } + CHECKPOINT_MARK("read source frame: %d", encoder_states[current_encoder_state].global->frame + cfg->seek); // Read one frame from the input diff --git a/src/encoder_state-bitstream.c b/src/encoder_state-bitstream.c index ba3a66c3..4308da97 100644 --- a/src/encoder_state-bitstream.c +++ b/src/encoder_state-bitstream.c @@ -675,8 +675,18 @@ static void add_checksum(encoder_state * const encoder_state) static void encoder_state_write_bitstream_main(encoder_state * const main_state) { const encoder_control * const encoder = main_state->encoder_control; bitstream * const stream = &main_state->stream; - + uint64_t curpos; int i; + + if (main_state->stream.base.type == BITSTREAM_TYPE_FILE) { + fgetpos(main_state->stream.file.output,(fpos_t*)&curpos); + } else if (main_state->stream.base.type == BITSTREAM_TYPE_MEMORY) { + curpos = stream->mem.output_length; + } else { + //Should not happen + assert(0); + curpos = 0; + } if (main_state->global->is_radl_frame) { // Access Unit Delimiter (AUD) @@ -737,6 +747,19 @@ static void encoder_state_write_bitstream_main(encoder_state * const main_state) } assert(main_state->tile->frame->poc == main_state->global->poc); + + //Get bitstream length for stats + if (main_state->stream.base.type == BITSTREAM_TYPE_FILE) { + uint64_t newpos; + fgetpos(main_state->stream.file.output,(fpos_t*)&newpos); + main_state->stats_bitstream_length = newpos - curpos; + } else if (main_state->stream.base.type == BITSTREAM_TYPE_MEMORY) { + main_state->stats_bitstream_length = stream->mem.output_length - curpos; + } else { + //Should not happen + assert(0); + main_state->stats_bitstream_length = 0; + } } void encoder_state_write_bitstream_leaf(encoder_state * const encoder_state) { diff --git a/src/encoderstate.c b/src/encoderstate.c index 78685e57..c2a7e482 100644 --- a/src/encoderstate.c +++ b/src/encoderstate.c @@ -830,13 +830,12 @@ void encoder_compute_stats(encoder_state *encoder_state, FILE * const recout, ui // PSNR calculations { - int32_t diff=0; //FIXME: get the correct length of bitstream double temp_psnr[3]; videoframe_compute_psnr(encoder_state->tile->frame, temp_psnr); fprintf(stderr, "POC %4d (%c-frame) %10d bits PSNR: %2.4f %2.4f %2.4f\n", encoder_state->global->frame, - "BPI"[encoder_state->global->slicetype%3], diff<<3, + "BPI"[encoder_state->global->slicetype%3], encoder_state->stats_bitstream_length<<3, temp_psnr[0], temp_psnr[1], temp_psnr[2]); // Increment total PSNR diff --git a/src/encoderstate.h b/src/encoderstate.h index 2391a6d2..cfe30035 100644 --- a/src/encoderstate.h +++ b/src/encoderstate.h @@ -163,6 +163,7 @@ typedef struct encoder_state { cabac_data cabac; int stats_done; + uint32_t stats_bitstream_length; //Bitstream length written in bytes //Jobs to wait for threadqueue_job * tqj_recon_done; //Reconstruction is done