[x265] [PATCH] rc: add slow first pass as a cli. set turbo(faster) first pass as default in 2 pass

Steve Borho steve at borho.org
Fri Aug 1 18:11:12 CEST 2014


On 08/01, aarthi at multicorewareinc.com wrote:
> # HG changeset patch
> # User Aarthi Thirumalai
> # Date 1406899062 -19800
> #      Fri Aug 01 18:47:42 2014 +0530
> # Node ID fc35093c609f35efab5f62cad43e5567a6127735
> # Parent  1e6f57c1d2fae37f1bbb813c0a01091195117e98
> rc: add slow first pass as a cli. set turbo(faster) first pass as default in 2 pass.
> 
> diff -r 1e6f57c1d2fa -r fc35093c609f source/CMakeLists.txt
> --- a/source/CMakeLists.txt	Fri Aug 01 18:45:57 2014 +0530
> +++ b/source/CMakeLists.txt	Fri Aug 01 18:47:42 2014 +0530
> @@ -19,7 +19,7 @@
>  include(CheckCXXCompilerFlag)
>  
>  # X265_BUILD must be incremented each time the public API is changed
> -set(X265_BUILD 29)
> +set(X265_BUILD 30)
>  configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
>                 "${PROJECT_BINARY_DIR}/x265.def")
>  configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
> diff -r 1e6f57c1d2fa -r fc35093c609f source/common/param.cpp
> --- a/source/common/param.cpp	Fri Aug 01 18:45:57 2014 +0530
> +++ b/source/common/param.cpp	Fri Aug 01 18:47:42 2014 +0530
> @@ -191,6 +191,7 @@
>      param->rc.statFileName = NULL;
>      param->rc.complexityBlur = 20;
>      param->rc.qblur = 0.5;
> +    param->rc.bEnableSlowFirstPass = 0;
>  
>      /* Quality Measurement Metrics */
>      param->bEnablePsnr = 0;
> @@ -351,6 +352,7 @@
>              param->searchMethod = X265_STAR_SEARCH;
>              param->bEnableTransformSkip = 1;
>              param->maxNumReferences = 5;
> +            param->rc.bEnableSlowFirstPass = 1;
>              // TODO: optimized esa
>          }
>          else
> @@ -640,6 +642,7 @@
>      OPT("input-csp") p->internalCsp = parseName(value, x265_source_csp_names, bError);
>      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("sar")
>      {
>          p->vui.aspectRatioIdc = parseName(value, x265_sar_names, bError);
> @@ -1020,6 +1023,21 @@
>      return check_failed;
>  }

for this feature to work for tools other than our own CLI; we must
either expose x265_param_apply_fastfirstpass() as a public API in x265.h
and export it from the library (x265.def). And in which case this flag
in x265_param is unnecessary; it can be handled with a CLIOption
variable like bDither or bForceY4m

*or*

x265_param_apply_fastfirstpass() needs to be called within
x265_encoder_open() prior to encoder->configure() and not from x265.cpp
This gives API users less flexibility in over-riding the fast-first-pass
settings; but it also simplifies the feature.

> +void x265_param_apply_fastfirstpass(x265_param* param)
> +{
> +    /* Set faster options in case of turbo firstpass. */
> +    if (param->rc.bStatWrite && !param->rc.bStatRead)
> +    {
> +        param->maxNumReferences = 1;
> +        param-> bEnableRectInter = 0;
> +        param->bEnableAMP = 0;
> +        param->searchMethod = X265_DIA_SEARCH;
> +        param->subpelRefine = X265_MIN(2, param->subpelRefine);
> +        param->bEnableEarlySkip = 1;
> +    }
> +

white-space nit

> +}
> +
>  int x265_set_globals(x265_param *param)
>  {
>      uint32_t maxCUDepth = (uint32_t)g_convertToBit[param->maxCUSize];
> diff -r 1e6f57c1d2fa -r fc35093c609f source/common/param.h
> --- a/source/common/param.h	Fri Aug 01 18:45:57 2014 +0530
> +++ b/source/common/param.h	Fri Aug 01 18:47:42 2014 +0530
> @@ -34,6 +34,7 @@
>  void  setParamAspectRatio(x265_param *p, int width, int height);
>  void  getParamAspectRatio(x265_param *p, int& width, int& height);
>  bool  parseLambdaFile(x265_param *param);
> +void x265_param_apply_fastfirstpass(x265_param *p);
>  
>  /* this table is kept internal to avoid confusion, since log level indices start at -1 */
>  static const char * const logLevelNames[] = { "none", "error", "warning", "info", "debug", "full", 0 };
> diff -r 1e6f57c1d2fa -r fc35093c609f source/x265.cpp
> --- a/source/x265.cpp	Fri Aug 01 18:45:57 2014 +0530
> +++ b/source/x265.cpp	Fri Aug 01 18:47:42 2014 +0530
> @@ -198,6 +198,7 @@
>      { "nr",             required_argument, NULL, 0 },
>      { "stats",          required_argument, NULL, 0 },
>      { "pass",           required_argument, NULL, 0 },
> +    { "slow-firstpass", no_argument, NULL,0 },

you have to include the no-slow-firstpass option here too
alignment nits

>      { 0, 0, 0, 0 }
>  };
>  
> @@ -426,6 +427,7 @@
>         "                                   - 1 : First pass, cretes stats file\n"
>         "                                   - 2 : Last pass, does not overwrite stats file\n"
>         "                                   - 3 : Nth pass, overwrites stats file\n");
> +    H0("   --[no-]slow-firstpass         Enable a slow first pass in a multipass rate control mode. Default %s\n", OPT(param->rc.bEnableSlowFirstPass));
>      H0("   --scaling-list <string>       Specify a file containing HM style quant scaling lists or 'default' or 'off'. Default: off\n");
>      H0("   --lambda-file <string>        Specify a file containing replacement values for the lambda tables\n");
>      H0("                                 MAX_MAX_QP+1 floats for lambda table, then again for lambda2 table\n");
> @@ -719,7 +721,8 @@
>          x265_log(NULL, X265_LOG_ERROR, "failed to open bitstream file <%s> for writing\n", bitstreamfn);
>          return true;
>      }
> -
> +    if (!param->rc.bEnableSlowFirstPass)
> +        x265_param_apply_fastfirstpass(param);
>      return false;
>  }
>  
> diff -r 1e6f57c1d2fa -r fc35093c609f source/x265.h
> --- a/source/x265.h	Fri Aug 01 18:45:57 2014 +0530
> +++ b/source/x265.h	Fri Aug 01 18:47:42 2014 +0530
> @@ -798,6 +798,9 @@
>          /* temporally blur complexity */
>          double    complexityBlur;
>  
> +        /* Enable slow and a more detailed first pass encode in  multi pass rate control */

extra space in comment

> +        int       bEnableSlowFirstPass;
> +
>          /* specify a text file which contains MAX_MAX_QP + 1 floating point
>           * values to be copied into x265_lambda_tab and a second set of
>           * MAX_MAX_QP + 1 floating point values for x265_lambda2_tab. All values

the new CLI option / param needs documentation in docs/reST/cli.rst

-- 
Steve Borho


More information about the x265-devel mailing list