[x265] [PATCH 1 of 3] cli: add options to support complex-analysis

2017-01-26 Thread bhavna
# HG changeset patch
# User Bhavna Hariharan 
# Date 1485500436 -19800
#  Fri Jan 27 12:30:36 2017 +0530
# Node ID 09a7c884054aa74f7a3c09978fc8a766164d35dd
# Parent  d1f6d9b8d6be1fb44d7d1dad7dd642c7ae95b226
cli: add options to support complex-analysis

diff -r d1f6d9b8d6be -r 09a7c884054a doc/reST/cli.rst
--- a/doc/reST/cli.rst  Fri Jan 20 10:27:41 2017 +0530
+++ b/doc/reST/cli.rst  Fri Jan 27 12:30:36 2017 +0530
@@ -872,6 +872,7 @@
 .. option:: --limit-tu <0..4>
 
Enables early exit from TU depth recursion, for inter coded blocks.
+   
Level 1 - decides to recurse to next higher depth based on cost 
comparison of full size TU and split TU.

@@ -943,6 +944,15 @@
quad-tree begins at the same depth of the coded tree unit, but if the
maximum TU size is smaller than the CU size then transform QT begins 
at the depth of the max-tu-size. Default: 32.
+   
+.. option:: --complex-analysis <0..4>
+   
+   Increases the RD-level at points where the bitrate drops due to vbv. 
+   The number of CUs for which the RD is reconfigured is determined based
+   on the strength. Strength 1 gives the best FPS, strength 4 gives the 
+   best SSIM. Strength 0 switches this feature off. Default: 0.
+   
+   Effective for RD levels 4 and below.
 
 .. option:: --ssim-rd, --no-ssim-rd
 
diff -r d1f6d9b8d6be -r 09a7c884054a source/CMakeLists.txt
--- a/source/CMakeLists.txt Fri Jan 20 10:27:41 2017 +0530
+++ b/source/CMakeLists.txt Fri Jan 27 12:30:36 2017 +0530
@@ -29,7 +29,7 @@
 option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 107)
+set(X265_BUILD 108)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
"${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r d1f6d9b8d6be -r 09a7c884054a source/common/param.cpp
--- a/source/common/param.cpp   Fri Jan 20 10:27:41 2017 +0530
+++ b/source/common/param.cpp   Fri Jan 27 12:30:36 2017 +0530
@@ -178,6 +178,7 @@
 param->bEnableTemporalMvp = 1;
 param->bSourceReferenceEstimation = 0;
 param->limitTU = 0;
+param->complexAnalysis = 0;
 
 /* Loop Filter */
 param->bEnableLoopFilter = 1;
@@ -929,6 +930,7 @@
 OPT("multi-pass-opt-analysis") p->analysisMultiPassRefine = 
atobool(value);
 OPT("multi-pass-opt-distortion") p->analysisMultiPassDistortion = 
atobool(value);
 OPT("aq-motion") p->bAQMotion = atobool(value);
+OPT("complex-analysis") p->complexAnalysis = atof(value);
 OPT("ssim-rd")
 {
 int bval = atobool(value);
@@ -1167,6 +1169,8 @@
   "RD Level is out of range");
 CHECK(param->rdoqLevel < 0 || param->rdoqLevel > 2,
 "RDOQ Level is out of range");
