[x264-devel] [PATCH] reference cost

Loren Merritt lorenm at u.washington.edu
Wed Sep 15 05:16:07 CEST 2004


The current code for calculating the cost of encoding which reference 
frame a MB is predicted from, introduces a bias towards ref0 and 
against P16x16.
Removing this bias produces an improvement of .4% - 2% bitrate,
depending on content and number of reference frames.

--Loren Merritt
-------------- next part --------------
Index: encoder/analyse.c
===================================================================
--- encoder/analyse.c	(revision 46)
+++ encoder/analyse.c	(working copy)
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
+#include <limits.h>
 
 #include "../core/common.h"
 #include "../core/macroblock.h"
@@ -464,15 +465,8 @@
 //    m.mvc[0]  = 0;
 //    m.mvc[1]  = 0;
 
-    /* ME for ref 0 */
-    m.p_fref = h->mb.pic.p_fref[0][0][0];
-    x264_mb_predict_mv_16x16( h, 0, 0, m.mvp );
-    x264_me_search( h, &m );
-
-    a->l0.i_ref = 0;
-    a->l0.me16x16 = m;
-
-    for( i_ref = 1; i_ref < h->i_ref0; i_ref++ )
+    a->l0.me16x16.cost = INT_MAX;
+    for( i_ref = 0; i_ref < h->i_ref0; i_ref++ )
     {
         /* search with ref */
         m.p_fref = h->mb.pic.p_fref[0][i_ref][0];
@@ -489,6 +483,9 @@
         }
     }
 
+    /* subtract ref cost, so we don't have to add it for the other P types */
+    a->l0.me16x16.cost -= m.lm * bs_size_te( h->sh.i_num_ref_idx_l0_active - 1, a->l0.i_ref );
+
     /* Set global ref, needed for all others modes */
     x264_macroblock_cache_ref( h, 0, 0, 4, 4, 0, a->l0.i_ref );
 }
@@ -765,15 +762,9 @@
     m.b_mvc   = 0;
     m.i_mv_range = a->i_mv_range;
 
-    /* ME for List 0 ref 0 */
-    m.p_fref = h->mb.pic.p_fref[0][0][0];
-    x264_mb_predict_mv_16x16( h, 0, 0, m.mvp );
-    x264_me_search( h, &m );
-
-    a->l0.i_ref = 0;
-    a->l0.me16x16 = m;
-
-    for( i_ref = 1; i_ref < h->i_ref0; i_ref++ )
+    /* ME for List 0 */
+    a->l0.me16x16.cost = INT_MAX;
+    for( i_ref = 0; i_ref < h->i_ref0; i_ref++ )
     {
         /* search with ref */
         m.p_fref = h->mb.pic.p_fref[0][i_ref][0];
@@ -790,15 +781,9 @@
         }
     }
 
-    /* ME for list 1 ref 0 */
-    m.p_fref = h->mb.pic.p_fref[1][0][0];
-    x264_mb_predict_mv_16x16( h, 1, 0, m.mvp );
-    x264_me_search( h, &m );
-
-    a->l1.i_ref = 0;
-    a->l1.me16x16 = m;
-
-    for( i_ref = 1; i_ref < h->i_ref1; i_ref++ )
+    /* ME for list 1 */
+    a->l1.me16x16.cost = INT_MAX;
+    for( i_ref = 0; i_ref < h->i_ref1; i_ref++ )
     {
         /* search with ref */
         m.p_fref = h->mb.pic.p_fref[1][i_ref][0];


More information about the x264-devel mailing list