<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 9, 2017 at 6:11 PM,  <span dir="ltr"><<a href="mailto:bhavna@multicorewareinc.com" target="_blank">bhavna@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""># HG changeset patch<br>
# User Bhavna Hariharan <<a href="mailto:bhavna@multicorewareinc.com">bhavna@multicorewareinc.com</a>><br>
# Date 1500881283 -19800<br>
#      Mon Jul 24 12:58:03 2017 +0530<br>
</span># Node ID 81f17d9c7c273e4b282be66bf8bcd1<wbr>93e25a1d2e<br>
<span class=""># Parent  d11482e5fedbcdaf62ee3c6872f438<wbr>27d99ad181<br>
Introduce refine-inter levels 2 and 3<br></span></blockquote><div><br></div><div>Pushed both patches to default branch</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
<br>
</span>refine-inter 2 limits the modes evaluated in the encode that uses<br>
--analysis-reuse-mode load.<br>
2nx2n in save encode - disable re-evaluation of rect and amp<br>
skip in save encode  - re-evaluates only skip, merge and 2nx2n modes<br>
<br>
refine-inter 3 will force only the depth from the encode that uses<br>
--analysis-reuse-mode=save and re-evaluates all the modes in the<br>
encode that uses --analysis-reuse-mode=load.<br>
<br>
diff -r d11482e5fedb -r 81f17d9c7c27 doc/reST/cli.rst<br>
<span class="">--- a/doc/reST/cli.rst  Mon Jul 24 11:15:38 2017 +0530<br>
+++ b/doc/reST/cli.rst  Mon Jul 24 12:58:03 2017 +0530<br>
</span>@@ -897,24 +897,38 @@<br>
<br>
        Enables refinement of intra blocks in current encode.<br>
<br>
-       Level 0 - Forces both mode and depth from the previous encode.<br>
+       Level 0 - Forces both mode and depth from the save encode.<br>
<br>
-       Level 1 - Evaluates all intra modes for blocks of size one smaller than<br>
-       the min-cu-size of the incoming analysis data from the previous encode,<br>
-       forces modes for blocks of larger size.<br>
+       Level 1 - Evaluates all intra modes at current depth(n) and at depth<br>
+       (n+1) when current block size is one greater than the min-cu-size.<br>
+       Forces modes for larger blocks.<br>
<br>
-       Level 2 - Evaluates all intra modes for blocks of size one smaller than<br>
-       the min-cu-size of the incoming analysis data from the previous encode.<br>
-       For larger blocks, force only depth when angular mode is chosen by the<br>
-       previous encode, force depth and mode when other intra modes are chosen.<br>
+       Level 2 - In addition to the functionality of level 1, at all depths, force<br>
+       (a) only depth when angular mode is chosen by the save encode.<br>
+       (b) depth and mode when other intra modes are chosen by the save encode.<br>
<span class=""><br>
        Default 0.<br>
<br>
-.. option:: --refine-inter-depth<br>
-<br>
-       Enables refinement of inter blocks in current encode. Evaluates all<br>
-       inter modes for blocks of size one smaller than the min-cu-size of the<br>
-       incoming analysis data from the previous encode. Default disabled.<br>
+.. option:: --refine-inter <0..3><br>
+<br>
+       Enables refinement of inter blocks in current encode.<br>
+<br>
</span>+       Level 0 - Forces both mode and depth from the save encode.<br>
+<br>
+       Level 1 - Evaluates all inter modes at current depth(n) and at depth<br>
+       (n+1) when current block size is one greater than the min-cu-size.<br>
+       Forces modes for larger blocks.<br>
+<br>
+       Level 2 - In addition to the functionality of level 1, restricts the modes<br>
+       evaluated when specific modes are decided as the best mode by the save encode.<br>
+<br>
+       2nx2n in save encode - disable re-evaluation of rect and amp.<br>
+<br>
+       skip in save encode  - re-evaluates only skip, merge and 2nx2n modes.<br>
+<br>
+       Level 3 - Perform analysis of inter modes while reusing depths from the save encode.<br>
<span class="">+<br>
+       Default 0.<br>
<br>
 .. option:: --refine-mv<br>