+CHECK(param->complexAnalysis < 0 || param->complexAnalysis > 
X265_MAX_ANALYSIS_STRENGTH,
+"Complex analysis strength must be between 0 and 4");
 CHECK(param->bframes && param->bframes >= param->lookaheadDepth && 
!param->rc.bStatRead,
   "Lookahead depth must be greater than the max consecutive bframe 
count");
 CHECK(param->bframes < 0,
@@ -1412,6 +1416,7 @@
 TOOLOPT(param->bEnableAMP, "amp");
 TOOLOPT(param->limitModes, "limit-modes");
 TOOLVAL(param->rdLevel, "rd=%d");
+TOOLVAL(param->complexAnalysis, "complex-analysis=%.2f");
 TOOLVAL(param->psyRd, "psy-rd=%.2lf");
 TOOLVAL(param->rdoqLevel, "rdoq=%d");
 TOOLVAL(param->psyRdoq, "psy-rdoq=%.2lf");
@@ -1511,6 +1516,7 @@
 s += sprintf(s, " tu-intra-depth=%d", p->tuQTMaxIntraDepth);
 s += sprintf(s, " limit-tu=%d", p->limitTU);
 s += sprintf(s, " rdoq-level=%d", p->rdoqLevel);
+s += sprintf(s, " complex-analysis=%.2f", p->complexAnalysis);
 BOOL(p->bEnableSignHiding, "signhide");
 BOOL(p->bEnableTransformSkip, "tskip");
 s += sprintf(s, " nr-intra=%d", p->noiseReductionIntra);
diff -r d1f6d9b8d6be -r 09a7c884054a source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppFri Jan 20 10:27:41 2017 +0530
+++ b/source/encoder/encoder.cppFri Jan 27 12:30:36 2017 +0530
@@ -2157,6 +2157,12 @@
 else
 m_param->rc.qgSize = p->maxCUSize;
 
+if (m_param->complexAnalysis && (!bIsVbv || !p->rc.aqMode || p->rdLevel > 
4))
+{
+p->complexAnalysis = 0;
+x265_log(p, X265_LOG_WARNING, "Complex-analysis disabled, requires RD 
<= 4, VBV and aq-mode enabled\n");
+}
+
 if (p->uhdBluray)
 {
 p->bEnableAccessUnitDelimiters = 1;
diff -r d1f6d9b8d6be -r 09a7c884054a source/x265.h
--- a/source/x265.h Fri Jan 20 10:27:41 2017 +0530
+++ b/source/x265.h Fri Jan 27 12:30:36 2017 +0530
@@ -390,6 +390,8 @@
 #define X265_AQ_AUTO_VARIANCE2
 #define X265_AQ_AUTO_VARIANCE_BIASED 3
 
+#define X265_MAX_ANALYSIS_STRENGTH   4
+
 /* NO

Re: [x265] [PATCH 1 of 3] cli: add options to support complex-analysis

2017-01-26 Thread Pradeep Ramachandran
On Wed, Jan 25, 2017 at 6:55 PM,  wrote:

> # HG changeset patch
> # User Bhavna Hariharan 
> # Date 1485245762 -19800
> #  Tue Jan 24 13:46:02 2017 +0530
> # Node ID bdf2856cc3a1eafb9092bc52a2c2323b4fe92a95
> # Parent  3737c70c3308c980259d60410c4231c74e892d23
> cli: add options to support complex-analysis
>
> diff -r 3737c70c3308 -r bdf2856cc3a1 doc/reST/cli.rst
> --- a/doc/reST/cli.rst  Fri Jan 20 16:44:03 2017 +0530
> +++ b/doc/reST/cli.rst  Tue Jan 24 13:46:02 2017 +0530
> @@ -872,6 +872,7 @@
>  .. option:: --limit-tu <0..4>
>
> Enables early exit from TU depth recursion, for inter coded blocks.
> +
> Level 1 - decides to recurse to next higher depth based on cost
> comparison of full size TU and split TU.
>
> @@ -943,6 +944,15 @@
> quad-tree begins at the same depth of the coded tree unit, but if
> the
> maximum TU size is smaller than the CU size then transform QT
> begins
> at the depth of the max-tu-size. Default: 32.
> +
> +.. option:: --complex-analysis <0..4>
> +
> +   Increases the RD-level at points where the bitrate drops due to
> vbv.
> +   The number of CUs for which the RD is reconfigured is determined
> based
> +   on the strength. Strength 1 gives the best FPS, strength 4 gives
> the
> +   best SSIM. Strength 0 switches this feature off. Default: 0.
> +
> +   Effective for RD levels 4 and below.
>
>  .. option:: --ssim-rd, --no-ssim-rd
>
> diff -r 3737c70c3308 -r bdf2856cc3a1 source/CMakeLists.txt
> --- a/source/CMakeLists.txt Fri Jan 20 16:44:03 2017 +0530
> +++ b/source/CMakeLists.txt Tue Jan 24 13:46:02 2017 +0530
> @@ -29,7 +29,7 @@
>  option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)
>  mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
>  # X265_BUILD must be incremented each time the public API is changed
> -set(X265_BUILD 107)
> +set(X265_BUILD 108)
>  configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
> "${PROJECT_BINARY_DIR}/x265.def")
>  configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
> diff -r 3737c70c3308 -r bdf2856cc3a1 source/common/param.cpp
> --- a/source/common/param.cpp   Fri Jan 20 16:44:03 2017 +0530
> +++ b/source/common/param.cpp   Tue Jan 24 13:46:02 2017 +0530
> @@ -178,6 +178,7 @@
>  param->bEnableTemporalMvp = 1;
>  param->bSourceReferenceEstimation = 0;
>  param->limitTU = 0;
> +param->complexAnalysis = 0;
>
>  /* Loop Filter */
>  param->bEnableLoopFilter = 1;
> @@ -929,6 +930,7 @@
>  OPT("multi-pass-opt-analysis") p->analysisMultiPassRefine =
> atobool(value);
>  OPT("multi-pass-opt-distortion") p->analysisMultiPassDistortion
> = atobool(value);
>  OPT("aq-motion") p->bAQMotion = atobool(value);
> +OPT("complex-analysis") p->complexAnalysis = atof(value);
>  OPT("ssim-rd")
>  {
>  int bval = atobool(value);
> @@ -1167,6 +1169,8 @@
>"RD Level is out of range");
>  CHECK(param->rdoqLevel < 0 || param->rdoqLevel > 2,
>  "RDOQ Level is out of range");
> +CHECK(param->complexAnalysis < 0 || param->complexAnalysis > 4,
> +"Complex analysis strength must be between 0 and 4");
>  CHECK(param->bframes && param->bframes >= param->lookaheadDepth &&
> !param->rc.bStatRead,
>"Lookahead depth must be greater than the max consecutive
> bframe count");
>  CHECK(param->bframes < 0,
> @@ -1412,6 +1416,7 @@
>  TOOLOPT(param->bEnableAMP, "amp");
>  TOOLOPT(param->limitModes, "limit-modes");
>  TOOLVAL(param->rdLevel, "rd=%d");
> +TOOLVAL(param->complexAnalysis, "complex-analysis=%.2f");
>  TOOLVAL(param->psyRd, "psy-rd=%.2lf");
>  TOOLVAL(param->rdoqLevel, "rdoq=%d");
>  TOOLVAL(param->psyRdoq, "psy-rdoq=%.2lf");
> @@ -1511,6 +1516,7 @@
>  s += sprintf(s, " tu-intra-depth=%d", p->tuQTMaxIntraDepth);
>  s += sprintf(s, " limit-tu=%d", p->limitTU);
>  s += sprintf(s, " rdoq-level=%d", p->rdoqLevel);
> +s += sprintf(s, " complex-analysis=%.2f", p->complexAnalysis);
>  BOOL(p->bEnableSignHiding, "signhide");
>  BOOL(p->bEnableTransformSkip, "tskip");
>  s += sprintf(s, " nr-intra=%d", p->noiseReductionIntra);
> diff -r 3737c70c3308 -r bdf2856cc3a1 source/encoder/encoder.cpp
> --- a/source/encoder/encoder.cppFri Jan 20 16:44:03 2017 +0530
> +++ b/source/encoder/encoder.cppTue Jan 24 13:46:02 2017 +0530
> @@ -2157,6 +2157,12 @@
>  else
>  m_param->rc.qgSize = p->maxCUSize;
>
> +if (m_param->complexAnalysis && (!bIsVbv || !p->rc.aqMode ||
> p->rdLevel > 4))
> +{
> +p->complexAnalysis = 0;
> +x265_log(p, X265_LOG_WARNING, "Complex-analysis disabled,
> requires RD > 4, VBV and aq-mode enabled\n");
>

Doesn't complex-analysis require rd level <=4 to work? Your message seems
incorrect.


> +}
> +
>  if (p->uhdBluray)
>  {
>  p->bEnableAccessUnitDelimiters = 1;
> diff -r 3737c70c3308 -r bd

[x265] [PATCH 1 of 3] cli: add options to support complex-analysis

2017-01-25 Thread bhavna
# HG changeset patch
# User Bhavna Hariharan 
# Date 1485245762 -19800
#  Tue Jan 24 13:46:02 2017 +0530
# Node ID bdf2856cc3a1eafb9092bc52a2c2323b4fe92a95
# Parent  3737c70c3308c980259d60410c4231c74e892d23
cli: add options to support complex-analysis

diff -r 3737c70c3308 -r bdf2856cc3a1 doc/reST/cli.rst
--- a/doc/reST/cli.rst  Fri Jan 20 16:44:03 2017 +0530
+++ b/doc/reST/cli.rst  Tue Jan 24 13:46:02 2017 +0530
@@ -872,6 +872,7 @@
 .. option:: --limit-tu <0..4>
 
Enables early exit from TU depth recursion, for inter coded blocks.
+   
Level 1 - decides to recurse to next higher depth based on cost 
comparison of full size TU and split TU.

@@ -943,6 +944,15 @@
quad-tree begins at the same depth of the coded tree unit, but if the
maximum TU size is smaller than the CU size then transform QT begins 
at the depth of the max-tu-size. Default: 32.
+   
+.. option:: --complex-analysis <0..4>
+   
+   Increases the RD-level at points where the bitrate drops due to vbv. 
+   The number of CUs for which the RD is reconfigured is determined based
+   on the strength. Strength 1 gives the best FPS, strength 4 gives the 
+   best SSIM. Strength 0 switches this feature off. Default: 0.
+   
+   Effective for RD levels 4 and below.
 
 .. option:: --ssim-rd, --no-ssim-rd
 
diff -r 3737c70c3308 -r bdf2856cc3a1 source/CMakeLists.txt
--- a/source/CMakeLists.txt Fri Jan 20 16:44:03 2017 +0530
+++ b/source/CMakeLists.txt Tue Jan 24 13:46:02 2017 +0530
@@ -29,7 +29,7 @@
 option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 107)
+set(X265_BUILD 108)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
"${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 3737c70c3308 -r bdf2856cc3a1 source/common/param.cpp
--- a/source/common/param.cpp   Fri Jan 20 16:44:03 2017 +0530
+++ b/source/common/param.cpp   Tue Jan 24 13:46:02 2017 +0530
@@ -178,6 +178,7 @@
 param->bEnableTemporalMvp = 1;
 param->bSourceReferenceEstimation = 0;
 param->limitTU = 0;
+param->complexAnalysis = 0;
 
 /* Loop Filter */
 param->bEnableLoopFilter = 1;
@@ -929,6 +930,7 @@
 OPT("multi-pass-opt-analysis") p->analysisMultiPassRefine = 
atobool(value);
 OPT("multi-pass-opt-distortion") p->analysisMultiPassDistortion = 
atobool(value);
 OPT("aq-motion") p->bAQMotion = atobool(value);
+OPT("complex-analysis") p->complexAnalysis = atof(value);
 OPT("ssim-rd")
 {
 int bval = atobool(value);
@@ -1167,6 +1169,8 @@
   "RD Level is out of range");
 CHECK(param->rdoqLevel < 0 || param->rdoqLevel > 2,
 "RDOQ Level is out of range");
+CHECK(param->complexAnalysis < 0 || param->complexAnalysis > 4,
+"Complex analysis strength must be between 0 and 4");
 CHECK(param->bframes && param->bframes >= param->lookaheadDepth && 
!param->rc.bStatRead,
   "Lookahead depth must be greater than the max consecutive bframe 
count");
 CHECK(param->bframes < 0,
@@ -1412,6 +1416,7 @@
 TOOLOPT(param->bEnableAMP, "amp");
 TOOLOPT(param->limitModes, "limit-modes");
 TOOLVAL(param->rdLevel, "rd=%d");
+TOOLVAL(param->complexAnalysis, "complex-analysis=%.2f");
 TOOLVAL(param->psyRd, "psy-rd=%.2lf");
 TOOLVAL(param->rdoqLevel, "rdoq=%d");
 TOOLVAL(param->psyRdoq, "psy-rdoq=%.2lf");
@@ -1511,6 +1516,7 @@
 s += sprintf(s, " tu-intra-depth=%d", p->tuQTMaxIntraDepth);
 s += sprintf(s, " limit-tu=%d", p->limitTU);
 s += sprintf(s, " rdoq-level=%d", p->rdoqLevel);
+s += sprintf(s, " complex-analysis=%.2f", p->complexAnalysis);
 BOOL(p->bEnableSignHiding, "signhide");
 BOOL(p->bEnableTransformSkip, "tskip");
 s += sprintf(s, " nr-intra=%d", p->noiseReductionIntra);
diff -r 3737c70c3308 -r bdf2856cc3a1 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppFri Jan 20 16:44:03 2017 +0530
+++ b/source/encoder/encoder.cppTue Jan 24 13:46:02 2017 +0530
@@ -2157,6 +2157,12 @@
 else
 m_param->rc.qgSize = p->maxCUSize;
 
+if (m_param->complexAnalysis && (!bIsVbv || !p->rc.aqMode || p->rdLevel > 
4))
+{
+p->complexAnalysis = 0;
+x265_log(p, X265_LOG_WARNING, "Complex-analysis disabled, requires RD 
> 4, VBV and aq-mode enabled\n");
+}
+
 if (p->uhdBluray)
 {
 p->bEnableAccessUnitDelimiters = 1;
diff -r 3737c70c3308 -r bdf2856cc3a1 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppFri Jan 20 16:44:03 2017 +0530
+++ b/source/encoder/ratecontrol.cppTue Jan 24 13:46:02 2017 +0530
@@ -228,6 +228,11 @@
 x265_log(m_param, X265_LOG_WARNING, "VBV is incompatible with 
constant QP, ignored.\n");