[x265] [PATCH 2 of 3] rc: restrict low tolerance for bitrate fluctuations to strict-cbr option
aarthi at multicorewareinc.com
aarthi at multicorewareinc.com
Mon Jan 12 06:48:29 CET 2015
# HG changeset patch
# User Aarthi Thirumalai
# Date 1419064540 -19800
# Sat Dec 20 14:05:40 2014 +0530
# Node ID b5925bd396dbb08c536d9d77cd5fccdf8195e385
# Parent 4f8a105102a7984226e62ce7ac8f149a7a9c747f
rc: restrict low tolerance for bitrate fluctuations to strict-cbr option
diff -r 4f8a105102a7 -r b5925bd396db 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,21 @@
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 finalDur = 1;
+ if (m_param->rc.bStrictCbr)
+ {
+ finalDur = x265_clip3(0.4, 1.0, totalDuration);
+ }
+ targetFill = X265_MIN(m_bufferFill + totalDuration * m_vbvMaxRate * 0.5 , m_bufferSize * (1 - 0.5 * finalDur));
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 = x265_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 = x265_clip3(m_bufferSize * (1 - 0.2 * finalDur), m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);
if (m_isCbr && bufferFillCur > targetFill)
{
q /= 1.01;
@@ -1976,7 +1980,7 @@
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 rcTol = bufferLeftPlanned / m_param->frameNumThreads * m_param->rc.rateTolerance;
int32_t encodedBitsSoFar = 0;
double accFrameBits = predictRowsSizeSum(curFrame, rce, qpVbv, encodedBitsSoFar);
@@ -1994,7 +1998,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