<br>
</span>diff -r d11482e5fedb -r 81f17d9c7c27 source/CMakeLists.txt<br>
<span class="">--- a/source/CMakeLists.txt     Mon Jul 24 11:15:38 2017 +0530<br>
+++ b/source/CMakeLists.txt     Mon Jul 24 12:58:03 2017 +0530<br>
@@ -29,7 +29,7 @@<br>
 option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)<br>
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)<br>
 # X265_BUILD must be incremented each time the public API is changed<br>
-set(X265_BUILD 131)<br>
+set(X265_BUILD 132)<br>
 configure_file("${PROJECT_<wbr>SOURCE_DIR}/<a href="http://x265.def.in" rel="noreferrer" target="_blank">x265.def.in</a>"<br>
                "${PROJECT_BINARY_DIR}/x265.<wbr>def")<br>
 configure_file("${PROJECT_<wbr>SOURCE_DIR}/<a href="http://x265_config.h.in" rel="noreferrer" target="_blank">x265_config.h.in</a>"<br>
</span>diff -r d11482e5fedb -r 81f17d9c7c27 source/common/param.cpp<br>
<span class="">--- a/source/common/param.cpp   Mon Jul 24 11:15:38 2017 +0530<br>
+++ b/source/common/param.cpp   Mon Jul 24 12:58:03 2017 +0530<br>
@@ -972,7 +972,7 @@<br>
         OPT("ctu-info") p->bCTUInfo = atoi(value);<br>
         OPT("scale-factor") p->scaleFactor = atoi(value);<br>
         OPT("refine-intra")p-><wbr>intraRefine = atoi(value);<br>
-        OPT("refine-inter")p-><wbr>interRefine = atobool(value);<br>
+        OPT("refine-inter")p-><wbr>interRefine = atoi(value);<br>
         OPT("refine-mv")p->mvRefine = atobool(value);<br>
         OPT("force-flush")p-><wbr>forceFlush = atoi(value);<br>
         else<br>
@@ -1318,6 +1318,10 @@<br>
         "Supported range for log2MaxPocLsb is 4 to 16");<br>
     CHECK(param->bCTUInfo < 0 || (param->bCTUInfo != 0 && param->bCTUInfo != 1 && param->bCTUInfo != 2 && param->bCTUInfo != 4 && param->bCTUInfo != 6) || param->bCTUInfo > 6,<br>
         "Supported values for bCTUInfo are 0, 1, 2, 4, 6");<br>
+    CHECK(param->interRefine > 3 || param->interRefine < 0,<br>
+        "Invalid refine-inter value, refine-inter levels 0 to 3 supported");<br>
+    CHECK(param->intraRefine > 2 || param->intraRefine < 0,<br>
+        "Invalid refine-intra value, refine-intra levels 0 to 2 supported");<br>
 #if !X86_64<br>
     CHECK(param->searchMethod == X265_SEA && (param->sourceWidth > 840 || param->sourceHeight > 480),<br>
         "SEA motion search does not support resolutions greater than 480p in 32 bit build");<br>
</span>diff -r d11482e5fedb -r 81f17d9c7c27 source/encoder/analysis.cpp<br>
<span class="">--- a/source/encoder/analysis.cpp       Mon Jul 24 11:15:38 2017 +0530<br>
+++ b/source/encoder/analysis.cpp       Mon Jul 24 12:58:03 2017 +0530<br>
</span>@@ -1131,10 +1131,18 @@<br>
<span class="">     bool chooseMerge = false;<br>
     bool bCtuInfoCheck = false;<br>
     int sameContentRef = 0;<br>
