[x265] [PATCH] add UHD bluray compatibility support

mahesh at multicorewareinc.com mahesh at multicorewareinc.com
Tue Feb 23 12:22:49 CET 2016


# HG changeset patch
# User Mahesh Pittala <mahesh at multicorewareinc.com>
# Date 1455872812 -19800
#      Fri Feb 19 14:36:52 2016 +0530
# Node ID 6b0255268b70f6adaff2a48d2178fd322cd6ec2a
# Parent  c2228fb8151ddce111a75fb1c02b25eca5a68604
add UHD bluray compatibility support

diff -r c2228fb8151d -r 6b0255268b70 source/common/param.cpp
--- a/source/common/param.cpp	Fri Feb 19 09:50:42 2016 +0530
+++ b/source/common/param.cpp	Fri Feb 19 14:36:52 2016 +0530
@@ -121,8 +121,8 @@
     /* Source specifications */
     param->internalBitDepth = X265_DEPTH;
     param->internalCsp = X265_CSP_I420;
-
     param->levelIdc = 0;
+    param->uhdBlurayCompat = 0;
     param->bHighTier = 0;
     param->interlaceMode = 0;
     param->bAnnexB = 1;
@@ -879,6 +879,7 @@
     OPT("max-cll") bError |= sscanf(value, "%hu,%hu", &p->maxCLL, &p->maxFALL) != 2;
     OPT("min-luma") p->minLuma = (uint16_t)atoi(value);
     OPT("max-luma") p->maxLuma = (uint16_t)atoi(value);
+    OPT("uhd-bluray-compat") p->uhdBlurayCompat = atobool(value);
     else
         return X265_PARAM_BAD_NAME;
 #undef OPT
