Skip to content

Commit 3858272

Browse files
authored
close #296 , reduce single pass rate control deviation from given target bit-rate, when intra period is not a multiple of gop size (#298)
1 parent 3fcfd93 commit 3858272

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

source/Lib/EncoderLib/RateCtrl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ int RateCtrl::getBaseQP()
361361
else if (m_pcEncCfg->m_LookAhead)
362362
{
363363
baseQP = int (24.5 - log (d) / log (2.0)); // QPstart, equivalent to round (24 + 2*log2 (resRatio))
364-
d = MAX_QP_PERCEPT_QPA - 2.0 - 1.5 * firstQPOffset - 0.5 * log (double (encRCSeq->intraPeriod / encRCSeq->gopSize)) / log (2.0);
364+
d = MAX_QP_PERCEPT_QPA - 2.0 - 1.5 * firstQPOffset - 0.5 * log ((double) encRCSeq->intraPeriod / encRCSeq->gopSize) / log (2.0);
365365
baseQP = int (0.5 + d + 0.5 * std::max (0.0, baseQP - d));
366366
}
367367

@@ -807,8 +807,8 @@ double RateCtrl::getAverageBitsFromFirstPass()
807807

808808
if (encRCSeq->intraPeriod > 1 && encRCSeq->gopSize > 1 && m_pcEncCfg->m_LookAhead)
809809
{
810-
const int gopsInIp = encRCSeq->intraPeriod / encRCSeq->gopSize;
811-
int l = 1;
810+
const int gopsInIp = (2 * encRCSeq->intraPeriod + (encRCSeq->gopSize >> 1)) / encRCSeq->gopSize;
811+
int l = 2 - (gopsInIp & 1); // fract. tuning
812812
uint64_t tlBits [8] = { 0 };
813813
unsigned tlCount[8] = { 0 };
814814

@@ -832,14 +832,14 @@ double RateCtrl::getAverageBitsFromFirstPass()
832832
l = 0; // no I-frame in the analysis range
833833
}
834834

835-
totalBitsFirstPass = (tlBits[0] + (tlCount[0] >> 1)) / std::max (1u, tlCount[0]) +
835+
totalBitsFirstPass = (2 * tlBits[0] + (tlCount[0] >> 1)) / std::max (1u, tlCount[0]) +
836836
((gopsInIp - l) * tlBits[1] + (tlCount[1] >> 1)) / std::max (1u, tlCount[1]);
837837
for (l = 2; l <= 7; l++)
838838
{
839839
totalBitsFirstPass += ((gopsInIp << (l - 2)) * tlBits[l] + (tlCount[l] >> 1)) / std::max (1u, tlCount[l]);
840840
}
841841

842-
return totalBitsFirstPass / (double) encRCSeq->intraPeriod;
842+
return totalBitsFirstPass / (2.0 * encRCSeq->intraPeriod);
843843
}
844844

845845
for (it = m_listRCFirstPassStats.begin(); it != m_listRCFirstPassStats.end(); it++) // for two-pass RC

source/Lib/vvenc/vvencCfg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,8 @@ VVENC_DECL bool vvenc_init_config_parameter( vvenc_config *c )
793793

794794
if( c->m_RCTargetBitrate != VVENC_RC_OFF && c->m_QP != VVENC_AUTO_QP && c->m_QP != rcQP )
795795
{
796-
msg.log( VVENC_WARNING, "Configuration warning: Rate control is enabled since a target bitrate is specified, ignoring QP value\n\n" );
796+
if( c->m_QP != VVENC_DEFAULT_QP )
797+
msg.log( VVENC_WARNING, "Configuration warning: Rate control is enabled since a target bitrate is specified, ignoring QP value\n\n" );
797798
c->m_QP = VVENC_AUTO_QP;
798799
}
799800

0 commit comments

Comments
 (0)