From c9e8e4de68825662580d99d0cae6989455698c2c Mon Sep 17 00:00:00 2001 From: Anton Mitrofanov Date: Sun, 21 Feb 2010 13:21:11 -0800 Subject: [PATCH] New algorithm for AQ mode 2 Combines the auto-ness of AQ2 with a new var^0.25 instead of log(var) formula. Works better with MB-tree than the old AQ mode 2 and should give higher SSIM. --- encoder/ratecontrol.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 78b55286..31038799 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -246,17 +246,20 @@ void x264_adaptive_quant_frame( x264_t *h, x264_frame_t *frame ) if( h->param.rc.i_aq_mode == X264_AQ_AUTOVARIANCE ) { + float avg_adj_pow2 = 0.f; for( mb_y = 0; mb_y < h->sps->i_mb_height; mb_y++ ) for( mb_x = 0; mb_x < h->sps->i_mb_width; mb_x++ ) { uint32_t energy = ac_energy_mb( h, mb_x, mb_y, frame ); - float qp_adj = x264_log2( energy + 2 ); - qp_adj *= qp_adj; + float qp_adj = powf( energy + 1, 0.125f ); frame->f_qp_offset[mb_x + mb_y*h->mb.i_mb_stride] = qp_adj; avg_adj += qp_adj; + avg_adj_pow2 += qp_adj * qp_adj; } avg_adj /= h->mb.i_mb_count; - strength = h->param.rc.f_aq_strength * avg_adj * (1.f / 6000.f); + avg_adj_pow2 /= h->mb.i_mb_count; + strength = h->param.rc.f_aq_strength * avg_adj; + avg_adj = avg_adj - 0.5f * (avg_adj_pow2 - 14.f) / avg_adj; } else strength = h->param.rc.f_aq_strength * 1.0397f; -- 2.40.0