[x265] [PATCH] Added few varibales in related to ABR stuff in x265_param_t and made corresponding changes in ratecontrol.cpp and .h

Steve Borho steve at borho.org
Mon Aug 12 13:16:25 CEST 2013


On Mon, Aug 12, 2013 at 5:45 AM, <sumalatha at multicorewareinc.com> wrote:

> # HG changeset patch
> # User sumalatha
> # Date 1376304273 -19800
> # Node ID 5a8afc3a576d259337176870a4de8af1da0703a9
> # Parent  14f9aa8dbe2e9dba972211146fa8675d0aa9240e
> Added few varibales in related to ABR stuff in x265_param_t and made
> corresponding changes in ratecontrol.cpp and .h
>
> diff -r 14f9aa8dbe2e -r 5a8afc3a576d source/common/common.cpp
> --- a/source/common/common.cpp  Mon Aug 12 04:55:03 2013 -0500
> +++ b/source/common/common.cpp  Mon Aug 12 16:14:33 2013 +0530
> @@ -137,6 +137,15 @@
>      param->bEnableRDOQTS = 1;
>      param->bEnableTransformSkip = 1;
>      param->bEnableTSkipFast = 1;
>


> +    //ABR relatedstuff
> +    param->bitrate = 1000;
> +    param->rateTolerance = 1;
> +    param->isAbrEnabled = true;
>

Lets add param->rateControlMode and enums like:

X265_RC_ABR
X265_RC_CQP


> +    param->qCompress = 0.6;
> +    param->ipFactor = 1.4;
> +    param->pbFactor = 1.3;
> +    param->iQpStep = 4;
> +
>

pls remove blank line here


