[x265] [PATCH] rc: fixes for 2 pass + vbv to calculate frameSizePlanned accurately
aarthi at multicorewareinc.com
aarthi at multicorewareinc.com
Tue Sep 16 10:51:39 CEST 2014
# HG changeset patch
# User Aarthi Thirumalai
# Date 1410757433 -19800
# Mon Sep 15 10:33:53 2014 +0530
# Node ID 49c54a540cc237659416be7d5fb53241fb0094e4
# Parent 1de67321275e70d510f0df3d5b7d4b9d391a1e66
rc: fixes for 2 pass + vbv to calculate frameSizePlanned accurately.
diff -r 1de67321275e -r 49c54a540cc2 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Mon Sep 15 15:00:13 2014 +0200
+++ b/source/encoder/encoder.cpp Mon Sep 15 10:33:53 2014 +0530
@@ -235,13 +235,10 @@
void Encoder::updateVbvPlan(RateControl* rc)
{
int encIdx, curIdx;
-
- curIdx = (m_curEncoder + m_param->frameNumThreads - 1) % m_param->frameNumThreads;
- encIdx = (curIdx + 1) % m_param->frameNumThreads;
- while (encIdx != curIdx)
+ for ( int i = 0; i < m_param->frameNumThreads; i++)
{
- FrameEncoder *encoder = &m_frameEncoder[encIdx];
- if (encoder->m_rce.isActive)
+ FrameEncoder *encoder = &m_frameEncoder[i];
+ if (encoder->m_rce.isActive && encoder->m_rce.poc != rc->m_curSlice->m_poc)
{
int64_t bits = (int64_t) X265_MAX(encoder->m_rce.frameSizeEstimated, encoder->m_rce.frameSizePlanned);
rc->m_bufferFill -= bits;
@@ -251,7 +248,6 @@
if (rc->m_2pass)
rc->m_predictedBits += bits;
}
- encIdx = (encIdx + 1) % m_param->frameNumThreads;
}
}
diff -r 1de67321275e -r 49c54a540cc2 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Mon Sep 15 15:00:13 2014 +0200
+++ b/source/encoder/ratecontrol.cpp Mon Sep 15 10:33:53 2014 +0530
@@ -1365,12 +1365,20 @@
q += m_pbOffset;
rce->qpNoVbv = q;
double qScale = x265_qp2qScale(q);
- if (m_leadingBframes > 5 && m_isVbv)
+
+ if (!m_2pass && m_isVbv)
{
- qScale = clipQscale(pic, qScale);
- m_lastQScaleFor[m_sliceType] = qScale;
+ if (m_leadingBframes > 5)
+ {
+ qScale = clipQscale(pic, qScale);
+ m_lastQScaleFor[m_sliceType] = qScale;
+ }
+ rce->frameSizePlanned = predictSize(&m_predBfromP, qScale, (double)m_leadingNoBSatd);
}
- rce->frameSizePlanned = predictSize(&m_predBfromP, qScale, (double)m_leadingNoBSatd);
+ else if (m_2pass && m_isVbv)
+ {
+ rce->frameSizePlanned = qScale2bits(rce, qScale);
+ }
rce->frameSizeEstimated = rce->frameSizePlanned;
rce->newQScale = qScale;
return qScale;
@@ -1400,8 +1408,7 @@
diff = m_predictedBits - (int64_t)rce->expectedBits;
q = rce->newQScale;
q /= Clip3(0.5, 2.0, (double)(abrBuffer - diff) / abrBuffer);
- if (((rce->encodeOrder + 1 - m_param->frameNumThreads) >= m_fps) &&
- (m_expectedBitsSum > 0))
+ if (m_expectedBitsSum > 0)
{
/* Adjust quant based on the difference between
* achieved and expected bitrate so far */
More information about the x265-devel
mailing list