[x265] [PATCH 2 of 2] rc: restrict low tolerance for bitrate fluctuations to strict-cbr option

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Tue Dec 30 10:21:48 CET 2014


# HG changeset patch
# User Aarthi Thirumalai
# Date 1419064540 -19800
#      Sat Dec 20 14:05:40 2014 +0530
# Node ID fa8ab4bd8851613983e152e682c031fd4b0e83e8
# Parent  98dfd6e0c72122e8613208d5927a4c81da6a8e7a
rc: restrict low tolerance for bitrate fluctuations to strict-cbr option

diff -r 98dfd6e0c721 -r fa8ab4bd8851 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Tue Dec 23 16:32:30 2014 +0530
+++ b/source/encoder/ratecontrol.cpp	Sat Dec 20 14:05:40 2014 +0530
@@ -1759,7 +1759,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;
@@ -1773,17 +1773,17 @@
                     bufferFillCur -= curBits;
                 }
 
-                /* Try to get the buffer no more than 80% filled, 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));
+                /* Try to get the buffer at least 50% filled, 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.5 * totalDuration * tol));
                 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% filled, but don't set an impossible goal. */
+                targetFill = Clip3(m_bufferSize * (1 - totalDuration * tol * 0.2), m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);
                 if (m_isCbr && bufferFillCur > targetFill)
                 {
                     q /= 1.01;
@@ -1976,7 +1976,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_param->rc.bStrictCbr ? 0.2 : 1;
+        double rcTol = (bufferLeftPlanned * tol) / m_param->frameNumThreads * m_param->rc.rateTolerance;
         int32_t encodedBitsSoFar = 0;
         double accFrameBits = predictRowsSizeSum(curFrame, rce, qpVbv, encodedBitsSoFar);
 
@@ -1994,7 +1995,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