-<br>
-    if (m_evaluateInter == 1)<br>
+    bool checkRefineInter = false;<br>
+<br>
+    if (m_evaluateInter)<br>
     {<br>
-        skipRectAmp = !!md.bestMode;<br>
</span>+        if (m_param->interRefine == 2)<br>
<span class="">+        {<br>
+            checkRefineInter = true;<br>
+            if (parentCTU.m_predMode[cuGeom.<wbr>absPartIdx] == MODE_SKIP)<br>
+                skipModes = true;<br>
+            if (parentCTU.m_partSize[cuGeom.<wbr>absPartIdx] == SIZE_2Nx2N)<br>
+                skipRectAmp = true;<br>
+        }<br>
         mightSplit &= false;<br>
</span>         minDepth = depth;<br>
     }<br>
@@ -1252,7 +1260,8 @@<br>
<span class="">         md.pred[PRED_SKIP].cu.<wbr>initSubCU(parentCTU, cuGeom, qp);<br>
         checkMerge2Nx2N_rd0_4(md.pred[<wbr>PRED_SKIP], md.pred[PRED_MERGE], cuGeom);<br>
         if (m_param->rdLevel)<br>
-            skipModes = m_param->bEnableEarlySkip && md.bestMode && md.bestMode->cu.isSkipped(0); // TODO: sa8d threshold per depth<br>
+            skipModes = (m_param->bEnableEarlySkip || checkRefineInter)<br>
+                        && md.bestMode && md.bestMode->cu.isSkipped(0); // TODO: sa8d threshold per depth<br>
     }<br>
<br>
     if (md.bestMode && m_param->bEnableRecursionSkip && !bCtuInfoCheck)<br>
</span>@@ -1511,7 +1520,7 @@<br>
                     }<br>
                 }<br>
             }<br>
-            bool bTryIntra = (m_slice->m_sliceType != B_SLICE || m_param->bIntraInBFrames) && cuGeom.log2CUSize != MAX_LOG2_CU_SIZE && !((m_param->bCTUInfo & 4) && bCtuInfoCheck);<br>
+            bool bTryIntra = (m_slice->m_sliceType != B_SLICE || m_param->bIntraInBFrames) && cuGeom.log2CUSize != MAX_LOG2_CU_SIZE && !((m_param->bCTUInfo & 4) && bCtuInfoCheck) && !checkRefineInter;<br>
             if (m_param->rdLevel >= 3)<br>
             {<br>
                 /* Calculate RD cost of best inter option */<br>
@@ -1756,10 +1765,18 @@<br>
<span class="">     bool skipRectAmp = false;<br>
     bool bCtuInfoCheck = false;<br>
     int sameContentRef = 0;<br>
-<br>
-    if (m_evaluateInter == 1)<br>
+    bool checkRefineInter = false;<br>
+<br>
+    if (m_evaluateInter)<br>
     {<br>
-        skipRectAmp = !!md.bestMode;<br>
</span>+        if (m_param->interRefine == 2)<br>
<span class="">+        {<br>
+            checkRefineInter = true;<br>
+            if (parentCTU.m_predMode[cuGeom.<wbr>absPartIdx] == MODE_SKIP)<br>
+                skipModes = true;<br>
+            if (parentCTU.m_partSize[cuGeom.<wbr>absPartIdx] == SIZE_2Nx2N)<br>
+                skipRectAmp = true;<br>
+        }<br>
         mightSplit &= false;<br>
     }<br>
<br>
</span>@@ -1883,7 +1900,8 @@<br>
<span class="">         md.pred[PRED_SKIP].cu.<wbr>initSubCU(parentCTU, cuGeom, qp);<br>
         md.pred[PRED_MERGE].cu.<wbr>initSubCU(parentCTU, cuGeom, qp);<br>
         checkMerge2Nx2N_rd5_6(md.pred[<wbr>PRED_SKIP], md.pred[PRED_MERGE], cuGeom);<br>
-        skipModes = m_param->bEnableEarlySkip && md.bestMode && !md.bestMode->cu.getQtRootCbf(<wbr>0);<br>
+        skipModes = (m_param->bEnableEarlySkip || checkRefineInter) &&<br>
+                    md.bestMode && !md.bestMode->cu.getQtRootCbf(<wbr>0);<br>
         refMasks[0] = allSplitRefs;<br>
         md.pred[PRED_2Nx2N].cu.<wbr>initSubCU(parentCTU, cuGeom, qp);<br>
         checkInter_rd5_6(md.pred[PRED_<wbr>2Nx2N], cuGeom, SIZE_2Nx2N, refMasks);<br>
</span>@@ -2135,7 +2153,7 @@<br>
<span class="">                 }<br>
             }<br>
