[x265] [PATCH] modify for BFrames in ABR , clean up code
aarthi at multicorewareinc.com
aarthi at multicorewareinc.com
Wed Sep 11 18:31:09 CEST 2013
# HG changeset patch
# User Aarthi Thirumalai
# Date 1378916973 -19800
# Wed Sep 11 21:59:33 2013 +0530
# Node ID 823b35128a7dcbd77f0d4c274a285d63deba7c5a
# Parent a6bf1f10e820da79da76b4649eaae11b6a030521
modify for BFrames in ABR , clean up code
diff -r a6bf1f10e820 -r 823b35128a7d source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Wed Sep 11 16:00:49 2013 +0530
+++ b/source/encoder/ratecontrol.cpp Wed Sep 11 21:59:33 2013 +0530
@@ -160,16 +160,19 @@
{
/* B-frames don't have independent rate control, but rather get the
* average QP of the two adjacent P-frames + an offset */
+ TComSlice* prevRefSlice = curFrame->getRefPic(REF_PIC_LIST_0, 0)->getSlice();
+ TComSlice* nextRefSlice = curFrame->getRefPic(REF_PIC_LIST_1, 0)->getSlice();
+ int i0 = prevRefSlice->getSliceType() == I_SLICE;
+ int i1 = nextRefSlice->getSliceType() == I_SLICE;
+ int dt0 = abs(curFrame->getPOC() - prevRefSlice->getPOC());
+ int dt1 = abs(curFrame->getPOC() - nextRefSlice->getPOC());
+ double q0 = prevRefSlice->getSliceQp();
+ double q1 = nextRefSlice->getSliceQp();
- int i0 = curFrame->getRefPic(REF_PIC_LIST_0, 0)->getSlice()->getSliceType() == I_SLICE;
- int i1 = curFrame->getRefPic(REF_PIC_LIST_1, 0)->getSlice()->getSliceType() == I_SLICE;
- int dt0 = abs(curFrame->getPOC() - curFrame->getRefPic(REF_PIC_LIST_0, 0)->getPOC());
- int dt1 = abs(curFrame->getPOC() - curFrame->getRefPic(REF_PIC_LIST_1, 0)->getPOC());
-
- //TODO:need to figure out this
- double q0 = curFrame->getRefPic(REF_PIC_LIST_0, 0)->getSlice()->getSliceQp();
- double q1 = curFrame->getRefPic(REF_PIC_LIST_1, 0)->getSlice()->getSliceQp();
-
+ if (prevRefSlice->getSliceType() == B_SLICE && prevRefSlice->isReferenced())
+ q0 -= pbOffset / 2;
+ if (nextRefSlice->getSliceType() == B_SLICE && nextRefSlice->isReferenced())
+ q1 -= pbOffset / 2;
if (i0 && i1)
q = (q0 + q1) / 2 + ipOffset;
else if (i0)
@@ -183,12 +186,8 @@
q += pbOffset / 2;
else
q += pbOffset;
-
- double qScale = qp2qScale(q);
- lastQScaleFor[P_SLICE] = lastQScale = qScale/pbFactor;
-
- return qScale;
+ return qp2qScale(q);
}
else
{
@@ -300,12 +299,14 @@
if (rateControlMode == X265_RC_ABR)
{
if (frameType != B_SLICE)
- cplxrSum += 1.1 *bits * qp2qScale(rce->qpaRc) / rce->lastRceq;
+ /* The factor 1.5 is to tune up the actual bits otherwise the cplxrSum is scaled too low
+ * to improve short term compensation for next frame. */
+ cplxrSum += 1.5 * bits * qp2qScale(rce->qpaRc) / rce->lastRceq;
else
{
/* Depends on the fact that B-frame's QP is an offset from the following P-frame's.
* Not perfectly accurate with B-refs, but good enough. */
- cplxrSum += bits * qp2qScale(rce->qpaRc) / (rce->lastRceq * fabs(0.5 * pbFactor));
+ cplxrSum += bits * qp2qScale(rce->qpaRc) / (rce->lastRceq * fabs(pbFactor));
}
cplxrSum *= cbrDecay;
wantedBitsWindow += frameDuration * bitrate;
More information about the x265-devel
mailing list