[x265] [PATCH] x265: implemented crf-min that specifies a minimum rate factor value for encode

Aarthi Priya Thirumalai aarthi at multicorewareinc.com
Thu May 8 07:37:23 CEST 2014


On Thu, May 8, 2014 at 10:39 AM, <gopu at multicorewareinc.com> wrote:

> # HG changeset patch
> # User Gopu Govindaswamy
> # Date 1399524053 -19800
> #      Thu May 08 10:10:53 2014 +0530
> # Node ID 7a3657ff29e24b7832002b76b3f9096736d20a36
> # Parent  6494bb2e64253fc0f9413b88933634d1f37c4881
> x265: implemented crf-min that specifies a minimum rate factor value for
> encode
>
> diff -r 6494bb2e6425 -r 7a3657ff29e2 source/common/param.cpp
> --- a/source/common/param.cpp   Wed May 07 14:03:25 2014 -0500
> +++ b/source/common/param.cpp   Thu May 08 10:10:53 2014 +0530
> @@ -604,6 +604,7 @@
>      OPT("vbv-bufsize") p->rc.vbvBufferSize = atoi(value);
>      OPT("vbv-init")    p->rc.vbvBufferInit = atof(value);
>      OPT("crf-max")     p->rc.rfConstantMax = atof(value);
> +    OPT("crf-min")     p->rc.rfConstantMin = atoi(value);
>      OPT("crf")
>      {
>          p->rc.rfConstant = atof(value);
> diff -r 6494bb2e6425 -r 7a3657ff29e2 source/encoder/encoder.cpp
> --- a/source/encoder/encoder.cpp        Wed May 07 14:03:25 2014 -0500
> +++ b/source/encoder/encoder.cpp        Thu May 08 10:10:53 2014 +0530
> @@ -1342,6 +1342,12 @@
>          x265_log(p, X265_LOG_WARNING, "Support for interlaced video is
> experimental\n");
>      }
>
> +    if (p->rc.rfConstantMin > p->rc.rfConstant)
> +    {
> +        x265_log(param, X265_LOG_WARNING, "CRF min must be less than
> CRF\n");
> +        p->rc.rfConstantMin = 0;
> +    }
> +
>      m_bframeDelay = p->bframes ? (p->bBPyramid ? 2 : 1) : 0;
>
>      //====== Coding Tools ========
> diff -r 6494bb2e6425 -r 7a3657ff29e2 source/encoder/ratecontrol.cpp
> --- a/source/encoder/ratecontrol.cpp    Wed May 07 14:03:25 2014 -0500
> +++ b/source/encoder/ratecontrol.cpp    Thu May 08 10:10:53 2014 +0530
> @@ -207,6 +207,7 @@
>      param->rc.rfConstant = Clip3((double)-QP_BD_OFFSET, (double)51,
> param->rc.rfConstant);
>      param->rc.rfConstantMax = Clip3((double)-QP_BD_OFFSET, (double)51,
> param->rc.rfConstantMax);
>      rateFactorMaxIncrement = 0;
> +    rateFactorMaxDecrement = 0;
>
>      if (param->rc.rateControlMode == X265_RC_CRF)
>      {
> @@ -226,6 +227,8 @@
>                  rateFactorMaxIncrement = 0;
>              }
>          }
> +        if (param->rc.rfConstantMin)
> +            rateFactorMaxDecrement = param->rc.rfConstant -
> param->rc.rfConstantMin;
>      }
>
>      isAbr = param->rc.rateControlMode != X265_RC_CQP; // later add 2pass
> option
> @@ -851,10 +854,15 @@
>      /* tweak quality based on difference from predicted size */
>      double prevRowQp = qpVbv;
>      double qpAbsoluteMax = MAX_MAX_QP;
> +    double qpAbsoluteMin = MIN_QP;
>      if (rateFactorMaxIncrement)
>          qpAbsoluteMax = X265_MIN(qpAbsoluteMax, rce->qpNoVbv +
> rateFactorMaxIncrement);
> +
> +    if (rateFactorMaxDecrement)
> +        qpAbsoluteMin = X265_MAX(qpAbsoluteMin, rce->qpNoVbv -
> rateFactorMaxIncrement);
> +
>
should not the above line be maximum of  qpAbsoluteMin and qpNoVbv -
rateFactorMaxDecrement?

     double qpMax = X265_MIN(prevRowQp + param->rc.qpStep, qpAbsoluteMax);
