From 037d123cf62c4af2dc13742b8606882b6d0d3d9e Mon Sep 17 00:00:00 2001 From: Anton Mitrofanov Date: Thu, 9 Feb 2012 15:27:53 -0800 Subject: [PATCH] Add an small per-MB cost penalty for lowres 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/encoder/slicetype.c b/encoder/slicetype.c index ddeb9924..e77ba1d0 100644 --- a/encoder/slicetype.c +++ b/encoder/slicetype.c @@ -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? */ -- 2.47.3