[x265] [PATCH 2 of 2] rc : avoid issues caused by zero-residual lookahead blocks , introduce a small bias to compute cu cost
Aarthi Thirumalai
aarthi at multicorewareinc.com
Fri Jan 17 14:18:52 CET 2014
# HG changeset patch
# User Aarthi Thirumalai
# Date 1389964662 -19800
# Fri Jan 17 18:47:42 2014 +0530
# Node ID e16f947ad39e590148f9312812d20f7c50faddd9
# Parent f2b8eda2fb94f50e6dc79e3151a8dadb40207b6a
rc : avoid issues caused by zero-residual lookahead blocks ,introduce a small bias to compute cu cost.
diff -r f2b8eda2fb94 -r e16f947ad39e source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp Fri Jan 17 18:45:35 2014 +0530
+++ b/source/encoder/slicetype.cpp Fri Jan 17 18:47:42 2014 +0530
@@ -461,6 +461,8 @@
cuy > 0 && cuy < heightInCU - 1) || widthInCU <= 2 || heightInCU <= 2;
me.setSourcePU(pelOffset, cuSize, cuSize);
+ /* A small, arbitrary bias to avoid VBV problems caused by zero-residual lookahead blocks. */
+ int lowresPenalty = 4;
MV(*fenc_mvs[2]) = { &fenc->lowresMvs[0][b - p0 - 1][cuXY],
&fenc->lowresMvs[1][p1 - b - 1][cuXY] };
@@ -585,6 +587,7 @@
primitives.transpose[nLog2SizeMinus2](buf_trans, me.fenc, FENC_STRIDE);
pixelcmp_t satd = primitives.satd[partitionFromSizes(cuSize, cuSize)];
int icost = me.COST_MAX, cost;
+ const int intraPenalty = 5 * lookAheadLambda;
for (uint32_t mode = 0; mode < 35; mode++)
{
if ((mode >= 2) && (mode < 18))
@@ -595,7 +598,7 @@
icost = cost;
}
- // TOOD: i_icost += intra_penalty + lowres_penalty;
+ icost += intraPenalty + lowresPenalty;
fenc->intraCost[cuXY] = icost;
fenc->rowSatds[0][0][cuy] += icost;
if (bFrameScoreCU)
@@ -605,6 +608,7 @@
costIntraAq += (icost * fenc->invQscaleFactor[cuXY] + 128) >> 8;
}
}
+ bcost += lowresPenalty;
if (!bBidir)
{
if (fenc->intraCost[cuXY] < bcost)
@@ -758,11 +762,15 @@
// We need the intra costs for row SATDs
estimateFrameCost(b, b, b, 0);
- /* calculate the frame costs ahead of time for x264_rc_analyse_slice while we still have lowres */
- if (cfg->param.rc.rateControlMode != X265_RC_CQP)
- {
- int p0, p1, b;
- p1 = b = bframes + 1;
+ // We need B-frame costs for row SATDs
+ p0 = 0;
+ for (b = 1; b <= bframes; b++)
+ {
+ if (frames[b]->sliceType == X265_TYPE_B)
+ for (p1 = b; frames[p1]->sliceType == X265_TYPE_B; )
+ {
+ p1++;
+ }
else
p1 = bframes + 1;
diff -r f2b8eda2fb94 -r e16f947ad39e source/encoder/slicetype.h
--- a/source/encoder/slicetype.h Fri Jan 17 18:45:35 2014 +0530
+++ b/source/encoder/slicetype.h Fri Jan 17 18:47:42 2014 +0530
@@ -59,7 +59,7 @@
int widthInCU;
int heightInCU;
int merange;
-
+ int lookAheadLambda;
LookaheadRow()
{
me.setQP(X265_LOOKAHEAD_QP);
@@ -67,6 +67,7 @@
me.setSubpelRefine(1);
predictions = (pixel*)X265_MALLOC(pixel, 35 * 8 * 8);
merange = 16;
+ lookAheadLambda = (int)x265_lambda2_non_I[X265_LOOKAHEAD_QP];
}
~LookaheadRow()
More information about the x265-devel
mailing list