From 28de670cd990e8d1da8ffafb34d1bc24c9c2299a Mon Sep 17 00:00:00 2001 From: Paul Wilkins <paulwilkins@google.com> Date: Mon, 7 Jun 2010 17:34:46 +0100 Subject: [PATCH] Fix RD bug. --- vp8/encoder/firstpass.c | 8 ++++++++ vp8/encoder/rdopt.c | 36 +++++++++++++++--------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/vp8/encoder/firstpass.c b/vp8/encoder/firstpass.c index 90f95e0831..26f09d5e35 100644 --- a/vp8/encoder/firstpass.c +++ b/vp8/encoder/firstpass.c @@ -1869,6 +1869,14 @@ void vp8_second_pass(VP8_COMP *cpi) } } + // Keep a globally available copy of this frames iiratio and the next. + cpi->this_iiratio = this_frame_intra_error / DOUBLE_DIVIDE_CHECK(this_frame_coded_error); + { + FIRSTPASS_STATS next_frame; + if ( lookup_next_frame_stats(cpi, &next_frame) != EOF ) + cpi->next_iiratio = next_frame.intra_error / DOUBLE_DIVIDE_CHECK(next_frame.coded_error); + } + // Set nominal per second bandwidth for this frame cpi->target_bandwidth = cpi->per_frame_bandwidth * cpi->output_frame_rate; if (cpi->target_bandwidth < 0) diff --git a/vp8/encoder/rdopt.c b/vp8/encoder/rdopt.c index ff03046000..a6bd8e86dc 100644 --- a/vp8/encoder/rdopt.c +++ b/vp8/encoder/rdopt.c @@ -171,15 +171,13 @@ static void fill_token_costs( } -static int rd_iifactor [ 32 ] = { 16, 16, 16, 12, 8, 4, 2, 0, +static int rd_iifactor [ 32 ] = { 4, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; - - // The values in this table should be reviewed static int sad_per_bit16lut[128] = { @@ -238,36 +236,32 @@ void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue) vp8_clear_system_state(); //__asm emms; - cpi->RDMULT = (int)((0.00007 * (capped_q * capped_q * capped_q * capped_q)) - (0.0125 * (capped_q * capped_q * capped_q)) + - (2.25 * (capped_q * capped_q)) - (12.5 * capped_q) + 25.0); + cpi->RDMULT = (int)( (0.0001 * (capped_q * capped_q * capped_q * capped_q)) + -(0.0125 * (capped_q * capped_q * capped_q)) + +(3.25 * (capped_q * capped_q)) + -(12.5 * capped_q) + 50.0); - if (cpi->RDMULT < 25) - cpi->RDMULT = 25; + if (cpi->RDMULT < 50) + cpi->RDMULT = 50; - if (cpi->pass == 2) + if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME)) { - if (cpi->common.frame_type == KEY_FRAME) - cpi->RDMULT += (cpi->RDMULT * rd_iifactor[0]) / 16; - else if (cpi->next_iiratio > 31) - cpi->RDMULT += (cpi->RDMULT * rd_iifactor[31]) / 16; + if (cpi->next_iiratio > 31) + cpi->RDMULT += (cpi->RDMULT * rd_iifactor[31]) >> 4; else - cpi->RDMULT += (cpi->RDMULT * rd_iifactor[cpi->next_iiratio]) / 16; + cpi->RDMULT += (cpi->RDMULT * rd_iifactor[cpi->next_iiratio]) >> 4; } // Extend rate multiplier along side quantizer zbin increases if (cpi->zbin_over_quant > 0) { - // Extend rate multiplier along side quantizer zbin increases - if (cpi->zbin_over_quant > 0) - { - double oq_factor = pow(1.006, cpi->zbin_over_quant); + double oq_factor = pow(1.006, cpi->zbin_over_quant); - if (oq_factor > (1.0 + ((double)cpi->zbin_over_quant / 64.0))) - oq_factor = (1.0 + (double)cpi->zbin_over_quant / 64.0); + if (oq_factor > (1.0 + ((double)cpi->zbin_over_quant / 64.0))) + oq_factor = (1.0 + (double)cpi->zbin_over_quant / 64.0); - cpi->RDMULT = (int)(oq_factor * cpi->RDMULT); - } + cpi->RDMULT = (int)(oq_factor * cpi->RDMULT); } cpi->mb.errorperbit = (cpi->RDMULT / 100); -- GitLab