[x265] [PATCH 1 of 4 x265] Fix the RC Pass2 ABR

kirithika at multicorewareinc.com kirithika at multicorewareinc.com
Wed Apr 22 09:14:14 CEST 2020


# HG changeset patch
# User Kirithika <kirithika at multicorewareinc.com>
# Date 1571388480 -19800
#      Fri Oct 18 14:18:00 2019 +0530
# Node ID 851a02eea935bacf74eb35655798f72892580880
# Parent  6bb2d88029c2e13fa13b5b053aa725d4fa84a084
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

diff -r 6bb2d88029c2 -r 851a02eea935 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Thu Apr 09 13:09:15 2020 +0530
+++ b/source/encoder/ratecontrol.cpp	Fri Oct 18 14:18:00 2019 +0530
@@ -833,7 +833,7 @@
         /* 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 @@
         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 @@
             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 @@
     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 @@
         /* 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 @@
             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 @@
                     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 @@
         /* 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 @@
                 /* 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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x265-1.patch
Type: text/x-patch
Size: 4489 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20200422/e09e2eeb/attachment.bin>


More information about the x265-devel mailing list