> -    double qpMin = X265_MAX(prevRowQp - param->rc.qpStep, MIN_QP);
> +    double qpMin = X265_MAX(prevRowQp - param->rc.qpStep, qpAbsoluteMin);
>      double stepSize = 0.5;
>      double bufferLeftPlanned = rce->bufferFill - rce->frameSizePlanned;
>
> @@ -922,6 +930,12 @@
>              qpVbv = Clip3(prevRowQp + 1.0f, qpMax, (prevRowQp + qpVbv) *
> 0.5);
>              return -1;
>          }
> +
> +        if (qpVbv < qpMin && prevRowQp > qpMin && canReencodeRow)
> +        {
> +            qpVbv = Clip3(prevRowQp + 1.0f, (prevRowQp + qpVbv) * 0.5,
> qpMin);
> +            return -1;
> +        }
>
i think the above condition needs to be executed only
when param->rc.rfConstantMin is set. else we dont need to reencode if qp
falls lesser in normal scenarios.
also, the clip should be done as Clip3(qpMin, (prevRowQp - qpVbv) *
0.5, prevRowQp - 1.0f); - find a value between qpMin and prevRowQp.

     }
>      else
>      {
> diff -r 6494bb2e6425 -r 7a3657ff29e2 source/encoder/ratecontrol.h
> --- a/source/encoder/ratecontrol.h      Wed May 07 14:03:25 2014 -0500
> +++ b/source/encoder/ratecontrol.h      Thu May 08 10:10:53 2014 +0530
> @@ -96,6 +96,7 @@
>      double vbvMinRate;       /* in kbps */
>      bool singleFrameVbv;
>      double rateFactorMaxIncrement; /* Don't allow RF above (CRF + this
> value). */
> +    double rateFactorMaxDecrement; /* don't allow RF below (this value).
> */
>      bool isVbv;
>      Predictor pred[5];
>      Predictor predBfromP;
> diff -r 6494bb2e6425 -r 7a3657ff29e2 source/x265.cpp
> --- a/source/x265.cpp   Wed May 07 14:03:25 2014 -0500
> +++ b/source/x265.cpp   Thu May 08 10:10:53 2014 +0530
> @@ -129,6 +129,7 @@
>      { "weightb",              no_argument, NULL, 0 },
>      { "crf",            required_argument, NULL, 0 },
>      { "crf-max",        required_argument, NULL, 0 },
> +    { "crf-min",        required_argument, NULL, 0 },
>      { "vbv-maxrate",    required_argument, NULL, 0 },
>      { "vbv-bufsize",    required_argument, NULL, 0 },
>      { "vbv-init",       required_argument, NULL, 0 },
> @@ -360,6 +361,8 @@
>      H0("   --crf <float>                 Quality-based VBR (0-51).
> Default %f\n", param->rc.rfConstant);
>      H0("   --crf-max <float>             With CRF+VBV, limit RF to this
> value. 0 for no limit (default)\n");
>      H0("                                 May cause VBV underflows!\n");
> +    H0("   --crf-min <float>             With CRF+VBV, limit RF to this
> value. 0 for no limit (default)\n");
> +    H0("                                 this specifies a minimum rate
> factor value for encode!\n");
>      H0("   --vbv-maxrate <integer>       Max local bitrate (kbit/s).
> Default %d\n", param->rc.vbvMaxBitrate);
>      H0("   --vbv-bufsize <integer>       Set size of the VBV buffer
> (kbit). Default %d\n", param->rc.vbvBufferSize);
>      H0("   --vbv-init <float>            Initial VBV buffer occupancy
> (fraction of bufsize or in kbits). Default %f\n", param->rc.vbvBufferInit);
> diff -r 6494bb2e6425 -r 7a3657ff29e2 source/x265.h
> --- a/source/x265.h     Wed May 07 14:03:25 2014 -0500
> +++ b/source/x265.h     Thu May 08 10:10:53 2014 +0530
> @@ -703,6 +703,9 @@
>
>          /* In CRF mode, maximum CRF as caused by VBV. 0 implies no limit
> */
>          double    rfConstantMax;
> +
> +        /* In CRF mode, minimum CRF as caused by VBV */
> +        double    rfConstantMin;
>      } rc;
>
>      /*== Video Usability Information ==*/
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20140508/0de6d083/attachment-0001.html>


More information about the x265-devel mailing list