]> git.videolan.org Git - x264.git/commitdiff
New algorithm for AQ mode 2
authorAnton Mitrofanov <BugMaster@narod.ru>
Sun, 21 Feb 2010 21:21:11 +0000 (13:21 -0800)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Tue, 23 Feb 2010 09:46:22 +0000 (01:46 -0800)
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

index d0fdb50016eb1183ebd4e3932b5094c572e690d8..8b47e29c7083f81033fca6bfeb454cf7dea835b0 100644 (file)
@@ -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;