]> git.sesse.net Git - x264/commitdiff
Add an small per-MB cost penalty for lowres
authorAnton Mitrofanov <Bugmaster@narod.ru>
Thu, 9 Feb 2012 23:27:53 +0000 (15:27 -0800)
committerFiona Glaser <fiona@x264.com>
Wed, 7 Mar 2012 01:10:30 +0000 (17:10 -0800)
Helps avoid VBV predictors going nuts with very low-cost MBs.
One particular case this fixes is zero-cost MBs: adaptive quantization decreases the QP a lot, but (before this patch), no cost penalty gets factored in for this, because anything times zero is zero.

encoder/slicetype.c

index 65ea761cb2f652fe916c0c7d9e08cca3ef916195..af08184e8eb39b1b03d4482256388ae0d14094f8 100644 (file)
@@ -457,6 +457,8 @@ static void x264_slicetype_mb_cost( x264_t *h, x264_mb_analysis_t *a,
     x264_me_t m[2];
     int i_bcost = COST_MAX;
     int list_used = 0;
+    /* A small, arbitrary bias to avoid VBV problems caused by zero-residual lookahead blocks. */
+    int lowres_penalty = 4;
 
     h->mb.pic.p_fenc[0] = h->mb.pic.fenc_buf;
     h->mc.copy[PIXEL_8x8]( h->mb.pic.p_fenc[0], FENC_STRIDE, &fenc->lowres[0][i_pel_offset], i_stride, 8 );
@@ -653,7 +655,7 @@ lowres_intra_mb:
             }
         }
 
-        i_icost += intra_penalty;
+        i_icost += intra_penalty + lowres_penalty;
         fenc->i_intra_cost[i_mb_xy] = i_icost;
         int i_icost_aq = i_icost;
         if( h->param.rc.i_aq_mode )
@@ -665,6 +667,7 @@ lowres_intra_mb:
             fenc->i_cost_est_aq[0][0] += i_icost_aq;
         }
     }
+    i_bcost += lowres_penalty;
 
     /* forbid intra-mbs in B-frames, because it's rare and not worth checking */
     /* FIXME: Should we still forbid them now that we cache intra scores? */