[x265] [PATCH] rc: bug fixes in 2 pass ABR
aarthi at multicorewareinc.com
aarthi at multicorewareinc.com
Tue Jul 22 17:54:30 CEST 2014
# HG changeset patch
# User Aarthi Thirumalai
# Date 1406027782 -19800
# Tue Jul 22 16:46:22 2014 +0530
# Node ID b85dbec30cc58d1e2aec0c7fd5c25dfd1ff524ab
# Parent d303b4d860e9f06396a156726dd518d0f41fe796
rc: bug fixes in 2 pass ABR
ratecontrol - fix duplication of bits in calculating m_totalBits
frameencoder - don't amortize totalBits in 2 pass ABR
diff -r d303b4d860e9 -r b85dbec30cc5 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Mon Jul 21 22:43:38 2014 -0500
+++ b/source/encoder/ratecontrol.cpp Tue Jul 22 16:46:22 2014 +0530
@@ -303,7 +303,7 @@
{
m_param = p;
int lowresCuWidth = ((m_param->sourceWidth / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
- int lowresCuHeight = ((m_param->sourceHeight / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
+ int lowresCuHeight = ((m_param->sourceHeight / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
m_ncu = lowresCuWidth * lowresCuHeight;
if (m_param->rc.cuTree)
@@ -1288,7 +1288,7 @@
if (!fread(&type, 1, 1, m_cutreeStatFileIn))
goto fail;
- if (fread(m_cuTreeStats.qpBuffer[m_cuTreeStats.qpBufPos], sizeof(uint16_t), m_ncu, m_cutreeStatFileIn) != sizeof(m_ncu))
+ if (fread(m_cuTreeStats.qpBuffer[m_cuTreeStats.qpBufPos], sizeof(uint16_t), m_ncu, m_cutreeStatFileIn) != (size_t)m_ncu)
goto fail;
if (type != sliceTypeActual && m_cuTreeStats.qpBufPos == 1)
@@ -1432,7 +1432,7 @@
q = Clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
}
else
- {
+ {
/* 1pass ABR */
/* Calculate the quantizer which would have produced the desired
@@ -1463,7 +1463,7 @@
}
else
{
- if (!m_param->rc.bStatRead)
+ if (!m_param->rc.bStatWrite && !m_param->rc.bStatRead)
checkAndResetABR(rce, false);
q = getQScale(rce, m_wantedBitsWindow / m_cplxrSum);
@@ -1541,22 +1541,24 @@
void RateControl::rateControlUpdateStats(RateControlEntry* rce)
{
- if (rce->sliceType == I_SLICE)
+ if (!m_param->rc.bStatWrite && !m_param->rc.bStatRead)
{
- /* previous I still had a residual; roll it into the new loan */
- if (m_partialResidualFrames)
- rce->rowTotalBits += m_partialResidualCost * m_partialResidualFrames;
+ if (rce->sliceType == I_SLICE)
+ {
+ /* previous I still had a residual; roll it into the new loan */
+ if (m_partialResidualFrames)
+ rce->rowTotalBits += m_partialResidualCost * m_partialResidualFrames;
- m_partialResidualFrames = X265_MIN(s_amortizeFrames, m_param->keyframeMax);
- m_partialResidualCost = (int)((rce->rowTotalBits * s_amortizeFraction) /m_partialResidualFrames);
- rce->rowTotalBits -= m_partialResidualCost * m_partialResidualFrames;
+ m_partialResidualFrames = X265_MIN(s_amortizeFrames, m_param->keyframeMax);
+ m_partialResidualCost = (int)((rce->rowTotalBits * s_amortizeFraction) /m_partialResidualFrames);
+ rce->rowTotalBits -= m_partialResidualCost * m_partialResidualFrames;
+ }
+ else if (m_partialResidualFrames)
+ {
+ rce->rowTotalBits += m_partialResidualCost;
+ m_partialResidualFrames--;
+ }
}
- else if (m_partialResidualFrames)
- {
- rce->rowTotalBits += m_partialResidualCost;
- m_partialResidualFrames--;
- }
-
if (rce->sliceType != B_SLICE)
rce->rowCplxrSum = rce->rowTotalBits * x265_qp2qScale(rce->qpaRc) / rce->qRceq;
else
@@ -2044,7 +2046,7 @@
int64_t actualBits = bits;
if (m_isAbr)
{
- if (m_param->rc.rateControlMode == X265_RC_ABR && !m_param->rc.bStatRead)
+ if (m_param->rc.rateControlMode == X265_RC_ABR && !m_param->rc.bStatRead && !m_param->rc.bStatWrite)
{
checkAndResetABR(rce, true);
}
@@ -2158,7 +2160,7 @@
if (m_2pass)
{
m_expectedBitsSum += qScale2bits(rce, x265_qp2qScale(rce->newQp));
- m_totalBits += bits;
+ m_totalBits += bits - rce->rowTotalBits;
}
if (m_isVbv)
More information about the x265-devel
mailing list