[x265] [PATCH] log: add the RateFactor for each frame to the .stats file when using --crf mode

Steve Borho steve at borho.org
Tue May 6 22:13:23 CEST 2014


On Tue, May 6, 2014 at 2:21 AM,  <gopu at multicorewareinc.com> wrote:
> # HG changeset patch
> # User Gopu Govindaswamy
> # Date 1399360773 -19800
> #      Tue May 06 12:49:33 2014 +0530
> # Node ID 4a78e823abdf875524ed07ac4485276160c52fb8
> # Parent  c4adcaef8d1d8d5f65841a42ef838594fa953185
> log: add the RateFactor for each frame to the .stats file when using --crf mode
>
> diff -r c4adcaef8d1d -r 4a78e823abdf source/Lib/TLibCommon/TComPic.h
> --- a/source/Lib/TLibCommon/TComPic.h   Mon May 05 00:22:50 2014 -0500
> +++ b/source/Lib/TLibCommon/TComPic.h   Tue May 06 12:49:33 2014 +0530
> @@ -116,6 +116,7 @@
>      double*               m_qpaRc;
>      double                m_avgQpRc; //avg QP as decided by ratecontrol
>      double                m_avgQpAq; //avg QP as decided by AQ in addition to ratecontrol
> +    double                m_rateFactor; //calculated based on the Frame QP
>
>      TComPic();
>      virtual ~TComPic();
> diff -r c4adcaef8d1d -r 4a78e823abdf source/encoder/encoder.cpp
> --- a/source/encoder/encoder.cpp        Mon May 05 00:22:50 2014 -0500
> +++ b/source/encoder/encoder.cpp        Tue May 06 12:49:33 2014 +0530
> @@ -124,7 +124,12 @@
>              if (m_csvfpt)
>              {
>                  if (param->logLevel >= X265_LOG_DEBUG)
> -                    fprintf(m_csvfpt, "Encode Order, Type, POC, QP, Bits, Y PSNR, U PSNR, V PSNR, YUV PSNR, SSIM, SSIM (dB), Encoding time, Elapsed time, List 0, List 1\n");
> +                {
> +                    if (param->rc.rateControlMode == X265_RC_CRF)
> +                        fprintf(m_csvfpt, "Encode Order, Type, POC, QP, Bits, RateFactor, Y PSNR, U PSNR, V PSNR, YUV PSNR, SSIM, SSIM (dB), Encoding time, Elapsed time, List 0, List 1\n");
> +                    else
> +                        fprintf(m_csvfpt, "Encode Order, Type, POC, QP, Bits, Y PSNR, U PSNR, V PSNR, YUV PSNR, SSIM, SSIM (dB), Encoding time, Elapsed time, List 0, List 1\n");

queued with this broken into three fprintf() statements to avoid
largely duplicate string constants

> +                }
>                  else
>                      fprintf(m_csvfpt, "Command, Date/Time, Elapsed Time, FPS, Bitrate, Y PSNR, U PSNR, V PSNR, Global PSNR, SSIM, SSIM (dB), Version\n");
>              }
> @@ -898,6 +903,8 @@
>          char buf[1024];
>          int p;
>          p = sprintf(buf, "POC:%d %c QP %2.2lf(%d) %10d bits", poc, c, pic->m_avgQpAq, slice->getSliceQp(), (int)bits);
> +        if (param->rc.rateControlMode == X265_RC_CRF)
> +            p += sprintf(buf + p, " RF:%f", pic->m_rateFactor);
>          if (param->bEnablePsnr)
>              p += sprintf(buf + p, " [Y:%6.2lf U:%6.2lf V:%6.2lf]", psnrY, psnrU, psnrV);
>          if (param->bEnableSsim)
> @@ -923,6 +930,8 @@
>          if (m_csvfpt)
>          {
>              fprintf(m_csvfpt, "%d, %c-SLICE, %4d, %2.2lf, %10d,", m_outputCount++, c, poc, pic->m_avgQpAq, (int)bits);
> +            if (param->rc.rateControlMode == X265_RC_CRF)
> +                fprintf(m_csvfpt, "%f,", pic->m_rateFactor);
>              double psnr = (psnrY * 6 + psnrU + psnrV) / 8;
>              if (param->bEnablePsnr)
>                  fprintf(m_csvfpt, "%.3lf, %.3lf, %.3lf, %.3lf,", psnrY, psnrU, psnrV, psnr);
> diff -r c4adcaef8d1d -r 4a78e823abdf source/encoder/ratecontrol.cpp
> --- a/source/encoder/ratecontrol.cpp    Mon May 05 00:22:50 2014 -0500
> +++ b/source/encoder/ratecontrol.cpp    Tue May 06 12:49:33 2014 +0530
> @@ -1008,6 +1008,19 @@
>          {
>              checkAndResetABR(rce, true);
>          }
> +        if (param->rc.rateControlMode == X265_RC_CRF)
> +        {
> +            if (int(pic->m_avgQpRc + 0.5) == pic->getSlice()->getSliceQp())
> +                pic->m_rateFactor = rateFactorConstant;
> +            else
> +            {
> +                /* If vbv changes the Frame QP then Recalculate the Ratefactor */
> +                double baseCplx = ncu * (param->bframes ? 120 : 80);
> +                double mbtree_offset = param->rc.cuTree ? (1.0 - param->rc.qCompress) * 13.5 : 0;
> +                pic->m_rateFactor = pow(baseCplx, 1 - qCompress) /
> +                    x265_qp2qScale(int(pic->m_avgQpRc + 0.5) + mbtree_offset);
> +            }
> +        }
>          if (!isAbrReset)
>          {
>              if (param->rc.aqMode || isVbv)
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel



-- 
Steve Borho


More information about the x265-devel mailing list