>  }
>
>  extern "C"
> diff -r 14f9aa8dbe2e -r 5a8afc3a576d source/encoder/ratecontrol.cpp
> --- a/source/encoder/ratecontrol.cpp    Mon Aug 12 04:55:03 2013 -0500
> +++ b/source/encoder/ratecontrol.cpp    Mon Aug 12 16:14:33 2013 +0530
> @@ -31,27 +31,37 @@
>      keyFrameInterval = param->keyframeInterval;
>      fps = param->frameRate;
>      bframes = param->bframes;
> -    //TODO : set default value here,later can get from  param as done in
> x264?
> -    rateTolerance = 1;
> -    //TODO : introduce bitrate var in param and cli options
> +    rateTolerance = param->rateTolerance;
>      bitrate = param->bitrate * 1000;
>      fps = param->frameRate;
> -    isAbrEnabled = true; // set from param later.
> +    isAbrEnabled = param->isAbrEnabled; // set from param later.
>      ncu = (param->sourceHeight * param->sourceWidth) / pow(2,
> param->maxCUSize);
>      lastNonBPictType = -1;
> -    //TODO : need  to confirm default val if mbtree is disabled
> -    qCompress = 1;
> +    qCompress = param->qCompress;
> +    ipFactor = param->ipFactor;
> +    pbFactor = param->pbFactor;
>      if (isAbrEnabled)
>      {
>          //TODO : confirm this value. obtained it from x264 when crf is
> disabled , abr enabled.
> -#define ABR_INIT_QP (24  + 6 * (param->internalBitDepth - 8));
> +#define ABR_INIT_QP (24  + 6 * (param->internalBitDepth - 8))
>

X265_DEPTH instead of param->internalBitDepth


>          accumPNorm = .01;
>          accumPQp = (ABR_INIT_QP)*accumPNorm;
>          /* estimated ratio that produces a reasonable QP for the first
> I-frame */
>          cplxrSum = .01 * pow(7.0e5, qCompress) * pow(ncu, 0.5);
>          wantedBitsWindow = 1.0 * bitrate / fps;
>          lastNonBPictType = I_SLICE;
> +
>

another extra blank line


>      }
> +    ipOffset = 6.0 * log( param->ipFactor );
> +    pbOffset = 6.0 * log( param->pbFactor );
> +    for( int i = 0; i < 3; i++ )
> +    {
> +        lastQScaleFor[i] = qp2qScale( ABR_INIT_QP );
> +        lmin[i] = qp2qScale( MIN_QP);
> +        lmax[i] = qp2qScale( MAX_QP );
> +    }
> +    lstep = pow( 2, param->iQpStep / 6.0 );
> +
>  }
>
>  void RateControl::rateControlInit(TComSlice* frame)
> @@ -86,7 +96,6 @@
>
>  void RateControl::accumPQpUpdate()
>  {
> -    //x264_ratecontrol_t *rc = h->rc;
>      accumPQp   *= .95;
>      accumPNorm *= .95;
>      accumPNorm += 1;
> @@ -131,7 +140,6 @@
>          else
>              q += pbOffset;
>
> -        qpNoVbv = q;
>          return qp2qScale(q);
>      }
>      else
> @@ -152,20 +160,14 @@
>
>          double wantedBits, overflow = 1;
>
> -        lastSatd = 0;     //need to get this from lookahead
>  //x264_rc_analyse_slice( h );
> -        shortTermCplxSum *= 0.5;
> -        shortTermCplxCount *= 0.5;
> -        //TODO:need to get the duration for each frame
> -        //short_term_cplxsum += last_satd /
> (CLIP_DURATION(h->fenc->f_duration) / BASE_FRAME_DURATION);
> -        shortTermCplxCount++;
> -
> +        lastSatd = 0;     //TODO:need to get this from lookahead
>  //x264_rc_analyse_slice( h );
>          rce->pCount = ncu;
>
>          rce->pictType = pictType;
>
>          //TODO:wanted_bits_window, fps , h->fenc->i_reordered_pts,
> h->i_reordered_pts_delay, h->fref_nearest[0]->f_qp_avg_rc,
> h->param.rc.f_ip_factor, h->sh.i_type
>          //need to checked where it is initialized
> -        q = getQScale(rce, wantedBitsWindow / cplxrSum, fps);
> +        q = getQScale(rce, wantedBitsWindow / cplxrSum);
>
>          /* ABR code can potentially be counterproductive in CBR, so just
> don't bother.
>           * Don't run it if the frame complexity is zero either. */
> @@ -193,7 +195,7 @@
>              && lastNonBPictType != I_SLICE)
>          {
>              q = qp2qScale(accumPQp / accumPNorm);
> -            q /= fabs(h->param.rc.f_ip_factor);
> +            q /= fabs(ipFactor);
>          }
>          else if (fps > 0)
>          {
> @@ -212,7 +214,7 @@
>              }
>          }
>
> -        qpNoVbv = qScale2qp(q);
> +        //qpNoVbv = qScale2qp(q);
>
>          //FIXME use get_diff_limited_q() ?
>          //q = clip_qscale( h, pict_type, q );
> @@ -224,7 +226,7 @@
>              lastQScale = q;
>
>          if (!fps == 0)
> -            lastQScaleFor[P_SLICE] = q * fabs(h->param.rc.f_ip_factor);
> +            lastQScaleFor[P_SLICE] = q * fabs(ipFactor);
>
>          //this is for VBV stuff
>          //frame_size_planned = predict_size( &pred[h->sh.i_type], q,
> last_satd );
> @@ -249,7 +251,7 @@
>          q = lastQScaleFor[rce->pictType];
>      else
>      {
> -        lastRceq = q;
> +        //lastRceq = q;// CHECK: not used further
>          q /= rateFactor;
>          lastQScale = q;
>      }
> diff -r 14f9aa8dbe2e -r 5a8afc3a576d source/encoder/ratecontrol.h
> --- a/source/encoder/ratecontrol.h      Mon Aug 12 04:55:03 2013 -0500
> +++ b/source/encoder/ratecontrol.h      Mon Aug 12 16:14:33 2013 +0530
> @@ -59,8 +59,8 @@
>      int ncu;                    /* number of CUs in a frame */
>      TComSlice *curFrame;        /* all info abt the current frame */
>      SliceType frameType;        /* Current frame type */
> -    float frameDuration;        /* current frame duration in seconds */
> -    int fps;          /* current frame number TODO: need to initaialize
> in init */
> +    //float frameDuration;        /* current frame duration in seconds */
> +    int fps;                    /* current frame rate TODO: need to
> initaialize in init */
>      int keyFrameInterval;       /* TODO: need to initialize in init */
>      bool isAbrEnabled;
>
> @@ -75,17 +75,13 @@
>      int bframes;
>      /* ABR stuff */
>      int    lastSatd;
> -    double lastRceq;
>      double cplxrSum;           /* sum of bits*qscale/rceq */
> -    double expectedBitsSum;   /* sum of qscale2bits after rceq,
> ratefactor, and overflow, only includes finished frames */
> -    int64_t fillerBitsSum;    /* sum in bits of finished frames' filler
> data */
>      double wantedBitsWindow;  /* target bitrate * window */
> -    double cbrDecay;
> -    double shortTermCplxSum;
> -    double shortTermCplxCount;
> -    double rateFactorConstant;
> +
>      double ipOffset;
>      double pbOffset;
> +    float ipFactor;
> +    float pbFactor;
>
>      int lastNonBPictType;
>      double accumPQp;          /* for determining I-frame quant */
> @@ -97,7 +93,6 @@
>      float qpNoVbv;             /* QP for the current frame if 1-pass VBV
> was disabled. */
>      double lmin[3];             /* min qscale by frame type */
>      double lmax[3];
> -    double frameSizePlanned;
>
>      RateControl(x265_param_t * param);    // constructor for initializing
> values for ratecontrol vars
>      void rateControlInit(TComSlice* frame);   // to be called for each
> frame to set the reqired parameters for rateControl.
> diff -r 14f9aa8dbe2e -r 5a8afc3a576d source/x265.h
> --- a/source/x265.h     Mon Aug 12 04:55:03 2013 -0500
> +++ b/source/x265.h     Mon Aug 12 16:14:33 2013 +0530
> @@ -218,6 +218,15 @@
>
>      // debugging
>      int       bEnableDecodedPictureHashSEI;    ///<
> Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI
> message
> +
>

it's tempting to place all of this into a struct rc {} sub-structure.

+    //ABR related Stuff
> +    double    bitrate;
> +    bool      isAbrEnabled;
> +    double    rateTolerance;
> +    double    qCompress;
>

is there a compelling reason to mix double and float here?


> +    float     ipFactor;
> +    float     pbFactor;
> +    int       iQpStep;
>

is the i prefix meaningful? should this just be qpStep?


>  }
>  x265_param_t;
>
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> http://mailman.videolan.org/listinfo/x265-devel
>



-- 
Steve Borho
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/private/x265-devel/attachments/20130812/71af1ded/attachment-0001.html>


More information about the x265-devel mailing list