[x265-commits] [x265] rc: bug fixes in 2 pass ABR

Aarthi at videolan.org Aarthi at videolan.org
Tue Jul 22 19:44:09 CEST 2014


details:   http://hg.videolan.org/x265/rev/b85dbec30cc5
branches:  
changeset: 7511:b85dbec30cc5
user:      Aarthi Thirumalai
date:      Tue Jul 22 16:46:22 2014 +0530
description:
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

diffstat:

 source/encoder/ratecontrol.cpp |  40 +++++++++++++++++++++-------------------
 1 files changed, 21 insertions(+), 19 deletions(-)

diffs (95 lines):

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 @@ RateControl::RateControl(x265_param *p)
 {
     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 @@ bool RateControl::cuTreeReadFor2Pass(Fra
 
                 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 @@ double RateControl::rateEstimateQscale(F
             q = Clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
         }
         else
-            {
+        {
             /* 1pass ABR */
 
             /* Calculate the quantizer which would have produced the desired
@@ -1463,7 +1463,7 @@ double RateControl::rateEstimateQscale(F
             }
             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 @@ double RateControl::rateEstimateQscale(F
 
 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 @@ int RateControl::rateControlEnd(Frame* p
     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 @@ int RateControl::rateControlEnd(Frame* p
     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-commits mailing list