[x265] [PATCH 1 of 2] cli: remove tune cbr and introduce strict-cbr as a param option instead

Steve Borho steve at borho.org
Thu Jan 8 15:30:53 CET 2015


On 01/07, aarthi at multicorewareinc.com wrote:
> # HG changeset patch
> # User Aarthi Thirumalai
> # Date 1419332550 -19800
> #      Tue Dec 23 16:32:30 2014 +0530
> # Node ID 9b30c4b16dfc4c673b57ee4c567fa8956a41e2fc
> # Parent  32ed3f21039a5b93a54da8961442825e4db69d88
> cli: remove tune cbr and introduce strict-cbr as a param option instead
> 
> strict-cbr can be enabled in CBR mode, enforces stricter checks for bitrate adhearance and
> lesser tolerance for bitrate deviance from the target.
> 
> diff -r 32ed3f21039a -r 9b30c4b16dfc doc/reST/cli.rst
> --- a/doc/reST/cli.rst	Mon Dec 29 13:49:02 2014 +0530
> +++ b/doc/reST/cli.rst	Tue Dec 23 16:32:30 2014 +0530
> @@ -209,7 +209,7 @@
>  	be applied after :option:`--preset` but before all other parameters. Default none.
>  	See :ref:`tunings <tunings>` for more detail.
>  
> -	**Values:** psnr, ssim, grain, zero-latency, fast-decode, cbr.
> +	**Values:** psnr, ssim, grain, zero-latency, fast-decode.

preset.rst also needs updating, as well as cli help for --tune. this can
be a follow-up patch

