[x265] [PATCH] modified Bframe logic in rateEstimateQscale and rateControlEnd to improve ABR
aarthi at multicorewareinc.com
aarthi at multicorewareinc.com
Wed Sep 11 18:21:44 CEST 2013
# HG changeset patch
# User Aarthi Thirumalai
# Date 1378916383 -19800
# Wed Sep 11 21:49:43 2013 +0530
# Node ID e159a2ac38906fd569e4b6dd88271e6ea4d5a87f
# Parent af8cddab103e87cb7817e4809780a64573d4dad2
modified Bframe logic in rateEstimateQscale and rateControlEnd to improve ABR.
diff -r af8cddab103e -r e159a2ac3890 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Wed Sep 11 00:03:09 2013 -0500
+++ b/source/encoder/ratecontrol.cpp Wed Sep 11 21:49:43 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