[x265] [PATCH] Add CLI option for simplifying colorimetry parameters

Niranjan Bala niranjan at multicorewareinc.com
Thu Mar 4 13:05:09 UTC 2021


>From 4e0c7904f3f53861250fba406dd19603b16ca15e Mon Sep 17 00:00:00 2001
From: Niranjan <niranjan at multicorewareinc.com>
Date: Fri, 5 Feb 2021 00:24:30 +0530
Subject: [PATCH] Add CLI option for simplifying colorimetry parameters

The CLI option covers commonly used combinations of color primaries,
transfer characteristics, color matrix, range of luma and chroma signals,
and chroma sample location
---
 doc/reST/cli.rst                 | 71 ++++++++++++++++++++++++
 source/CMakeLists.txt            |  2 +-
 source/common/param.cpp          |  7 +++
 source/encoder/encoder.cpp       | 95 ++++++++++++++++++++++++++++++++
 source/encoder/encoder.h         |  2 +
 source/test/regression-tests.txt |  1 +
 source/x265.h                    |  4 ++
 source/x265cli.cpp               | 22 ++++++++
 source/x265cli.h                 |  1 +
 9 files changed, 204 insertions(+), 1 deletion(-)

diff --git a/doc/reST/cli.rst b/doc/reST/cli.rst
index f19a28734..0f5a37e1d 100755
--- a/doc/reST/cli.rst
+++ b/doc/reST/cli.rst
@@ -2386,6 +2386,77 @@ VUI fields must be manually specified.
  Values in the range 0..12. See D.3.3 of the HEVC spec. for a detailed
explanation.
  Required for HLG (Hybrid Log Gamma) signaling. Not signaled by default.

+.. option:: --video-signal-type-preset <string>
+
+ Specify combinations of color primaries, transfer characteristics, color
matrix,
+ range of luma and chroma signals, and chroma sample location.
+ String format: <system-id>[:<color-volume>]
+
+ system-id options and their corresponding values:
+
+----------------+---------------------------------------------------------------+
+ | system-id      | Value
        |
+
+================+===============================================================+
+ | BT601_525      | --colorprim smpte170m --transfer smpte170m
       |
+ |                | --colormatrix smpte170m --range limited --chromaloc 0
        |
+
+----------------+---------------------------------------------------------------+
+ | BT601_626      | --colorprim bt470bg --transfer smpte170m --colormatrix
bt470bg|
+ |                | --range limited --chromaloc 0
        |
+
+----------------+---------------------------------------------------------------+
+ | BT709_YCC      | --colorprim bt709 --transfer bt709 --colormatrix bt709
       |
+ |                | --range limited --chromaloc 0
        |
+
+----------------+---------------------------------------------------------------+
+ | BT709_RGB      | --colorprim bt709 --transfer bt709 --colormatrix gbr
       |
+ |                | --range limited
        |
+
+----------------+---------------------------------------------------------------+
+ | BT2020_YCC_NCL | --colorprim bt2020 --transfer bt2020-10 --colormatrix
bt709   |
+ |                | --range limited --chromaloc 2
        |
+
+----------------+---------------------------------------------------------------+
+ | BT2020_RGB     | --colorprim bt2020 --transfer smpte2084 --colormatrix
bt2020nc|
+ |                | --range limited
        |
+
+----------------+---------------------------------------------------------------+
+ | BT2100_PQ_YCC  | --colorprim bt2020 --transfer smpte2084 --colormatrix
bt2020nc|
+ |                | --range limited --chromaloc 2
        |
+
+----------------+---------------------------------------------------------------+
+ | BT2100_PQ_ICTCP| --colorprim bt2020 --transfer smpte2084 --colormatrix
ictcp   |
+ |                | --range limited --chromaloc 2
        |
+
+----------------+---------------------------------------------------------------+
+ | BT2100_PQ_RGB  | --colorprim bt2020 --transfer smpte2084 --colormatrix
gbr     |
+ |                | --range limited
        |
+
+----------------+---------------------------------------------------------------+
+ | BT2100_HLG_YCC | --colorprim bt2020 --transfer arib-std-b67
       |
+ |                | --colormatrix bt2020nc --range limited --chromaloc 2
       |
+
+----------------+---------------------------------------------------------------+
+ | BT2100_HLG_RGB | --colorprim bt2020 --transfer arib-std-b67
--colormatrix gbr  |
+ |                | --range limited
        |
+
+----------------+---------------------------------------------------------------+
+ | FR709_RGB      | --colorprim bt709 --transfer bt709 --colormatrix gbr
       |
