[x265] [PATCH] rc: fix zone in multi-pass encodes

Divya Manivannan divya at multicorewareinc.com
Wed Mar 16 11:05:32 CET 2016


# HG changeset patch
# User Divya Manivannan <divya at multicorewareinc.com>
# Date 1458118488 -19800
#      Wed Mar 16 14:24:48 2016 +0530
# Node ID 2fa58c1c53387fa89972e9bfc27f949750c42f72
# Parent  4a2f94a592511afabd434fc6cf02a469b6d65091
rc: fix zone in multi-pass encodes

diff -r 4a2f94a59251 -r 2fa58c1c5338 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Wed Mar 09 14:34:06 2016 +0530
+++ b/source/encoder/ratecontrol.cpp	Wed Mar 16 14:24:48 2016 +0530
@@ -1359,14 +1359,6 @@
         m_accumPNorm = mask * (1 + m_accumPNorm);
     }
 
-    x265_zone* zone = getZone();
-    if (zone)
-    {
-        if (zone->bForceQp)
-            q = x265_qp2qScale(zone->qp);
-        else
-            q /= zone->bitrateFactor;
-    }
     return q;
 }
 double RateControl::countExpectedBits(int startPos, int endPos)
@@ -1688,6 +1680,14 @@
             }
             diff = m_predictedBits - (int64_t)rce->expectedBits;
             q = rce->newQScale;
+            x265_zone* zone = getZone();
+            if (zone)
+            {
+                if (zone->bForceQp)
+                    q = x265_qp2qScale(zone->qp);
+                else
+                    q /= zone->bitrateFactor;
+            }
             q /= x265_clip3(0.5, 2.0, (double)(abrBuffer - diff) / abrBuffer);
             if (m_expectedBitsSum > 0)
             {
@@ -1749,12 +1749,28 @@
             if (m_param->rc.rateControlMode == X265_RC_CRF)
             {
                 q = getQScale(rce, m_rateFactorConstant);
+                x265_zone* zone = getZone();
+                if (zone)
+                {
+                    if (zone->bForceQp)
+                        q = x265_qp2qScale(zone->qp);
+                    else
+                        q /= zone->bitrateFactor;
+                }
             }
             else
             {
                 if (!m_param->rc.bStatRead)
                     checkAndResetABR(rce, false);
                 double initialQScale = getQScale(rce, m_wantedBitsWindow / m_cplxrSum);
+                x265_zone* zone = getZone();
+                if (zone)
+                {
+                    if (zone->bForceQp)
+                        initialQScale = x265_qp2qScale(zone->qp);
+                    else
+                        initialQScale /= zone->bitrateFactor;
+                }
                 double tunedQScale = tuneAbrQScaleFromFeedback(initialQScale);
                 overflow = tunedQScale / initialQScale;
                 q = !m_partialResidualFrames? tunedQScale : initialQScale;
@@ -2359,15 +2375,7 @@
         m_lastRceq = q;
         q /= rateFactor;
     }
-    
-    x265_zone* zone = getZone();
-    if (zone)
-    {
-        if (zone->bForceQp)
-            q = x265_qp2qScale(zone->qp);
-        else
-            q /= zone->bitrateFactor;
-    }
+
     return q;
 }
 


More information about the x265-devel mailing list