[x265] [PATCH] rc: Bug fixes for ABR

Aarthi Thirumalai aarthi at multicorewareinc.com
Tue Oct 22 08:35:30 CEST 2013


# HG changeset patch
# User Aarthi Thirumalai
# Date 1382423723 -19800
#      Tue Oct 22 12:05:23 2013 +0530
# Node ID f8ab02273bdb8cfa271f7139a3208400bcfe1cd7
# Parent  9245a882ccee89fc1d158b501587bac7d6e081e4
rc: Bug fixes for ABR.

remove uninitialized local variables and use values from cfg.param.rc as required.

diff -r 9245a882ccee -r f8ab02273bdb source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Mon Oct 21 22:45:55 2013 -0500
+++ b/source/encoder/ratecontrol.cpp	Tue Oct 22 12:05:23 2013 +0530
@@ -149,7 +149,7 @@
         accumPNorm = .01;
         accumPQp = (ABR_INIT_QP_MIN)*accumPNorm;
         /* estimated ratio that produces a reasonable QP for the first I-frame */
-        cplxrSum = .01 * pow(7.0e5, qCompress) * pow(2 * ncu, 0.5);
+        cplxrSum = .01 * pow(7.0e5, cfg->param.rc.qCompress) * pow(2 * ncu, 0.5);
         wantedBitsWindow = bitrate * frameDuration;
         lastNonBPictType = I_SLICE;
     }
@@ -261,7 +261,7 @@
     }
     else
     {
-        double abrBuffer = 1.5 * rateTolerance * bitrate;
+        double abrBuffer = 1.5 * cfg->param.rc.rateTolerance * bitrate;
 
         /* 1pass ABR */
 
@@ -291,7 +291,7 @@
         if (lastSatd)
         {
             /* use framesDone instead of POC as poc count is not serial with bframes enabled */
-            double timeDone = (double)(framesDone - frameThreads + 1) / framerate;
+            double timeDone = (double)(framesDone - frameThreads + 1) / cfg->param.frameRate;
             wantedBits = timeDone * bitrate;
             if (wantedBits > 0 && totalBits > 0)
             {
@@ -301,11 +301,11 @@
             }
         }
 
-        if (pictType == I_SLICE && keyFrameInterval > 1
+        if (pictType == I_SLICE && cfg->param.keyframeMax > 1
             && lastNonBPictType != I_SLICE)
         {
             q = qp2qScale(accumPQp / accumPNorm);
-            q /= fabs(ipFactor);
+            q /= fabs(cfg->param.rc.ipFactor);
         }
         if (cfg->param.rc.rateControlMode != X265_RC_CRF)
         {
@@ -354,7 +354,7 @@
         lastQScaleFor[pictType] = q;
 
         if (curFrame->getPOC() == 0)
-            lastQScaleFor[P_SLICE] = q * fabs(ipFactor);
+            lastQScaleFor[P_SLICE] = q * fabs(cfg->param.rc.ipFactor);
 
         return q;
     }
@@ -367,7 +367,7 @@
 {
     double q;
 
-    q = pow(rce->blurredComplexity, 1 - qCompress);
+    q = pow(rce->blurredComplexity, 1 - cfg->param.rc.qCompress);
 
     // avoid NaN's in the rc_eq
     if (rce->texBits + rce->mvBits == 0)
@@ -393,7 +393,7 @@
         {
             /* Depends on the fact that B-frame's QP is an offset from the following P-frame's.
              * Not perfectly accurate with B-refs, but good enough. */
-            cplxrSum += bits * qp2qScale(rce->qpaRc) / (rce->qRceq * fabs(pbFactor));
+            cplxrSum += bits * qp2qScale(rce->qpaRc) / (rce->qRceq * fabs(cfg->param.rc.pbFactor));
         }
         wantedBitsWindow += frameDuration * bitrate;
         rce = NULL;
diff -r 9245a882ccee -r f8ab02273bdb source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h	Mon Oct 21 22:45:55 2013 -0500
+++ b/source/encoder/ratecontrol.h	Tue Oct 22 12:05:23 2013 +0530
@@ -47,23 +47,18 @@
     TEncCfg *cfg;
     SliceType frameType;        /* Current frame type */
     int ncu;                    /* number of CUs in a frame */
-    int framerate;              /* current frame rate TODO: need to initialize in init */
     int frameThreads;
     int keyFrameInterval;       /* TODO: need to initialize in init */
     int qp;                     /* updated qp for current frame */
     int baseQp;                 /* CQP base QP */
     double frameDuration;        /* current frame duration in seconds */
     double bitrate;
-    double rateTolerance;
-    double qCompress;
     int    lastSatd;
     int    qpConstant[3];
     double cplxrSum;           /* sum of bits*qscale/rceq */
     double wantedBitsWindow;  /* target bitrate * window */
     double ipOffset;
     double pbOffset;
-    double ipFactor;
-    double pbFactor;
     int lastNonBPictType;
     double accumPQp;          /* for determining I-frame quant */
     double accumPNorm;


More information about the x265-devel mailing list