+ |                | --range full
       |
+
+----------------+---------------------------------------------------------------+
+ | FR2020_RGB     | --colorprim bt2020 --transfer bt2020-10 --colormatrix
gbr     |
+ |                | --range full
       |
+
+----------------+---------------------------------------------------------------+
+ | FRP3D65_YCC    | --colorprim smpte432 --transfer bt709 --colormatrix
smpte170m |
+ |                | --range full --chromaloc 1
       |
+
+----------------+---------------------------------------------------------------+
+
+ color-volume options and their corresponding values:
+
+----------------+---------------------------------------------------------------+
+ | color-volume   | Value
        |
+
+================+===============================================================+
+ | P3D65x1000n0005| --master-display
G(13250,34500)B(7500,3000)R(34000,16000)     |
+ |                |                  WP(15635,16450)L(10000000,5)
        |
+
+----------------+---------------------------------------------------------------+
+ | P3D65x4000n005 | --master-display
G(13250,34500)B(7500,3000)R(34000,16000)     |
+ |                |                  WP(15635,16450)L(40000000,50)
       |
+
+----------------+---------------------------------------------------------------+
+ | BT2100x108n0005| --master-display
G(8500,39850)B(6550,2300)R(34000,146000)     |
+ |                |                  WP(15635,16450)L(10000000,1)
        |
+
+----------------+---------------------------------------------------------------+
+
+ Note: The color-volume options can be used only with the system-id
options BT2100_PQ_YCC,
+       BT2100_PQ_ICTCP, and BT2100_PQ_RGB. It is incompatible with other
options.
+
+
 Bitstream options
 =================

diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index 95218f5dc..a407271b4 100755
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -29,7 +29,7 @@ option(NATIVE_BUILD "Target the build CPU" OFF)
 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 198)
+set(X265_BUILD 199)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff --git a/source/common/param.cpp b/source/common/param.cpp
index 47a7a7c47..90b80c8a4 100755
--- a/source/common/param.cpp
+++ b/source/common/param.cpp
@@ -318,6 +318,7 @@ void x265_param_default(x265_param* param)
     param->maxLuma = PIXEL_MAX;
     param->log2MaxPocLsb = 8;
     param->maxSlices = 1;
+    param->videoSignalTypePreset = NULL;

     /*Conformance window*/
     param->confWinRightOffset = 0;
@@ -1381,6 +1382,7 @@ int x265_param_parse(x265_param* p, const char* name,
const char* value)
         OPT("vbv-live-multi-pass") p->bliveVBV2pass = atobool(value);
         OPT("min-vbv-fullness") p->minVbvFullness = atof(value);
         OPT("max-vbv-fullness") p->maxVbvFullness = atof(value);
+        OPT("video-signal-type-preset") p->videoSignalTypePreset =
strdup(value);
         else
             return X265_PARAM_BAD_NAME;
     }
@@ -2015,6 +2017,8 @@ char *x265_param2string(x265_param* p, int padx, int
pady)
         bufSize += strlen(p->numaPools);
     if (p->masteringDisplayColorVolume)
         bufSize += strlen(p->masteringDisplayColorVolume);
+    if (p->videoSignalTypePreset)
+        bufSize += strlen(p->videoSignalTypePreset);

     buf = s = X265_MALLOC(char, bufSize);
     if (!buf)
@@ -2616,6 +2620,9 @@ void x265_copy_params(x265_param* dst, x265_param*
src)
     dst->confWinRightOffset = src->confWinRightOffset;
     dst->confWinBottomOffset = src->confWinBottomOffset;
     dst->bliveVBV2pass = src->bliveVBV2pass;
+
+    if (src->videoSignalTypePreset) dst->videoSignalTypePreset =
strdup(src->videoSignalTypePreset);
+    else dst->videoSignalTypePreset = NULL;
 #ifdef SVT_HEVC
     memcpy(dst->svtHevcParam, src->svtHevcParam,
sizeof(EB_H265_ENC_CONFIGURATION));
 #endif
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
index 1f710e1ce..1dd247124 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -74,6 +74,38 @@ DolbyVisionProfileSpec dovi[] =
     { 1, 1, 1, 1, 1, 5, 0, 16, 9, 9, 81 },
     { 1, 1, 1, 1, 1, 5, 0,  1, 1, 1, 82 }
 };
