[x265] [PATCH 2 of 4] rc: clamp qp for first I frame only in rateEstimateQscale (changes output)

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Thu May 8 20:28:25 CEST 2014


# HG changeset patch
# User Aarthi Thirumalai
# Date 1399573309 -19800
#      Thu May 08 23:51:49 2014 +0530
# Node ID 7ae5c6b44e111240f8b0727254db0c2ca91c0506
# Parent  06c641032ed727f7160c3c6e412576b2f8935a19
rc: clamp qp for first I frame only in rateEstimateQscale (changes output)

diff -r 06c641032ed7 -r 7ae5c6b44e11 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Thu May 08 23:43:59 2014 +0530
+++ b/source/encoder/ratecontrol.cpp	Thu May 08 23:51:49 2014 +0530
@@ -443,6 +443,7 @@
     if (pic->m_forceqp)
     {
         qp = int32_t(pic->m_forceqp + 0.5) - 1;
+        qp = Clip3(MIN_QP, MAX_MAX_QP, qp);
         rce->qpaRc = pic->m_avgQpRc = pic->m_avgQpAq = qp;
     }
     framesDone++;
@@ -571,34 +572,35 @@
             q = x265_qp2qScale(accumPQp / accumPNorm);
             q /= fabs(param->rc.ipFactor);
         }
+
         else if (framesDone > 0)
         {
             if (param->rc.rateControlMode != X265_RC_CRF)
             {
                 double lqmin = 0, lqmax = 0;
-                if (totalBits == 0 && !isVbv)
-                {
-                    lqmin = x265_qp2qScale(ABR_INIT_QP_MIN) / lstep;
-                    lqmax = x265_qp2qScale(ABR_INIT_QP_MAX) * lstep;
-                    q = Clip3(lqmin, lqmax, q);
-                }
-                else if (totalBits > 0 || (isVbv && framesDone > 0))
-                {
-                    lqmin = lastQScaleFor[sliceType] / lstep;
-                    lqmax = lastQScaleFor[sliceType] * lstep;
-                    if (overflow > 1.1 && framesDone > 3)
-                        lqmax *= lstep;
-                    else if (overflow < 0.9)
-                        lqmin /= lstep;
-                    q = Clip3(lqmin, lqmax, q);
-                }
+                lqmin = lastQScaleFor[sliceType] / lstep;
+                lqmax = lastQScaleFor[sliceType] * lstep;
+                if (overflow > 1.1 && framesDone > 3)
+                    lqmax *= lstep;
+                else if (overflow < 0.9)
+                    lqmin /= lstep;
+                q = Clip3(lqmin, lqmax, q);
             }
         }
+
         else if (qCompress != 1 && param->rc.rateControlMode == X265_RC_CRF)
         {
             q = x265_qp2qScale(CRF_INIT_QP) / fabs(param->rc.ipFactor);
         }
 
+        else if (framesDone == 0 && !isVbv)
+        {
+            /* for ABR alone, clipe the first I frame qp within the range (ABR_INIT_QP_MIN, ABR_INIT_QP_MAX) to ensure quality. */
+            double lqmin = x265_qp2qScale(ABR_INIT_QP_MIN) / lstep;
+            double lqmax = x265_qp2qScale(ABR_INIT_QP_MAX) * lstep;
+            q = Clip3(lqmin, lqmax, q);
+        }
+
         q = Clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
         rce->qpNoVbv = x265_qScale2qp(q);
 


More information about the x265-devel mailing list