[x265] [PATCH] rc: fix bitrate accuracy for vbv in fast presets

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Wed Aug 27 08:01:57 CEST 2014


# HG changeset patch
# User Aarthi Thirumalai
# Date 1409119144 -19800
#      Wed Aug 27 11:29:04 2014 +0530
# Node ID 488548650e47dbc6834175901360312fd57b6bdb
# Parent  9eed52d658080bcdcc256d0724fa8ff57c16f1b8
rc: fix bitrate accuracy for vbv in fast presets.

diff -r 9eed52d65808 -r 488548650e47 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Wed Aug 27 11:23:54 2014 +0530
+++ b/source/encoder/ratecontrol.cpp	Wed Aug 27 11:29:04 2014 +0530
@@ -1735,6 +1735,25 @@
 
             q = X265_MAX(q0, q);
         }
+         // Check B-frame complexity, and use up any bits that would
+         // overflow before the next P-frame.
+         if (m_leadingBframes <= 5 && m_sliceType == P_SLICE && !m_singleFrameVbv)
+         {
+             int nb = m_leadingBframes;
+             double bits = predictSize(&m_pred[m_sliceType], q, (double)m_currentSatd);
+             double bbits = predictSize(&m_predBfromP, q * m_param->rc.pbFactor, (double)m_currentSatd);
+             double space;
+             if (bbits > m_bufferRate)
+                 nb = 0;
+             double pbbits = nb * bbits;
+
+             space = m_bufferFill + (1 + nb) * m_bufferRate - m_bufferSize;
+             if (pbbits < space)
+             {
+                 q *= X265_MAX(pbbits / space, bits / (0.5 * m_bufferSize));
+             }
+             q = X265_MAX(q0 / 2, q);
+         }
 
         if (!m_isCbr)
             q = X265_MAX(q0, q);


More information about the x265-devel mailing list