+
+typedef struct
+{
+    int bEnableVideoSignalTypePresentFlag;
+    int bEnableColorDescriptionPresentFlag;
+    int bEnableChromaLocInfoPresentFlag;
+    int colorPrimaries;
+    int transferCharacteristics;
+    int matrixCoeffs;
+    int bEnableVideoFullRangeFlag;
+    int chromaSampleLocTypeTopField;
+    int chromaSampleLocTypeBottomField;
+    const char* systemId;
+}VideoSignalTypePresets;
+
+VideoSignalTypePresets vstPresets[] =
+{
+    {1, 1, 1, 6, 6, 6, 0, 0, 0, "BT601_525"},
+    {1, 1, 1, 5, 6, 5, 0, 0, 0, "BT601_626"},
+    {1, 1, 1, 1, 1, 1, 0, 0, 0, "BT709_YCC"},
+    {1, 1, 0, 1, 1, 0, 0, 0, 0, "BT709_RGB"},
+    {1, 1, 1, 9, 14, 1, 0, 2, 2, "BT2020_YCC_NCL"},
+    {1, 1, 0, 9, 16, 9, 0, 0, 0, "BT2020_RGB"},
+    {1, 1, 1, 9, 16, 9, 0, 2, 2, "BT2100_PQ_YCC"},
+    {1, 1, 1, 9, 16, 14, 0, 2, 2, "BT2100_PQ_ICTCP"},
+    {1, 1, 0, 9, 16, 0, 0, 0, 0, "BT2100_PQ_RGB"},
+    {1, 1, 1, 9, 18, 9, 0, 2, 2, "BT2100_HLG_YCC"},
+    {1, 1, 0, 9, 18, 0, 0, 0, 0, "BT2100_HLG_RGB"},
+    {1, 1, 0, 1, 1, 0, 1, 0, 0, "FR709_RGB"},
+    {1, 1, 0, 9, 14, 0, 1, 0, 0, "FR2020_RGB"},
+    {1, 1, 1, 12, 1, 6, 1, 1, 1, "FRP3D65_YCC"}
+};
 }

 /* Threshold for motion vection, based on expermental result.
@@ -982,6 +1014,7 @@ void Encoder::destroy()
         free((char*)m_param->toneMapFile);
         free((char*)m_param->analysisSave);
         free((char*)m_param->analysisLoad);
+        free((char*)m_param->videoSignalTypePreset);
         PARAM_NS::x265_param_free(m_param);
     }
 }
@@ -3548,6 +3581,65 @@ void Encoder::configureDolbyVisionParams(x265_param*
p)
         p->crQpOffset = 3;
 }

+void Encoder::configureVideoSignalTypePreset(x265_param* p)
+{
+    char systemId[20] = {};
+    char colorVolume[20] = {};
+    sscanf(p->videoSignalTypePreset, "%[^:]:%s", systemId, colorVolume);
+    uint32_t sysId = 0;
+    while (strcmp(vstPresets[sysId].systemId, systemId))
+    {
+        if (sysId + 1 == sizeof(vstPresets) / sizeof(vstPresets[0]))
+        {
+            x265_log(NULL, X265_LOG_ERROR, "Incorrect system-id,
aborting\n");
+            m_aborted = true;
+            break;
+        }
+        sysId++;
+    }
+
+    p->vui.bEnableVideoSignalTypePresentFlag =
vstPresets[sysId].bEnableVideoSignalTypePresentFlag;
+    p->vui.bEnableColorDescriptionPresentFlag =
vstPresets[sysId].bEnableColorDescriptionPresentFlag;
+    p->vui.bEnableChromaLocInfoPresentFlag =
vstPresets[sysId].bEnableChromaLocInfoPresentFlag;
+    p->vui.colorPrimaries = vstPresets[sysId].colorPrimaries;
+    p->vui.transferCharacteristics =
vstPresets[sysId].transferCharacteristics;
+    p->vui.matrixCoeffs = vstPresets[sysId].matrixCoeffs;
+    p->vui.bEnableVideoFullRangeFlag =
vstPresets[sysId].bEnableVideoFullRangeFlag;
+    p->vui.chromaSampleLocTypeTopField =
vstPresets[sysId].chromaSampleLocTypeTopField;
+    p->vui.chromaSampleLocTypeBottomField =
vstPresets[sysId].chromaSampleLocTypeBottomField;
+
+    if (colorVolume[0] != '\0')
+    {
+        if (!strcmp(systemId, "BT2100_PQ_YCC") || !strcmp(systemId,
"BT2100_PQ_ICTCP") || !strcmp(systemId, "BT2100_PQ_RGB"))
+        {
+            p->bEmitHDR10SEI = 1;
+            if (!strcmp(colorVolume, "P3D65x1000n0005"))
+            {
+                p->masteringDisplayColorVolume =
strdup("G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,5)");
+            }
+            else if (!strcmp(colorVolume, "P3D65x4000n005"))
+            {
+                p->masteringDisplayColorVolume =
strdup("G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(40000000,50)");
+            }
+            else if (!strcmp(colorVolume, "BT2100x108n0005"))
+            {
+                p->masteringDisplayColorVolume =
strdup("G(8500,39850)B(6550,2300)R(34000,146000)WP(15635,16450)L(10000000,1)");
+            }
+            else
+            {
+                x265_log(NULL, X265_LOG_ERROR, "Incorrect color-volume,
aborting\n");
+                m_aborted = true;
+            }
+        }
+        else
+        {
+            x265_log(NULL, X265_LOG_ERROR, "Color-volume is not supported
with the given system-id, aborting\n");
+            m_aborted = true;
+        }
+    }
+
+}
+
 void Encoder::configure(x265_param *p)
 {
     this->m_param = p;
@@ -4243,6 +4335,9 @@ void Encoder::configure(x265_param *p)
         }
     }

+    if (p->videoSignalTypePreset)     // Default disabled.
+        configureVideoSignalTypePreset(p);
+
     if (m_param->toneMapFile || p->bHDR10Opt || p->bEmitHDR10SEI)
     {
         if (!p->bRepeatHeaders)
diff --git a/source/encoder/encoder.h b/source/encoder/encoder.h
index ecb6e153f..22a886ef4 100644
--- a/source/encoder/encoder.h
+++ b/source/encoder/encoder.h
@@ -387,6 +387,8 @@ public:

     void configureDolbyVisionParams(x265_param* p);

+    void configureVideoSignalTypePreset(x265_param* p);
+
 protected:

     void initVPS(VPS *vps);
diff --git a/source/test/regression-tests.txt
b/source/test/regression-tests.txt
index 26f6b7ed3..a4fcab87f 100644
--- a/source/test/regression-tests.txt
+++ b/source/test/regression-tests.txt
@@ -165,6 +165,7 @@ crowd_run_1920x1080_50.yuv, --preset faster --ctu 32
--rskip 2 --rskip-edge-thre
 crowd_run_1920x1080_50.yuv, --preset fast --ctu 64 --rskip 2
--rskip-edge-threshold 5 --aq-mode 4
 crowd_run_1920x1080_50.yuv, --preset slow --ctu 32 --rskip 2
--rskip-edge-threshold 5 --hist-scenecut --hist-threshold 0.1
 crowd_run_1920x1080_50.yuv, --preset slower --ctu 16 --rskip 2
--rskip-edge-threshold 5 --hist-scenecut --hist-threshold 0.1 --aq-mode 4
+crowd_run_1920x1080_50.yuv, --preset ultrafast --video-signal-type-preset
BT2100_PQ_YCC:BT2100x108n0005

 # Main12 intraCost overflow bug test
 720p50_parkrun_ter.y4m,--preset medium
diff --git a/source/x265.h b/source/x265.h
index f44040ba7..8ac90c38f 100644
--- a/source/x265.h
+++ b/source/x265.h
@@ -1932,6 +1932,10 @@ typedef struct x265_param
     /* Maximum VBV fullness to be maintained. Default 80. Keep the buffer
     * at max 80% full */
     double   maxVbvFullness;
