@@ -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
0 commit comments