[x265] [PATCH] rc: restrict low tolerance for bitrate deviance to CBR option

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Mon Dec 22 15:21:53 CET 2014


# HG changeset patch
# User Aarthi Thirumalai
# Date 1419064540 -19800
#      Sat Dec 20 14:05:40 2014 +0530
# Node ID 2c2a55374a530408c9fb41af017e21a33113558f
# Parent  775ebb4694ad7931a98b796640bf646085659ea2
rc: restrict low tolerance for bitrate deviance to CBR option

to improve quality in CRF with capped VBV

diff -r 775ebb4694ad -r 2c2a55374a53 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Tue Dec 16 09:40:00 2014 +0530
+++ b/source/encoder/ratecontrol.cpp	Sat Dec 20 14:05:40 2014 +0530
@@ -1754,7 +1754,7 @@
                 for (int j = 0; bufferFillCur >= 0; j++)
                 {
                     int type = curFrame->m_lowres.plannedType[j];
-                    if (type == X265_TYPE_AUTO)
+                    if (type == X265_TYPE_AUTO || totalDuration >= 1.0)
                         break;
                     totalDuration += m_frameDuration;
                     double wantedFrameSize = m_vbvMaxRate * m_frameDuration;
@@ -1768,17 +1768,17 @@
                     bufferFillCur -= curBits;
                 }
 
-                /* Try to get the buffer no more than 80% filled, but don't set an impossible goal. */
+                /* Try to get the buffer at least 50% available, but don't set an impossible goal. */
                 double tol = isIFramePresent ? 1 / totalDuration : totalDuration < 0.5 ? 2 : 1;
-                targetFill = X265_MIN(m_bufferFill + totalDuration * m_vbvMaxRate * 0.5 , m_bufferSize * (1 - 0.8 * totalDuration * tol));
+                targetFill = X265_MIN(m_bufferFill + totalDuration * m_vbvMaxRate * 0.5 , m_bufferSize * totalDuration * tol * 0.5);
                 if (bufferFillCur < targetFill)
                 {
                     q *= 1.01;
                     loopTerminate |= 1;
                     continue;
                 }
-                /* Try to get the buffer atleast 50% filled, but don't set an impossible goal. */
-                targetFill = Clip3(m_bufferSize - (m_bufferSize * totalDuration * 0.5), m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);
+                /* Try to get the buffer not more than 80% available, but don't set an impossible goal. */
+                targetFill = Clip3(m_bufferSize - (m_bufferSize * totalDuration * tol * 0.2), m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);
                 if (m_isCbr && bufferFillCur > targetFill)
                 {
                     q /= 1.01;
@@ -1971,7 +1971,8 @@
     if (row < sps.numCuInHeight - 1)
     {
         /* More threads means we have to be more cautious in letting ratecontrol use up extra bits. */
-        double rcTol = (bufferLeftPlanned * 0.2) / m_param->frameNumThreads * m_param->rc.rateTolerance;
+        double tol = m_isCbr ? 0.5 : 1;
+        double rcTol = (bufferLeftPlanned * tol) / m_param->frameNumThreads * m_param->rc.rateTolerance;
         int32_t encodedBitsSoFar = 0;
         double accFrameBits = predictRowsSizeSum(curFrame, rce, qpVbv, encodedBitsSoFar);
 
@@ -1989,7 +1990,7 @@
 
         while (qpVbv < qpMax
                && ((accFrameBits > rce->frameSizePlanned + rcTol) ||
-                   (rce->bufferFill - accFrameBits < bufferLeftPlanned * 0.2) ||
+                   (rce->bufferFill - accFrameBits < bufferLeftPlanned * 0.5) ||
                    (accFrameBits > rce->frameSizePlanned && qpVbv < rce->qpNoVbv)))
         {
             qpVbv += stepSize;


More information about the x265-devel mailing list