<br>
-            if ((m_slice->m_sliceType != B_SLICE || m_param->bIntraInBFrames) && (cuGeom.log2CUSize != MAX_LOG2_CU_SIZE) && !((m_param->bCTUInfo & 4) && bCtuInfoCheck))<br>
+            if ((m_slice->m_sliceType != B_SLICE || m_param->bIntraInBFrames) && (cuGeom.log2CUSize != MAX_LOG2_CU_SIZE) && !((m_param->bCTUInfo & 4) && bCtuInfoCheck) && !checkRefineInter)<br>
             {<br>
                 if (!m_param->limitReferences || splitIntra)<br>
                 {<br>
</span>@@ -2260,7 +2278,7 @@<br>
<span class="">             }<br>
             checkIntra(mode, cuGeom, size);<br>
         }<br>
-        else<br>
+        else if (m_param->interRefine < 2)<br>
         {<br>
             mode.cu.copyFromPic(parentCTU, cuGeom, m_csp, false);<br>
             uint32_t numPU = parentCTU.getNumPartInter(<wbr>cuGeom.absPartIdx);<br>
</span>@@ -2328,16 +2346,19 @@<br>
<div><div class="h5">                 checkDQP(mode, cuGeom);<br>
         }<br>
<br>
-        if (m_bTryLossless)<br>
-            tryLossless(cuGeom);<br>
-<br>
-        if (mightSplit)<br>
-            addSplitFlagCost(*md.bestMode, cuGeom.depth);<br>
-<br>
-        if (mightSplit && m_param->rdLevel < 5)<br>
-            checkDQPForSplitPred(*md.<wbr>bestMode, cuGeom);<br>
-<br>
-        if (m_param->interRefine && parentCTU.m_predMode[cuGeom.<wbr>absPartIdx] == MODE_SKIP  && !mode.cu.isSkipped(0))<br>
+        if (m_param->interRefine < 2 || parentCTU.isIntra(cuGeom.<wbr>absPartIdx))<br>
+        {<br>
+            if (m_bTryLossless)<br>
+                tryLossless(cuGeom);<br>
+<br>
+            if (mightSplit)<br>
+                addSplitFlagCost(*md.bestMode, cuGeom.depth);<br>
+<br>
+            if (mightSplit && m_param->rdLevel < 5)<br>
+                checkDQPForSplitPred(*md.<wbr>bestMode, cuGeom);<br>
+        }<br>
+<br>
+        if (!parentCTU.isIntra(cuGeom.<wbr>absPartIdx) && ( m_param->interRefine > 1 || (m_param->interRefine && parentCTU.m_predMode[cuGeom.<wbr>absPartIdx] == MODE_SKIP  && !mode.cu.isSkipped(0))))<br>
         {<br>
             m_evaluateInter = 1;<br>
             m_param->rdLevel > 4 ? compressInterCU_rd5_6(<wbr>parentCTU, cuGeom, qp) : compressInterCU_rd0_4(<wbr>parentCTU, cuGeom, qp);<br>
</div></div>diff -r d11482e5fedb -r 81f17d9c7c27 source/encoder/encoder.cpp<br>
<span class="">--- a/source/encoder/encoder.cpp        Mon Jul 24 11:15:38 2017 +0530<br>
+++ b/source/encoder/encoder.cpp        Mon Jul 24 12:58:03 2017 +0530<br>
@@ -2349,6 +2349,11 @@<br>
             x265_log(p, X265_LOG_WARNING, "MV refinement requires analysis load, analysis-reuse-level 10, scale factor. Disabling MV refine.\n");<br>
             p->mvRefine = 0;<br>
         }<br>