>  Input/Output File Options
>  =========================
> @@ -992,6 +992,12 @@
>  	* :option:`--subme` = MIN(2, :option:`--subme`)
>  	* :option:`--rd` = MIN(2, :option:`--rd`)
>  
> +.. option:: --strict-cbr, --no-strict-cbr
> +	
> +	Enables stricter conditions to control bitrate
> +	deviance from the target in CBR mode. Bitrate adhearance is prioritised
> +	over quality. Rate tolerance is set to 50%. Default disabled
> +	
>  .. option:: --cbqpoffs <integer>
>  
>  	Offset of Cb chroma QP from the luma QP selected by rate control.
> diff -r 32ed3f21039a -r 9b30c4b16dfc source/CMakeLists.txt
> --- a/source/CMakeLists.txt	Mon Dec 29 13:49:02 2014 +0530
> +++ b/source/CMakeLists.txt	Tue Dec 23 16:32:30 2014 +0530
> @@ -21,7 +21,7 @@
>  include(CheckCXXCompilerFlag)
>  
>  # X265_BUILD must be incremented each time the public API is changed
> -set(X265_BUILD 40)
> +set(X265_BUILD 41)
>  configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
>                 "${PROJECT_BINARY_DIR}/x265.def")
>  configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
> diff -r 32ed3f21039a -r 9b30c4b16dfc source/common/param.cpp
> --- a/source/common/param.cpp	Mon Dec 29 13:49:02 2014 +0530
> +++ b/source/common/param.cpp	Tue Dec 23 16:32:30 2014 +0530
> @@ -206,6 +206,7 @@
>      param->rc.complexityBlur = 20;
>      param->rc.qblur = 0.5;
>      param->rc.bEnableSlowFirstPass = 0;
> +    param->rc.bStrictCbr = 0;
>  
>      /* Video Usability Information (VUI) */
>      param->vui.aspectRatioIdc = 0;
> @@ -421,11 +422,6 @@
>              param->rc.aqStrength = 0.3;
>              param->rc.qCompress = 0.8;
>          }
> -        else if (!strcmp(tune, "cbr"))
> -        {
> -            param->rc.pbFactor = 1.0;
> -            param->rc.rateTolerance = 0.5;
> -        }
>          else
>              return -1;
>      }
> @@ -699,6 +695,12 @@
>      OPT("me")        p->searchMethod = parseName(value, x265_motion_est_names, bError);
>      OPT("cutree")    p->rc.cuTree = atobool(value);
>      OPT("slow-firstpass") p->rc.bEnableSlowFirstPass = atobool(value);
> +    OPT("strict-cbr")
> +    {
> +        p->rc.bStrictCbr = atobool(value);
> +        p->rc.pbFactor = 1.0;
> +        p->rc.rateTolerance = 0.5;
> +    }
>      OPT("analysis-mode") p->analysisMode = parseName(value, x265_analysis_names, bError);
>      OPT("sar")
>      {
> @@ -1087,6 +1089,8 @@
>            "Constant rate-factor is incompatible with 2pass");
>      CHECK(param->rc.rateControlMode == X265_RC_CQP && param->rc.bStatRead,
>            "Constant QP is incompatible with 2pass");
> +    CHECK(param->rc.bStrictCbr && (param->rc.bitrate <= 0 || param->rc.vbvBufferSize <=0),
> +          "Strict-cbr cannot be applied without specifying target bitrate or vbv bufsize");
>      return check_failed;
>  }
>  
> diff -r 32ed3f21039a -r 9b30c4b16dfc source/encoder/ratecontrol.cpp
> --- a/source/encoder/ratecontrol.cpp	Mon Dec 29 13:49:02 2014 +0530
> +++ b/source/encoder/ratecontrol.cpp	Tue Dec 23 16:32:30 2014 +0530
> @@ -324,10 +324,6 @@
>      m_numEntries = 0;
>      m_amortizeFraction = 0.85;
>      m_amortizeFrames = 75;
> -    if (m_param->totalFrames <= 2 * m_fps)
> -    {
> -        m_amortizeFraction = m_amortizeFrames = 0;
> -    }
>      if (m_param->rc.rateControlMode == X265_RC_CRF)
>      {
>          m_param->rc.qp = (int)m_param->rc.rfConstant;
> @@ -396,6 +392,11 @@
>              x265_log(m_param, X265_LOG_WARNING, "max bitrate less than average bitrate, assuming CBR\n");
>              m_param->rc.bitrate = m_param->rc.vbvMaxBitrate;
>          }
> +        if (m_param->rc.bStrictCbr && m_param->rc.vbvMaxBitrate != m_param->rc.bitrate)
> +        {
> +            x265_log(m_param, X265_LOG_WARNING, "strict CBR set without CBR mode, ignored\n");
> +            m_param->rc.bStrictCbr = 0;
> +        }
>      }
>      else if (m_param->rc.vbvMaxBitrate)
>      {
> @@ -408,7 +409,11 @@
>          x265_log(m_param, X265_LOG_WARNING, "NAL HRD parameters require VBV parameters, ignored\n");
>          m_param->bEmitHRDSEI = 0;
>      }
> -
> +    if (m_param->totalFrames <= 2 * m_fps && m_param->rc.bStrictCbr)
> +    {
> +        m_amortizeFraction = 0;
> +        m_amortizeFrames = 0;
> +    }
>      m_isCbr = m_param->rc.rateControlMode == X265_RC_ABR && m_isVbv && !m_2pass && m_param->rc.vbvMaxBitrate <= m_param->rc.bitrate;
>      m_leadingBframes = m_param->bframes;
>      m_bframeBits = 0;
> diff -r 32ed3f21039a -r 9b30c4b16dfc source/x265.cpp
> --- a/source/x265.cpp	Mon Dec 29 13:49:02 2014 +0530
> +++ b/source/x265.cpp	Tue Dec 23 16:32:30 2014 +0530
> @@ -217,6 +217,7 @@
>      { "no-slow-firstpass",    no_argument, NULL, 0 },
>      { "analysis-mode",  required_argument, NULL, 0 },
>      { "analysis-file",  required_argument, NULL, 0 },
> +    { "strict-cbr",           no_argument, NULL, 0 },
>      { 0, 0, 0, 0 }
>  };
>  
> @@ -457,6 +458,7 @@
>         "                                   - 3 : Nth pass, overwrites stats file\n");
>      H0("   --stats                       Filename for stats file in multipass pass rate control. Default x265_2pass.log\n");
>      H0("   --[no-]slow-firstpass         Enable a slow first pass in a multipass rate control mode. Default %s\n", OPT(param->rc.bEnableSlowFirstPass));
> +    H0("   --[no-]strict-cbr             Enable stricter conditions and tolerance for bitrate deviations in CBR mode. Default %s\n", OPT(param->rc.bStrictCbr));
>      H0("   --analysis-mode <string|int>  save - Dump analysis info into file, load - Load analysis buffers from the file. Default %d\n", param->analysisMode);
>      H0("   --analysis-file <filename>    Specify file name used for either dumping or reading analysis data.\n");
>      H0("   --aq-mode <integer>           Mode for Adaptive Quantization - 0:none 1:uniform AQ 2:auto variance. Default %d\n", param->rc.aqMode);
> diff -r 32ed3f21039a -r 9b30c4b16dfc source/x265.h
> --- a/source/x265.h	Mon Dec 29 13:49:02 2014 +0530
> +++ b/source/x265.h	Tue Dec 23 16:32:30 2014 +0530
> @@ -875,6 +875,10 @@
>           * ignored. The lambda tables are process-global, so these new lambda
>           * values will affect all encoders in the same process */
>          const char* lambdaFileName;
> +
> +        /* Enable stricter conditions to check bitrate deviations in CBR mode. May compromise 
> +           quality to maintain bitrate adhearance */
> +        int bStrictCbr;
>      } rc;
>  
>      /*== Video Usability Information ==*/
> @@ -1032,7 +1036,7 @@
>   *      100 times faster than placebo!
>   *
>   *      Currently available tunings are: */
> -static const char * const x265_tune_names[] = { "psnr", "ssim", "grain", "zerolatency", "fastdecode", "cbr", 0 };
> +static const char * const x265_tune_names[] = { "psnr", "ssim", "grain", "zerolatency", "fastdecode", 0 };
>  
>  /*      returns 0 on success, negative on failure (e.g. invalid preset/tune name). */
>  int x265_param_default_preset(x265_param *, const char *preset, const char *tune);
> _______________________________________________
> 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