changeset 12438:8eb57eb225d5 draft

hrd: Add cli option to set concatenation flag in buffering period SEI
author Aruna Matheswaran <aruna@multicorewareinc.com>
date Wed, 03 Oct 2018 17:00:53 +0530
parents e50f803e26fb
children 3023bd8b05c0
files doc/reST/cli.rst source/CMakeLists.txt source/common/param.cpp source/encoder/frameencoder.cpp source/encoder/sei.h source/x265.h source/x265cli.h
diffstat 7 files changed, 24 insertions(+-), 3 deletions(-) [+]
line wrap: on
line diff
--- a/doc/reST/cli.rst	Thu Sep 27 14:16:15 2018 +0530
+++ b/doc/reST/cli.rst	Wed Oct 03 17:00:53 2018 +0530
@@ -1506,7 +1506,7 @@ Slice decision options
 	0 - flush the encoder only when all the input pictures are over.
 	1 - flush all the frames even when the input is not over. 
 	    slicetype decision may change with this option.
-	2 - flush the slicetype decided frames only.     
+	2 - flush the slicetype decided frames only.   
 
 Quality, rate control and rate distortion options
 =================================================
@@ -2195,6 +2195,14 @@ Bitstream options
 	Picture Timing SEI messages providing timing information to the
 	decoder. Default disabled
 
+    	
+.. option:: --hrd-concat, --no-hrd-concat
+
+    Set concantenation flag for the first keyframe in the HRD buffering period SEI. This
+    is to signal the decoder if splicing is performed during bitstream generation. 
+    Recommended to enable this option during chunked encoding, except for the first chunk.
+    Default disabled.
+
 .. option:: --dolby-vision-profile <integer|float>
 
     Generate bitstreams confirming to the specified Dolby Vision profile,
--- a/source/CMakeLists.txt	Thu Sep 27 14:16:15 2018 +0530
+++ b/source/CMakeLists.txt	Wed Oct 03 17:00:53 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 167)
+set(X265_BUILD 168)
 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	Thu Sep 27 14:16:15 2018 +0530
+++ b/source/common/param.cpp	Wed Oct 03 17:00:53 2018 +0530
@@ -158,6 +158,7 @@ void x265_param_default(x265_param* para
     param->radl = 0;
     param->chunkStart = 0;
     param->chunkEnd = 0;
+    param->bEnableHRDConcatFlag = 0;
 
     /* Intra Coding Tools */
     param->bEnableConstrainedIntra = 0;
@@ -1059,6 +1060,7 @@ int x265_param_parse(x265_param* p, cons
             else
                 bError = true;
         }
+        OPT("hrd-concat") p->bEnableHRDConcatFlag = atobool(value);
         else
             return X265_PARAM_BAD_NAME;
     }
