changeset 12001:7be938c392b0 draft

dynamic-refine: add cli and param options to support dynamic refinement.
author Bhavna Hariharan <bhavna@multicorewareinc.com>
date Fri, 09 Mar 2018 09:44:53 +0530
parents b7c8bfabc808
children 5037a012d93e
files doc/reST/cli.rst source/CMakeLists.txt source/common/param.cpp source/encoder/encoder.cpp source/x265.h source/x265cli.h
diffstat 6 files changed, 34 insertions(+-), 2 deletions(-) [+]
line wrap: on
line diff
--- a/doc/reST/cli.rst	Thu Mar 08 15:38:14 2018 +0530
+++ b/doc/reST/cli.rst	Fri Mar 09 09:44:53 2018 +0530
@@ -955,6 +955,12 @@ will not reuse analysis if slice type pa
 	Level 3 - Perform analysis of inter modes while reusing depths from the save encode.
 	
 	Default 0.
+	
+.. option:: --dynamic-refine, --no-dynamic-refine
+
+	Dynamically switches :option:`--refine-inter` levels 0-3 based on the content and 
+	the encoder settings. It is recommended to use :option:`--refine-intra` 4 with dynamic 
+	refinement. Default disabled.
 
 .. option:: --refine-mv
 	
--- a/source/CMakeLists.txt	Thu Mar 08 15:38:14 2018 +0530
+++ b/source/CMakeLists.txt	Fri Mar 09 09:44:53 2018 +0530
@@ -29,7 +29,7 @@ option(NATIVE_BUILD "Target the build CP
 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 155)
+set(X265_BUILD 156)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
--- a/source/common/param.cpp	Thu Mar 08 15:38:14 2018 +0530
+++ b/source/common/param.cpp	Fri Mar 09 09:44:53 2018 +0530
@@ -289,6 +289,7 @@ void x265_param_default(x265_param* para
     param->scaleFactor = 0;
     param->intraRefine = 0;
     param->interRefine = 0;
+    param->bDynamicRefine = 0;
     param->mvRefine = 0;
     param->bUseAnalysisFile = 1;
     param->csvfpt = NULL;
@@ -1015,6 +1016,7 @@ int x265_param_parse(x265_param* p, cons
         OPT("analysis-load") p->analysisLoad = strdup(value);
         OPT("radl") p->radl = atoi(value);
         OPT("max-ausize-factor") p->maxAUSizeFactor = atof(value);
+        OPT("dynamic-refine") p->bDynamicRefine = atobool(value);
         else
             return X265_PARAM_BAD_NAME;
     }
@@ -1509,6 +1511,7 @@ void x265_print_params(x265_param* param
     TOOLVAL(param->bCTUInfo, "ctu-info=%d");
     if (param->bMVType == AVC_INFO)
         TOOLOPT(param->bMVType, "refine-mv-type=avc");
+    TOOLOPT(param->bDynamicRefine, "dynamic-refine");
     if (param->maxSlices > 1)
         TOOLVAL(param->maxSlices, "slices=%d");
     if (param->bEnableLoopFilter)
@@ -1747,6 +1750,7 @@ char *x265_param2string(x265_param* p, i
     s += sprintf(s, " refine-mv-type=%d", p->bMVType);
     s += sprintf(s, " copy-pic=%d", p->bCopyPicToFrame);
     s += sprintf(s, " max-ausize-factor=%.1f", p->maxAUSizeFactor);
+    BOOL(p->bDynamicRefine, "dynamic-refine");
 #undef BOOL
     return buf;
 }
--- a/source/encoder/encoder.cpp	Thu Mar 08 15:38:14 2018 +0530
+++ b/source/encoder/encoder.cpp	Fri Mar 09 09:44:53 2018 +0530
@@ -2688,7 +2688,21 @@ void Encoder::configure(x265_param *p)
         }
     }
 
-    if (p->limitTU && p->interRefine)
+    if (p->bDynamicRefine)
+    {
+        if (!p->analysisLoad || p->analysisReuseLevel < 10 || !p->scaleFactor)
+        {
+            x265_log(p, X265_LOG_WARNING, "Dynamic refinement requires analysis load, analysis-reuse-level 10, scale factor. Disabling dynamic refine.\n");
+            p->bDynamicRefine = 0;
+        }
+        if (p->interRefine)
+        {
+            x265_log(p, X265_LOG_WARNING, "Inter refine cannot be used with dynamic refine. Disabling refine-inter.\n");
+            p->interRefine = 0;
+        }
+    }
+
+    if (p->limitTU && (p->interRefine || p->bDynamicRefine))
     {
         x265_log(p, X265_LOG_WARNING, "Inter refinement does not support limitTU. Disabling limitTU.\n");
         p->limitTU = 0;
--- a/source/x265.h	Thu Mar 08 15:38:14 2018 +0530
+++ b/source/x265.h	Fri Mar 09 09:44:53 2018 +0530
@@ -466,6 +466,8 @@ typedef enum
 
 #define x265_ADAPT_RD_STRENGTH   4
 
+#define X265_REFINE_INTER_LEVELS 4
+
 /* NOTE! For this release only X265_CSP_I420 and X265_CSP_I444 are supported */
 
 /* Supported internal color space types (according to semantics of chroma_format_idc) */
@@ -1562,6 +1564,9 @@ typedef struct x265_param
     * at each IDR frame describing poc of the recovery point, exact matching flag
     * and broken link flag. Default is disabled. */
     int       bEmitIDRRecoverySEI;
+
+    /* Dynamically change refine-inter at block level*/
+    int       bDynamicRefine;
 } x265_param;
 
 /* x265_param_alloc:
--- a/source/x265cli.h	Thu Mar 08 15:38:14 2018 +0530
+++ b/source/x265cli.h	Fri Mar 09 09:44:53 2018 +0530
@@ -263,6 +263,8 @@ static const struct option long_options[
     { "scale-factor",   required_argument, NULL, 0 },
     { "refine-intra",   required_argument, NULL, 0 },
     { "refine-inter",   required_argument, NULL, 0 },
+    { "dynamic-refine",       no_argument, NULL, 0 },
+    { "no-dynamic-refine",    no_argument, NULL, 0 },
     { "strict-cbr",           no_argument, NULL, 0 },
     { "temporal-layers",      no_argument, NULL, 0 },
     { "no-temporal-layers",   no_argument, NULL, 0 },
@@ -492,6 +494,7 @@ static void showHelp(x265_param *param)
         "                                    - 2 : Functionality of (1) + irrespective of size restrict the modes evaluated when specific modes are decided as the best mode by the save encode.\n"
         "                                    - 3 : Functionality of (1) + irrespective of size evaluate all inter modes.\n"
         "                                Default:%d\n", param->interRefine);
+    H0("   --[no-]dynamic-refine         Dynamically changes refine-inter level for each CU. Default %s\n", OPT(param->bDynamicRefine));
     H0("   --[no-]refine-mv              Enable mv refinement for load mode. Default %s\n", OPT(param->mvRefine));
     H0("   --aq-mode <integer>           Mode for Adaptive Quantization - 0:none 1:uniform AQ 2:auto variance 3:auto variance with bias to dark scenes. Default %d\n", param->rc.aqMode);
     H0("   --aq-strength <float>         Reduces blocking and blurring in flat and textured areas (0 to 3.0). Default %.2f\n", param->rc.aqStrength);