[x265] [PATCH] level & tiers: fix

mahesh at multicorewareinc.com mahesh at multicorewareinc.com
Mon Apr 25 14:48:50 CEST 2016


# HG changeset patch
# User Mahesh Pittala <mahesh at multicorewareinc.com>
# Date 1461582611 -19800
#      Mon Apr 25 16:40:11 2016 +0530
# Node ID dfc3c2fefc9a0124ecd01967269e06c7abf4d4e5
# Parent  02d79be487d7f825c961d15535a8681a201da3b1
level & tiers: fix

1) uhd-bd: lower bitrate to level-5.1 high tier as per uhd-bd spec if user specifies
higher bitrate than level-5.1 high tier
2) if no tier specifed by user then set to main and set bitrate accordingly
3) enable warnings for levels and tiers when encoder changes
4) when sourceHeight is 1080, it is padded by some value to become multiple of the
minimum CU size(for ex- 1088) so just moved down those calculations after uhd-bd.

diff -r 02d79be487d7 -r dfc3c2fefc9a source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Sun Apr 17 21:07:28 2016 +0000
+++ b/source/encoder/encoder.cpp	Mon Apr 25 16:40:11 2016 +0530
@@ -1850,16 +1850,6 @@
         m_conformanceWindow.rightOffset = padsize;
     }
 
-    /* set pad size if height is not multiple of the minimum CU size */
-    if (p->sourceHeight & (p->minCUSize - 1))
-    {
-        uint32_t rem = p->sourceHeight & (p->minCUSize - 1);
-        uint32_t padsize = p->minCUSize - rem;
-        p->sourceHeight += padsize;
-
-        m_conformanceWindow.bEnabled = true;
-        m_conformanceWindow.bottomOffset = padsize;
-    }
     if (p->bDistributeModeAnalysis && p->analysisMode)
     {
         p->analysisMode = X265_ANALYSIS_OFF;
@@ -1890,10 +1880,17 @@
 
     if (p->uhdBluray)
     {
+        int disableUhdBd = 0;
         p->bEnableAccessUnitDelimiters = 1;
         p->vui.aspectRatioIdc = 1;
         p->bEmitHRDSEI = 1;
-        int disableUhdBd = 0;
+
+        if (p->levelIdc < 51 || p->levelIdc > 51) x265_log(p, X265_LOG_WARNING, "uhd-bd: level set to 5.1\n");
+        if (!p->bHighTier)
+        {
+            x265_log(p, X265_LOG_WARNING, "uhd-bd: enabling high tier\n");
+            p->bHighTier = 1;
+        }
         if (!p->bRepeatHeaders)
         {
             x265_log(p, X265_LOG_WARNING, "uhd-bd: Turning on repeat-headers\n");
@@ -1970,7 +1967,16 @@
             x265_log(p, X265_LOG_ERROR, "uhd-bd: Disabled\n");
         }
     }
+    /* set pad size if height is not multiple of the minimum CU size */
+    if (p->sourceHeight & (p->minCUSize - 1))
+    {
+        uint32_t rem = p->sourceHeight & (p->minCUSize - 1);
+        uint32_t padsize = p->minCUSize - rem;
+        p->sourceHeight += padsize;
 
+        m_conformanceWindow.bEnabled = true;
+        m_conformanceWindow.bottomOffset = padsize;
+    }
 
     if (p->bLogCuStats)
         x265_log(p, X265_LOG_WARNING, "--cu-stats option is now deprecated\n");
diff -r 02d79be487d7 -r dfc3c2fefc9a source/encoder/level.cpp
--- a/source/encoder/level.cpp	Sun Apr 17 21:07:28 2016 +0000
+++ b/source/encoder/level.cpp	Mon Apr 25 16:40:11 2016 +0530
@@ -209,7 +209,7 @@
         else
             vps.ptl.tierFlag = Level::MAIN;
 #undef CHECK_RANGE
-        if (param.uhdBluray || param.bHighTier)
+        if (param.bHighTier)
             vps.ptl.tierFlag = Level::HIGH;
         vps.ptl.levelIdc = levels[i].levelEnum;
         vps.ptl.minCrForLevel = levels[i].minCompressionRatio;
@@ -293,13 +293,16 @@
     vps.maxDecPicBuffering = X265_MIN(MAX_NUM_REF, X265_MAX(vps.numReorderPics + 2, (uint32_t)param.maxNumReferences) + 1);
 
     /* no level specified by user, just auto-detect from the configuration */
-    if (param.levelIdc <= 0)
+    if ((!param.uhdBluray) && param.levelIdc <= 0)
+    {
+        x265_log(&param, X265_LOG_INFO, "level is auto-detected from the configuration\n");
         return true;
+    }
 
     uint32_t level = 0;
-    while (levels[level].levelIdc != param.levelIdc && level + 1 < sizeof(levels) / sizeof(levels[0]))
+    while (levels[level].levelIdc != (param.uhdBluray ? 51 : param.levelIdc) && level + 1 < sizeof(levels) / sizeof(levels[0]))
         level++;
-    if (levels[level].levelIdc != param.levelIdc)
+    if (levels[level].levelIdc != (param.uhdBluray ? 51 : param.levelIdc))
     {
         x265_log(&param, X265_LOG_ERROR, "specified level %d does not exist\n", param.levelIdc);
         return false;
@@ -332,7 +335,6 @@
         x265_log(&param, X265_LOG_ERROR, "frame rate is out of range for specified level\n");
         return false;
     }
-
     if ((uint32_t)param.rc.vbvMaxBitrate > (highTier ? l.maxBitrateHigh : l.maxBitrateMain))
     {
         param.rc.vbvMaxBitrate = highTier ? l.maxBitrateHigh : l.maxBitrateMain;
@@ -349,8 +351,8 @@
     case X265_RC_ABR:
         if ((uint32_t)param.rc.bitrate > (highTier ? l.maxBitrateHigh : l.maxBitrateMain))
         {
-            param.rc.bitrate = l.maxBitrateHigh;
-            x265_log(&param, X265_LOG_WARNING, "lowering target bitrate to High tier limit of %dKbps\n", param.rc.bitrate);
+            param.rc.bitrate = highTier ? l.maxBitrateHigh : l.maxBitrateMain;
+            x265_log(&param, X265_LOG_WARNING, "lowering target bitrate to %s tier limit of %dKbps\n", (highTier ? "high" : "main"), param.rc.bitrate);
         }
         break;
 


More information about the x265-devel mailing list