+        else if (p->interRefine >= 2)<br>
+        {<br>
</span>+            x265_log(p, X265_LOG_WARNING, "MVs are recomputed when refine-inter >= 2. MV refinement not applicable. Disabling MV refine\n");<br>
<span class="">+            p->mvRefine = 0;<br>
+        }<br>
     }<br>
<br>
     if ((p->analysisMultiPassRefine || p-><wbr>analysisMultiPassDistortion) && (p->bDistributeModeAnalysis || p-><wbr>bDistributeMotionEstimation))<br>
</span>diff -r d11482e5fedb -r 81f17d9c7c27 source/x265cli.h<br>
<span class="">--- a/source/x265cli.h  Mon Jul 24 11:15:38 2017 +0530<br>
+++ b/source/x265cli.h  Mon Jul 24 12:58:03 2017 +0530<br>
@@ -255,8 +255,7 @@<br>
     { "analysis-reuse-level", required_argument, NULL, 0 },<br>
     { "scale-factor",   required_argument, NULL, 0 },<br>
     { "refine-intra",   required_argument, NULL, 0 },<br>
-    { "refine-inter",   no_argument, NULL, 0 },<br>
-    { "no-refine-inter",no_argument, NULL, 0 },<br>
+    { "refine-inter",   required_argument, NULL, 0 },<br>
     { "strict-cbr",           no_argument, NULL, 0 },<br>
     { "temporal-layers",      no_argument, NULL, 0 },<br>
     { "no-temporal-layers",   no_argument, NULL, 0 },<br>
</span>@@ -454,8 +453,17 @@<br>
     H0("   --analysis-reuse-file <filename>    Specify file name used for either dumping or reading analysis data. Deault x265_analysis.dat\n");<br>
<span class="">     H0("   --analysis-reuse-level <1..10>      Level of analysis reuse indicates amount of info stored/reused in save/load mode, 1:least..10:most. Default %d\n", param->analysisReuseLevel);<br>
     H0("   --scale-factor <int>          Specify factor by which input video is scaled down for analysis save mode. Default %d\n", param->scaleFactor);<br>
</span>-    H0("   --refine-intra <int>          Enable intra refinement for load mode. Default %d\n", param->intraRefine);<br>
<span class="">-    H0("   --[no-]refine-inter           Enable inter refinement for load mode. Default %s\n", OPT(param->interRefine));<br>
</span>+    H0("   --refine-intra <0..2>         Enable intra refinement for encode that uses analysis-reuse-mode=load.\n"<br>
+        "                                    - 0 : Forces both mode and depth from the save encode.\n"<br>
+        "                                    - 1 : Evaluates all intra modes when current block size is one greater than the min-cu-size.\n"<br>
+        "                                    - 2 : In addition to level 1 functionality, force only depth when angular mode is chosen by the save encode.\n"<br>
+        "                                Default:%d\n", param->intraRefine);<br>
+    H0("   --refine-inter <0..3>         Enable inter refinement for encode that uses analysis-reuse-mode=load.\n"<br>
+        "                                    - 0 : Forces both mode and depth from the save encode.\n"<br>
+        "                                    - 1 : Evaluates all inter modes when current block is a skip and block size is one greater than the min-cu-size.\n"<br>
+        "                                    - 2 : In addition to level 1 functionality, restricts the modes evaluated when specific modes are decided as the best mode by the save encode.\n"<br>
+        "                                    - 3 : Perform analysis of inter modes while reusing depths from the previous encode.\n"<br>
+        "                                Default:%d\n", param->interRefine);<br>
<div class="HOEnZb"><div class="h5">     H0("   --[no-]refine-mv              Enable mv refinement for load mode. Default %s\n", OPT(param->mvRefine));<br>
     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);<br>
     H0("   --aq-strength <float>         Reduces blocking and blurring in flat and textured areas (0 to 3.0). Default %.2f\n", param->rc.aqStrength);<br>
</div></div><br>______________________________<wbr>_________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/<wbr>listinfo/x265-devel</a><br>
<br></blockquote></div><br></div></div>