+
+    /* Specify combinations of color primaries, transfer characteristics,
color matrix,
+     * range of luma and chroma signals, and chroma sample location */
+    const char* videoSignalTypePreset;
 } x265_param;

 /* x265_param_alloc:
diff --git a/source/x265cli.cpp b/source/x265cli.cpp
index c28dd7f8c..cfb832d2e 100755
--- a/source/x265cli.cpp
+++ b/source/x265cli.cpp
@@ -313,6 +313,28 @@ namespace X265_NS {
         H0("   --master-display <string>     SMPTE ST 2086 master display
color volume info SEI (HDR)\n");
         H0("                                    format:
G(x,y)B(x,y)R(x,y)WP(x,y)L(max,min)\n");
         H0("   --max-cll <string>            Specify content light level
info SEI as \"cll,fall\" (HDR).\n");
+        H0("   --video-signal-type-preset <string>    Specify combinations
of color primaries, transfer characteristics, color matrix, range of luma
and chroma signals, and chroma sample location\n");
+        H0("                                            format:
<system-id>[:<color-volume>]\n");
+        H0("                                            The color-volume
can be used only with the system-id options BT2100_PQ_YCC, BT2100_PQ_ICTCP,
and BT2100_PQ_RGB.\n");
+        H0("                                            system-id options
and their corresponding values:\n");
+        H0("                                              BT601_525:
--colorprim smpte170m --transfer smpte170m --colormatrix smpte170m --range
limited --chromaloc 0\n");
+        H0("                                              BT601_626:
--colorprim bt470bg --transfer smpte170m --colormatrix bt470bg --range
limited --chromaloc 0\n");
+        H0("                                              BT709_YCC:
--colorprim bt709 --transfer bt709 --colormatrix bt709 --range limited
--chromaloc 0\n");
+        H0("                                              BT709_RGB:
--colorprim bt709 --transfer bt709 --colormatrix gbr --range limited\n");
+        H0("                                              BT2020_YCC_NCL:
 --colorprim bt2020 --transfer bt2020-10 --colormatrix bt709 --range
limited --chromaloc 2\n");
+        H0("                                              BT2020_RGB:
 --colorprim bt2020 --transfer smpte2084 --colormatrix bt2020nc --range
limited\n");
+        H0("                                              BT2100_PQ_YCC:
--colorprim bt2020 --transfer smpte2084 --colormatrix bt2020nc --range
limited --chromaloc 2\n");
+        H0("                                              BT2100_PQ_ICTCP:
--colorprim bt2020 --transfer smpte2084 --colormatrix ictcp --range limited
--chromaloc 2\n");
+        H0("                                              BT2100_PQ_RGB:
--colorprim bt2020 --transfer smpte2084 --colormatrix gbr --range
limited\n");
+        H0("                                              BT2100_HLG_YCC:
 --colorprim bt2020 --transfer arib-std-b67 --colormatrix bt2020nc --range
limited --chromaloc 2\n");
+        H0("                                              BT2100_HLG_RGB:
 --colorprim bt2020 --transfer arib-std-b67 --colormatrix gbr --range
limited\n");
+        H0("                                              FR709_RGB:
--colorprim bt709 --transfer bt709 --colormatrix gbr --range full\n");
+        H0("                                              FR2020_RGB:
 --colorprim bt2020 --transfer bt2020-10 --colormatrix gbr --range full\n");
+        H0("                                              FRP3D65_YCC:
--colorprim smpte432 --transfer bt709 --colormatrix smpte170m --range full
--chromaloc 1\n");
+        H0("                                            color-volume
options and their corresponding values:\n");
+        H0("                                              P3D65x1000n0005:
--master-display
G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,5)\n");
+        H0("                                              P3D65x4000n005:
 --master-display
G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(40000000,50)\n");
+        H0("                                              BT2100x108n0005:
--master-display
G(8500,39850)B(6550,2300)R(34000,146000)WP(15635,16450)L(10000000,1)\n");
         H0("   --[no-]cll                    Emit content light level info
SEI. Default %s\n", OPT(param->bEmitCLL));
         H0("   --[no-]hdr10                  Control dumping of HDR10 SEI
packet. If max-cll or master-display has non-zero values, this is enabled.
Default %s\n", OPT(param->bEmitHDR10SEI));
         H0("   --[no-]hdr-opt                Add luma and chroma offsets
for HDR/WCG content. Default %s. Now deprecated.\n", OPT(param->bHDROpt));
diff --git a/source/x265cli.h b/source/x265cli.h
index a24d25435..3d2480374 100644
--- a/source/x265cli.h
+++ b/source/x265cli.h
@@ -249,6 +249,7 @@ static const struct option long_options[] =
     { "crop-rect",      required_argument, NULL, 0 }, /* DEPRECATED */
     { "master-display", required_argument, NULL, 0 },
     { "max-cll",        required_argument, NULL, 0 },
+    {"video-signal-type-preset", required_argument, NULL, 0 },
     { "min-luma",       required_argument, NULL, 0 },
     { "max-luma",       required_argument, NULL, 0 },
     { "log2-max-poc-lsb", required_argument, NULL, 8 },
-- 
2.18.0.windows.1


-- 

Thanks & Regards
*Niranjan Kumar B*
Video Codec Engineer
Media & AI Analytics
+91 958 511 1449
<https://multicorewareinc.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20210304/a74eb04f/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x265.diff
Type: application/octet-stream
Size: 20696 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20210304/a74eb04f/attachment-0001.obj>


More information about the x265-devel mailing list