[x265] [PATCH RFC] rc: define function for updating rate control statistics in processRowEncoder
santhoshini at multicorewareinc.com
santhoshini at multicorewareinc.com
Tue Jul 15 11:34:44 CEST 2014
# HG changeset patch
# User Santhoshini Sekar <santhoshini at multicorewareinc.com>
# Date 1405416189 -19800
# Tue Jul 15 14:53:09 2014 +0530
# Node ID 8f7ef1fd08bd4e045921e8831b3c57b1ea866c4d
# Parent e171ad8bc8a3611b75e084587f4c07c41427c73d
rc: define function for updating rate control statistics in processRowEncoder
Rate control updates its statistics like bits in RateControlEnd. With
frame parallelsim enabled and N parallel frames running, the feedback given to
rate control is delayed until rateControlStart of N frames are called. To avoid
this delay, update rate control statistics for every frame after encode of few
frames are done in processRowEncoder.By updating statistics for every frame we
make ABR to function more accurately(predicts more accurate QP) making use of
latest data rather than stale values.
diff -r e171ad8bc8a3 -r 8f7ef1fd08bd source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Fri Jul 11 01:44:43 2014 -0500
+++ b/source/encoder/ratecontrol.cpp Tue Jul 15 14:53:09 2014 +0530
@@ -781,6 +781,32 @@
}
}
+void RateControl::rateControlUpdateStats(RateControlEntry* rce)
+{
+ if (rce->sliceType == I_SLICE)
+ {
+ /* previous I still had a residual; roll it into the new loan */
+ if (m_residualFrames)
+ rce->rowTotalBits += m_residualCost * m_residualFrames;
+
+ m_residualFrames = X265_MIN(s_amortizeFrames, m_param->keyframeMax);
+ m_residualCost = (int)((rce->rowTotalBits * s_amortizeFraction) / m_residualFrames);
+ rce->rowTotalBits -= m_residualCost * m_residualFrames;
+ }
+ else if (m_residualFrames)
+ {
+ rce->rowTotalBits += m_residualCost;
+ }
+
+ if (rce->sliceType != B_SLICE)
+ rce->rowCplxrSum = rce->rowTotalBits * x265_qp2qScale(rce->qpaRc) / rce->qRceq;
+ else
+ rce->rowCplxrSum = rce->rowTotalBits * x265_qp2qScale(rce->qpaRc) / (rce->qRceq * fabs(m_param->rc.pbFactor));
+
+ m_cplxrSum += rce->rowCplxrSum;
+ m_totalBits += rce->rowTotalBits;
+}
+
void RateControl::checkAndResetABR(RateControlEntry* rce, bool isFrameDone)
{
double abrBuffer = 2 * m_param->rc.rateTolerance * m_bitrate;
diff -r e171ad8bc8a3 -r 8f7ef1fd08bd source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h Fri Jul 11 01:44:43 2014 -0500
+++ b/source/encoder/ratecontrol.h Tue Jul 15 14:53:09 2014 +0530
@@ -68,6 +68,8 @@
double frameSizePlanned; /* frame Size decided by RateCotrol before encoding the frame */
double bufferRate;
double movingAvgSum;
+ double rowCplxrSum;
+ int64_t rowTotalBits; /* update cplxrsum and totalbits at the end of 2 rows */
double qpNoVbv;
double bufferFill;
Predictor rowPreds[3][2];
@@ -158,6 +160,7 @@
// to be called for each frame to process RateControl and set QP
void rateControlStart(Frame* pic, Lookahead *, RateControlEntry* rce, Encoder* enc);
void calcAdaptiveQuantFrame(Frame *pic);
+ void rateControlUpdateStats(RateControlEntry* rce);
int rateControlEnd(Frame* pic, int64_t bits, RateControlEntry* rce, FrameStats* stats);
int rowDiagonalVbvRateControl(Frame* pic, uint32_t row, RateControlEntry* rce, double& qpVbv);
void hrdFullness(SEIBufferingPeriod* sei);
More information about the x265-devel
mailing list