changeset 12645:eca79c288012

Fix the RC Pass2 ABR This commit does the following changes: 1. Fix the order of RC Pass 1 stats Analysis in Pass2 2. Fix the aggressive Qp tuning for I/P frames in Pass2
author Kirithika <kirithika@multicorewareinc.com>
date Fri, 18 Oct 2019 14:18:00 +0530
parents 94bfe7f2c0c1
children 37916f420742
files source/encoder/ratecontrol.cpp
diffstat 1 files changed, 10 insertions(+-), 11 deletions(-) [+]
line wrap: on
line diff
--- a/source/encoder/ratecontrol.cpp	Thu Apr 16 18:48:56 2020 +0530
+++ b/source/encoder/ratecontrol.cpp	Fri Oct 18 14:18:00 2019 +0530
@@ -833,7 +833,7 @@ bool RateControl::analyseABR2Pass(uint64
         /* weighted average of cplx of future frames */
         for (int j = 1; j < cplxBlur * 2 && j < m_numEntries - i; j++)
         {
-            int index = m_encOrder[i + j];
+            int index = i+j;
             RateControlEntry *rcj = &m_rce2Pass[index];
             weight *= 1 - pow(rcj->iCuCount / m_ncu, 2);
             if (weight < 0.0001)
@@ -846,7 +846,7 @@ bool RateControl::analyseABR2Pass(uint64
         weight = 1.0;
         for (int j = 0; j <= cplxBlur * 2 && j <= i; j++)
         {
-            int index = m_encOrder[i - j];
+            int index = i-j;
             RateControlEntry *rcj = &m_rce2Pass[index];
             gaussianWeight = weight * exp(-j * j / 200.0);
             weightSum += gaussianWeight;
@@ -855,7 +855,7 @@ bool RateControl::analyseABR2Pass(uint64
             if (weight < .0001)
                 break;
         }
-        m_rce2Pass[m_encOrder[i]].blurredComplexity = cplxSum / weightSum;
+        m_rce2Pass[i].blurredComplexity= cplxSum / weightSum;
     }
     CHECKED_MALLOC(qScale, double, m_numEntries);
     if (filterSize > 1)
@@ -874,7 +874,7 @@ bool RateControl::analyseABR2Pass(uint64
     expectedBits = 1;
     for (int i = 0; i < m_numEntries; i++)
     {
-        RateControlEntry* rce = &m_rce2Pass[m_encOrder[i]];
+        RateControlEntry* rce = &m_rce2Pass[i];
         double q = getQScale(rce, 1.0);
         expectedBits += qScale2bits(rce, q);
         m_lastQScaleFor[rce->sliceType] = q;
@@ -897,15 +897,15 @@ bool RateControl::analyseABR2Pass(uint64
         /* find qscale */
         for (int i = 0; i < m_numEntries; i++)
         {
-            RateControlEntry *rce = &m_rce2Pass[m_encOrder[i]];
+            RateControlEntry *rce = &m_rce2Pass[i];
             qScale[i] = getQScale(rce, rateFactor);
             m_lastQScaleFor[rce->sliceType] = qScale[i];
         }
 
         /* fixed I/B qscale relative to P */
-        for (int i = m_numEntries - 1; i >= 0; i--)
+        for (int i = 0; i < m_numEntries; i++)
         {
-            qScale[i] = getDiffLimitedQScale(&m_rce2Pass[m_encOrder[i]], qScale[i]);
+            qScale[i] = getDiffLimitedQScale(&m_rce2Pass[i], qScale[i]);
             X265_CHECK(qScale[i] >= 0, "qScale became negative\n");
         }
 
@@ -916,7 +916,6 @@ bool RateControl::analyseABR2Pass(uint64
             for (int i = 0; i < m_numEntries; i++)
             {
                 double q = 0.0, sum = 0.0;
-
                 for (int j = 0; j < filterSize; j++)
                 {
                     int idx = i + j - filterSize / 2;
@@ -924,7 +923,7 @@ bool RateControl::analyseABR2Pass(uint64
                     double coeff = qBlur == 0 ? 1.0 : exp(-d * d / (qBlur * qBlur));
                     if (idx < 0 || idx >= m_numEntries)
                         continue;
-                    if (m_rce2Pass[m_encOrder[i]].sliceType != m_rce2Pass[m_encOrder[idx]].sliceType)
+                    if (m_rce2Pass[i].sliceType != m_rce2Pass[idx].sliceType)
                         continue;
                     q += qScale[idx] * coeff;
                     sum += coeff;
@@ -936,7 +935,7 @@ bool RateControl::analyseABR2Pass(uint64
         /* find expected bits */
         for (int i = 0; i < m_numEntries; i++)
         {
-            RateControlEntry *rce = &m_rce2Pass[m_encOrder[i]];
+            RateControlEntry *rce = &m_rce2Pass[i];
             rce->newQScale = clipQscale(NULL, rce, blurredQscale[i]); // check if needed
             X265_CHECK(rce->newQScale >= 0, "new Qscale is negative\n");
             expectedBits += qScale2bits(rce, rce->newQScale);
@@ -1956,7 +1955,7 @@ double RateControl::rateEstimateQscale(F
                 /* Adjust quant based on the difference between
                  * achieved and expected bitrate so far */
                 double curTime = (double)rce->encodeOrder / m_numEntries;
-                double w = x265_clip3(0.0, 1.0, curTime * 100);
+                double w = x265_clip3(0.0, 1.0, curTime);
                 q *= pow((double)m_totalBits / m_expectedBitsSum, w);
             }
             if (m_framesDone == 0 && m_param->rc.rateControlMode == X265_RC_ABR && m_isGrainEnabled)