@@ -1663,6 +1665,7 @@ char *x265_param2string(x265_param* p, i
     s += sprintf(s, " lookahead-slices=%d", p->lookaheadSlices);
     s += sprintf(s, " scenecut=%d", p->scenecutThreshold);
     s += sprintf(s, " radl=%d", p->radl);
+    BOOL(p->bEnableHRDConcatFlag, "splice");
     BOOL(p->bIntraRefresh, "intra-refresh");
     s += sprintf(s, " ctu=%d", p->maxCUSize);
     s += sprintf(s, " min-cu-size=%d", p->minCUSize);
--- a/source/encoder/frameencoder.cpp	Thu Sep 27 14:16:15 2018 +0530
+++ b/source/encoder/frameencoder.cpp	Wed Oct 03 17:00:53 2018 +0530
@@ -657,6 +657,8 @@ void FrameEncoder::compressFrame()
             bpSei->m_auCpbRemovalDelayDelta = 1;
             bpSei->m_cpbDelayOffset = 0;
             bpSei->m_dpbDelayOffset = 0;
+            bpSei->m_concatenationFlag = (m_param->bEnableHRDConcatFlag && !m_frame->m_poc) ? true : false;
+
             // hrdFullness() calculates the initial CPB removal delay and offset
             m_top->m_rateControl->hrdFullness(bpSei);
             bpSei->writeSEImessages(m_bs, *slice->m_sps, NAL_UNIT_PREFIX_SEI, m_nalList, m_param->bSingleSeiNal);
--- a/source/encoder/sei.h	Thu Sep 27 14:16:15 2018 +0530
+++ b/source/encoder/sei.h	Wed Oct 03 17:00:53 2018 +0530
@@ -220,6 +220,7 @@ public:
     SEIBufferingPeriod()
         : m_cpbDelayOffset(0)
         , m_dpbDelayOffset(0)
+        , m_concatenationFlag(0)
         , m_auCpbRemovalDelayDelta(1)
     {
         m_payloadType = BUFFERING_PERIOD;
@@ -227,6 +228,7 @@ public:
     }
     bool     m_cpbDelayOffset;
     bool     m_dpbDelayOffset;
+    bool     m_concatenationFlag;
     uint32_t m_initialCpbRemovalDelay;
     uint32_t m_initialCpbRemovalDelayOffset;
     uint32_t m_auCpbRemovalDelayDelta;
@@ -237,7 +239,7 @@ public:
 
         WRITE_UVLC(0, "bp_seq_parameter_set_id");
         WRITE_FLAG(0, "rap_cpb_params_present_flag");
-        WRITE_FLAG(0, "concatenation_flag");
+        WRITE_FLAG(m_concatenationFlag, "concatenation_flag");
         WRITE_CODE(m_auCpbRemovalDelayDelta - 1,   hrd.cpbRemovalDelayLength,       "au_cpb_removal_delay_delta_minus1");
         WRITE_CODE(m_initialCpbRemovalDelay,       hrd.initialCpbRemovalDelayLength,        "initial_cpb_removal_delay");
         WRITE_CODE(m_initialCpbRemovalDelayOffset, hrd.initialCpbRemovalDelayLength, "initial_cpb_removal_delay_offset");
--- a/source/x265.h	Thu Sep 27 14:16:15 2018 +0530
+++ b/source/x265.h	Wed Oct 03 17:00:53 2018 +0530
@@ -1730,6 +1730,9 @@ typedef struct x265_param
      * device as RPU will be ignored. Default 0 (disabled) */
     int dolbyProfile;
 
+    /* Set concantenation flag for the first keyframe in the HRD buffering period SEI. */
+    int bEnableHRDConcatFlag;
+
 } x265_param;
 /* x265_param_alloc:
  *  Allocates an x265_param instance. The returned param structure is not
--- a/source/x265cli.h	Thu Sep 27 14:16:15 2018 +0530
+++ b/source/x265cli.h	Wed Oct 03 17:00:53 2018 +0530
@@ -307,6 +307,8 @@ static const struct option long_options[
     { "pic-struct", required_argument, NULL, 0 },
     { "nalu-file", required_argument, NULL, 0 },
     { "dolby-vision-rpu", required_argument, NULL, 0 },
+    { "hrd-concat",          no_argument, NULL, 0},
+    { "no-hrd-concat",       no_argument, NULL, 0 },
     { 0, 0, 0, 0 },
     { 0, 0, 0, 0 },
     { 0, 0, 0, 0 },
@@ -463,6 +465,7 @@ static void showHelp(x265_param *param)
     H1("                                 0 - flush the encoder only when all the input pictures are over.\n");
     H1("                                 1 - flush all the frames even when the input is not over. Slicetype decision may change with this option.\n");
     H1("                                 2 - flush the slicetype decided frames only.\n");
+    H0("   --[no-]-hrd-concat            Set HRD concatenation flag for the first keyframe in the buffering period SEI. Default %s\n", OPT(param->bEnableHRDConcatFlag));
     H0("\nRate control, Adaptive Quantization:\n");
     H0("   --bitrate <integer>           Target bitrate (kbps) for ABR (implied). Default %d\n", param->rc.bitrate);
     H1("-q/--qp <integer>                QP for P slices in CQP mode (implied). --ipratio and --pbration determine other slice QPs\n");