@@ -1025,7 +1026,8 @@
 {
 #define CHECK(expr, msg) check_failed |= _confirm(param, expr, msg)
     int check_failed = 0; /* abort if there is a fatal configuration problem */
-
+    CHECK(param->uhdBlurayCompat == 1 && (X265_DEPTH != 10 || param->internalCsp != 1 || param->interlaceMode != 0),
+        "for bluray compatibility x265 bit depth, chroma subsample, source picture type must be 10, 4:2:0, progressive");
     CHECK(param->maxCUSize != 64 && param->maxCUSize != 32 && param->maxCUSize != 16,
           "max cu size must be 16, 32, or 64");
     if (check_failed == 1)
diff -r c2228fb8151d -r 6b0255268b70 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Fri Feb 19 09:50:42 2016 +0530
+++ b/source/encoder/encoder.cpp	Fri Feb 19 14:36:52 2016 +0530
@@ -1594,7 +1594,43 @@
 void Encoder::configure(x265_param *p)
 {
     this->m_param = p;
+    if (p->uhdBlurayCompat)
+    {
+        p->bEnableAccessUnitDelimiters = 1;
+        p->vui.aspectRatioIdc = 1;
+        p->bEmitHRDSEI = 1;
+        p->bRepeatHeaders = 1;
+        p->bIntraRefresh = 0;
+        p->keyframeMin = 1;
+        int fps = (int)round((double)p->fpsNum / p->fpsDenom);
+        if (p->keyframeMax > fps)
+        {
+            x265_log(p, X265_LOG_WARNING, "keyframeMax should be equal to fps of input video for UHD bluray compatibility, so keyframeMax setting to %d\n", fps);
+            p->keyframeMax = fps;
+        }
+        if (p->maxNumReferences > 6)
+        {
+            x265_log(p, X265_LOG_WARNING, "maxNumReferences should be lessthan or equal to 6 for UHD bluray compatibility, so maxNumReferences setting to %d\n", X265_MIN(6, p->maxNumReferences));
+            p->maxNumReferences = X265_MIN(6, p->maxNumReferences);
+        }
+        p->bEnableTemporalSubLayers = 0;
+        if (p->vui.colorPrimaries != 1 && p->vui.colorPrimaries != 9)
+            x265_log(p, X265_LOG_ERROR, "for ITR(BT.709) colour primaries set to 1(BT.709) for content type SDR and for ITR(BT.2020) set to 9(BT.2020) for content type SDR and HDR to support UHD bluray compatibility\n");
+        else if (p->vui.colorPrimaries == 9)
+        {
+            p->vui.bEnableChromaLocInfoPresentFlag = 1;
+            p->vui.chromaSampleLocTypeTopField = 2;
+            p->vui.chromaSampleLocTypeBottomField = 2;
+        }
+        if (p->vui.transferCharacteristics != 1 && p->vui.transferCharacteristics != 14 && p->vui.transferCharacteristics != 16)
+            x265_log(p, X265_LOG_ERROR, "for ITR(BT.709) transfer_characteristics set to 1 for content type SDR and for ITR(BT.2020) set to 14(16 for HDR) for content type SDR and HDR to support UHD bluray compatibility\n");
 
+        if (p->vui.matrixCoeffs != 1 && p->vui.matrixCoeffs != 9)
+            x265_log(p, X265_LOG_ERROR, "for ITR(BT.709) matrix_coeffs set to 1 for content type SDR and for ITR(BT.2020) set to 9 for content type SDR and HDR to support UHD bluray compatibility\n");
+
+        if ((p->sourceWidth != 1920 && p->sourceWidth != 3840) || (p->sourceHeight != 1080 && p->sourceHeight != 1088 && p->sourceHeight != 2160))
+            x265_log(p, X265_LOG_ERROR, "UHD bluray supported resolutions are 1920x1080, 1920x1088 and 3840x2160\n");
+    }
     if (p->keyframeMax < 0)
     {
         /* A negative max GOP size indicates the user wants only one I frame at
diff -r c2228fb8151d -r 6b0255268b70 source/encoder/level.cpp
--- a/source/encoder/level.cpp	Fri Feb 19 09:50:42 2016 +0530
+++ b/source/encoder/level.cpp	Fri Feb 19 14:36:52 2016 +0530
@@ -133,21 +133,31 @@
     }
     else for (i = 0; i < NumLevels; i++)
     {
-        if (lumaSamples > levels[i].maxLumaSamples)
+        if (param.uhdBlurayCompat && levels[i].levelIdc != 51)
+        {
             continue;
-        else if (samplesPerSec > levels[i].maxLumaSamplesPerSecond)
-            continue;
-        else if (bitrate > levels[i].maxBitrateMain && levels[i].maxBitrateHigh == MAX_UINT)
-            continue;
-        else if (bitrate > levels[i].maxBitrateHigh)
-            continue;
-        else if (param.sourceWidth > sqrt(levels[i].maxLumaSamples * 8.0f))
-            continue;
-        else if (param.sourceHeight > sqrt(levels[i].maxLumaSamples * 8.0f))
-            continue;
-
+        }
+        else if (!param.uhdBlurayCompat)
+        {
+            if (lumaSamples > levels[i].maxLumaSamples)
+                continue;
+            else if (samplesPerSec > levels[i].maxLumaSamplesPerSecond)
+                continue;
+            else if (bitrate > levels[i].maxBitrateMain && levels[i].maxBitrateHigh == MAX_UINT)
+                continue;
+            else if (bitrate > levels[i].maxBitrateHigh)
+                continue;
+            else if (param.sourceWidth > sqrt(levels[i].maxLumaSamples * 8.0f))
+                continue;
+            else if (param.sourceHeight > sqrt(levels[i].maxLumaSamples * 8.0f))
+                continue;
+            else if (param.levelIdc && param.levelIdc != levels[i].levelIdc)
+                continue;
+        }
         uint32_t maxDpbSize = MaxDpbPicBuf;
-        if (lumaSamples <= (levels[i].maxLumaSamples >> 2))
+        if (param.uhdBlurayCompat)
+            maxDpbSize = 6;
+        else if (lumaSamples <= (levels[i].maxLumaSamples >> 2))
             maxDpbSize = X265_MIN(4 * MaxDpbPicBuf, 16);
         else if (lumaSamples <= (levels[i].maxLumaSamples >> 1))
             maxDpbSize = X265_MIN(2 * MaxDpbPicBuf, 16);
@@ -199,7 +209,8 @@
         else
             vps.ptl.tierFlag = Level::MAIN;
 #undef CHECK_RANGE
-
+        if (param.uhdBlurayCompat || param.bHighTier)
+            vps.ptl.tierFlag = Level::HIGH;
         vps.ptl.levelIdc = levels[i].levelEnum;
         vps.ptl.minCrForLevel = levels[i].minCompressionRatio;
         vps.ptl.maxLumaSrForLevel = levels[i].maxLumaSamplesPerSecond;
diff -r c2228fb8151d -r 6b0255268b70 source/x265.h
--- a/source/x265.h	Fri Feb 19 09:50:42 2016 +0530
+++ b/source/x265.h	Fri Feb 19 14:36:52 2016 +0530
@@ -610,7 +610,8 @@
     /* if levelIdc is specified (non-zero) this flag will differentiate between
      * Main (0) and High (1) tier. Default is Main tier (0) */
     int       bHighTier;
-
+    /* Enable UHD Blu-ray compatibility support */
+    int       uhdBlurayCompat;
     /* The maximum number of L0 references a P or B slice may use. This
      * influences the size of the decoded picture buffer. The higher this
      * number, the more reference frames there will be available for motion
diff -r c2228fb8151d -r 6b0255268b70 source/x265cli.h
--- a/source/x265cli.h	Fri Feb 19 09:50:42 2016 +0530
+++ b/source/x265cli.h	Fri Feb 19 14:36:52 2016 +0530
@@ -53,6 +53,7 @@
     { "profile",        required_argument, NULL, 'P' },
     { "level-idc",      required_argument, NULL, 0 },
     { "high-tier",            no_argument, NULL, 0 },
+    { "uhd-bluray-compat",    no_argument, NULL, 0 },
     { "no-high-tier",         no_argument, NULL, 0 },
     { "allow-non-conformance",no_argument, NULL, 0 },
     { "no-allow-non-conformance",no_argument, NULL, 0 },
@@ -281,6 +282,7 @@
     H0("-P/--profile <string>            Enforce an encode profile: main, main10, mainstillpicture\n");
     H0("   --level-idc <integer|float>   Force a minimum required decoder level (as '5.0' or '50')\n");
     H0("   --[no-]high-tier              If a decoder level is specified, this modifier selects High tier of that level\n");
+    H0("   --[no-]uhd-bluray-compat      Enable UHD Bluray compatibility support\n");
     H0("   --[no-]allow-non-conformance  Allow the encoder to generate profile NONE bitstreams. Default %s\n", OPT(param->bAllowNonConformance));
     H0("\nThreading, performance:\n");
     H0("   --pools <integer,...>         Comma separated thread count per thread pool (pool per NUMA node)\n");


More information about the x265-devel mailing list