changeset 11996:f6fb77f466d4 draft

analysis: Introduce refine-intra level 4 refine-intra 4 does not reuse any analysis information from the save encode. Analysis is re-done for all I-frames and intra in inter blocks in the load run, this improves the quality of the subsequent inter frames.
author Bhavna Hariharan <bhavna@multicorewareinc.com>
date Tue, 27 Feb 2018 15:02:21 +0530
parents 580aa959f568
children 4c0d8a22625d
files doc/reST/cli.rst source/CMakeLists.txt source/common/param.cpp source/encoder/analysis.cpp source/x265cli.h
diffstat 5 files changed, 21 insertions(+-), 13 deletions(-) [+]
line wrap: on
line diff
--- a/doc/reST/cli.rst	Wed Feb 28 11:09:18 2018 +0530
+++ b/doc/reST/cli.rst	Tue Feb 27 15:02:21 2018 +0530
@@ -915,7 +915,7 @@ will not reuse analysis if slice type pa
        This option should be coupled with analysis-reuse-mode option, --analysis-reuse-level 10.
        The ctu size of load should be double the size of save. Default 0.
 
-.. option:: --refine-intra <0..3>
+.. option:: --refine-intra <0..4>
 	
 	Enables refinement of intra blocks in current encode. 
 	
@@ -931,6 +931,8 @@ will not reuse analysis if slice type pa
 	
 	Level 3 - Perform analysis of intra modes for depth reused from first encode.
 	
+	Level 4 - Does not reuse any analysis information - redo analysis for the intra block.
+	
 	Default 0.
 	
 .. option:: --refine-inter <0..3>
--- a/source/CMakeLists.txt	Wed Feb 28 11:09:18 2018 +0530
+++ b/source/CMakeLists.txt	Tue Feb 27 15:02:21 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 151)
+set(X265_BUILD 152)
 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	Wed Feb 28 11:09:18 2018 +0530
+++ b/source/common/param.cpp	Tue Feb 27 15:02:21 2018 +0530
@@ -1365,7 +1365,7 @@ int x265_check_params(x265_param* param)
         "Supported values for bCTUInfo are 0, 1, 2, 4, 6");
     CHECK(param->interRefine > 3 || param->interRefine < 0,
         "Invalid refine-inter value, refine-inter levels 0 to 3 supported");
-    CHECK(param->intraRefine > 3 || param->intraRefine < 0,
+    CHECK(param->intraRefine > 4 || param->intraRefine < 0,
         "Invalid refine-intra value, refine-intra levels 0 to 3 supported");
 #if !X86_64
     CHECK(param->searchMethod == X265_SEA && (param->sourceWidth > 840 || param->sourceHeight > 480),
--- a/source/encoder/analysis.cpp	Wed Feb 28 11:09:18 2018 +0530
+++ b/source/encoder/analysis.cpp	Tue Feb 27 15:02:21 2018 +0530
@@ -518,10 +518,10 @@ uint64_t Analysis::compressIntraCU(const
     bool mightSplit = !(cuGeom.flags & CUGeom::LEAF);
     bool mightNotSplit = !(cuGeom.flags & CUGeom::SPLIT_MANDATORY);
 
-    bool bAlreadyDecided = parentCTU.m_lumaIntraDir[cuGeom.absPartIdx] != (uint8_t)ALL_IDX;
-    bool bDecidedDepth = parentCTU.m_cuDepth[cuGeom.absPartIdx] == depth;
+    bool bAlreadyDecided = m_param->intraRefine != 4 && parentCTU.m_lumaIntraDir[cuGeom.absPartIdx] != (uint8_t)ALL_IDX;
+    bool bDecidedDepth = m_param->intraRefine != 4 && parentCTU.m_cuDepth[cuGeom.absPartIdx] == depth;
     int split = 0;
-    if (m_param->intraRefine)
+    if (m_param->intraRefine && m_param->intraRefine != 4)
     {
         split = ((cuGeom.log2CUSize == (uint32_t)(g_log2Size[m_param->minCUSize] + 1)) && bDecidedDepth);
         if (cuGeom.log2CUSize == (uint32_t)(g_log2Size[m_param->minCUSize]) && !bDecidedDepth)
@@ -2425,14 +2425,19 @@ void Analysis::recodeCU(const CUData& pa
         PartSize size = (PartSize)parentCTU.m_partSize[cuGeom.absPartIdx];
         if (parentCTU.isIntra(cuGeom.absPartIdx) && m_param->interRefine < 2)
         {
-            bool reuseModes = !((m_param->intraRefine == 3) ||
-                                (m_param->intraRefine == 2 && parentCTU.m_lumaIntraDir[cuGeom.absPartIdx] > DC_IDX));
-            if (reuseModes)
+            if (m_param->intraRefine == 4)
+                compressIntraCU(parentCTU, cuGeom, qp);
+            else
             {
-                memcpy(mode.cu.m_lumaIntraDir, parentCTU.m_lumaIntraDir + cuGeom.absPartIdx, cuGeom.numPartitions);
-                memcpy(mode.cu.m_chromaIntraDir, parentCTU.m_chromaIntraDir + cuGeom.absPartIdx, cuGeom.numPartitions);
+                bool reuseModes = !((m_param->intraRefine == 3) ||
+                    (m_param->intraRefine == 2 && parentCTU.m_lumaIntraDir[cuGeom.absPartIdx] > DC_IDX));
+                if (reuseModes)
+                {
+                    memcpy(mode.cu.m_lumaIntraDir, parentCTU.m_lumaIntraDir + cuGeom.absPartIdx, cuGeom.numPartitions);
+                    memcpy(mode.cu.m_chromaIntraDir, parentCTU.m_chromaIntraDir + cuGeom.absPartIdx, cuGeom.numPartitions);
+                }
+                checkIntra(mode, cuGeom, size);
             }
-            checkIntra(mode, cuGeom, size);
         }
         else if (!parentCTU.isIntra(cuGeom.absPartIdx) && m_param->interRefine < 2)
         {
--- a/source/x265cli.h	Wed Feb 28 11:09:18 2018 +0530
+++ b/source/x265cli.h	Tue Feb 27 15:02:21 2018 +0530
@@ -475,11 +475,12 @@ static void showHelp(x265_param *param)
     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);
     H0("   --refine-mv-type <string>     Reuse MV information received through API call. Supported option is avc. Default disabled - %d\n", param->bMVType);
     H0("   --scale-factor <int>          Specify factor by which input video is scaled down for analysis save mode. Default %d\n", param->scaleFactor);
-    H0("   --refine-intra <0..3>         Enable intra refinement for encode that uses analysis-load.\n"
+    H0("   --refine-intra <0..4>         Enable intra refinement for encode that uses analysis-load.\n"
         "                                    - 0 : Forces both mode and depth from the save encode.\n"
         "                                    - 1 : Functionality of (0) + evaluate all intra modes at min-cu-size's depth when current depth is one smaller than min-cu-size's depth.\n"
         "                                    - 2 : Functionality of (1) + irrespective of size evaluate all angular modes when the save encode decides the best mode as angular.\n"
         "                                    - 3 : Functionality of (1) + irrespective of size evaluate all intra modes.\n"
+        "                                    - 4 : Re-evaluate all intra blocks, does not reuse data from save encode.\n"
         "                                Default:%d\n", param->intraRefine);
     H0("   --refine-inter <0..3>         Enable inter refinement for encode that uses analysis-load.\n"
         "                                    - 0 : Forces both mode and depth from the save encode.\n"