# HG changeset patch # User Bhavna Hariharan <bha...@multicorewareinc.com> # Date 1492645223 25200 # Wed Apr 19 16:40:23 2017 -0700 # Node ID 8dbdf0b6a8ff6972136313a0199a0016948bb430 # Parent 9c3ae5906579b7494ca86b957c68d66d69d2817a dhdr10-opt: limits frames for which tone mapping SEI is inserted
diff -r 9c3ae5906579 -r 8dbdf0b6a8ff doc/reST/cli.rst --- a/doc/reST/cli.rst Tue Mar 28 10:53:31 2017 +0530 +++ b/doc/reST/cli.rst Wed Apr 19 16:40:23 2017 -0700 @@ -1876,6 +1876,16 @@ Add luma and chroma offsets for HDR/WCG content. Input video should be 10 bit 4:2:0. Applicable for HDR content. Default disabled. **Experimental Feature** + +.. option:: --dhdr10-info <filename> + + Inserts tone mapping information as an SEI message. + +.. option:: --dhdr10-opt, --no-dhdr10-opt + + Limits the frames for which tone mapping information is inserted as + SEI message. Inserts SEI only for IDR frames and for frames where tone + mapping information has changed. .. option:: --min-luma <integer> diff -r 9c3ae5906579 -r 8dbdf0b6a8ff source/CMakeLists.txt --- a/source/CMakeLists.txt Tue Mar 28 10:53:31 2017 +0530 +++ b/source/CMakeLists.txt Wed Apr 19 16:40:23 2017 -0700 @@ -29,7 +29,7 @@ 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 115) +set(X265_BUILD 116) configure_file("${PROJECT_SOURCE_DIR}/x265.def.in" "${PROJECT_BINARY_DIR}/x265.def") configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in" diff -r 9c3ae5906579 -r 8dbdf0b6a8ff source/common/param.cpp --- a/source/common/param.cpp Tue Mar 28 10:53:31 2017 +0530 +++ b/source/common/param.cpp Wed Apr 19 16:40:23 2017 -0700 @@ -272,8 +272,11 @@ param->bAQMotion = 0; param->bHDROpt = 0; param->analysisRefineLevel = 5; + param->toneMapFile = NULL; + param->bDhdr10opt = 0; } + int x265_param_default_preset(x265_param* param, const char* preset, const char* tune) { #if EXPORT_C_API @@ -950,6 +953,7 @@ OPT("hdr-opt") p->bHDROpt = atobool(value); OPT("limit-sao") p->bLimitSAO = atobool(value); OPT("dhdr10-info") p->toneMapFile = strdup(value); + OPT("dhdr10-opt") p->bDhdr10opt = atobool(value); else return X265_PARAM_BAD_NAME; } @@ -1663,6 +1667,7 @@ BOOL(p->bAQMotion, "aq-motion"); BOOL(p->bEmitHDRSEI, "hdr"); BOOL(p->bHDROpt, "hdr-opt"); + BOOL(p->bDhdr10opt, "dhdr10-opt"); s += sprintf(s, " refine-level=%d", p->analysisRefineLevel); BOOL(p->bLimitSAO, "limit-sao"); #undef BOOL diff -r 9c3ae5906579 -r 8dbdf0b6a8ff source/encoder/encoder.cpp --- a/source/encoder/encoder.cpp Tue Mar 28 10:53:31 2017 +0530 +++ b/source/encoder/encoder.cpp Wed Apr 19 16:40:23 2017 -0700 @@ -87,6 +87,7 @@ MotionEstimate::initScales(); #if ENABLE_DYNAMIC_HDR10 m_hdr10plus_api = hdr10plus_api_get(); + m_prevTonemapPayload.payload = NULL; #endif } inline char *strcatFilename(const char *input, const char *suffix) @@ -2226,6 +2227,12 @@ x265_log(p, X265_LOG_WARNING, "Dynamic-rd disabled, requires RD <= 4, VBV and aq-mode enabled\n"); } #ifdef ENABLE_DYNAMIC_HDR10 + if (m_param->bDhdr10opt && m_param->toneMapFile == NULL) + { + x265_log(p, X265_LOG_WARNING, "Disabling dhdr10-opt. dhdr10-info must be enabled.\n"); + m_param->bDhdr10opt = 0; + } + if (m_param->toneMapFile) { if (!x265_fopen(p->toneMapFile, "r")) @@ -2246,6 +2253,11 @@ m_bToneMap = 0; m_param->toneMapFile = NULL; } + else if (m_param->bDhdr10opt) + { + x265_log(p, X265_LOG_WARNING, "Disabling dhdr10-opt. dhdr10-info must be enabled.\n"); + m_param->bDhdr10opt = 0; + } #endif if (p->uhdBluray) diff -r 9c3ae5906579 -r 8dbdf0b6a8ff source/encoder/encoder.h --- a/source/encoder/encoder.h Tue Mar 28 10:53:31 2017 +0530 +++ b/source/encoder/encoder.h Wed Apr 19 16:40:23 2017 -0700 @@ -175,9 +175,15 @@ int m_bToneMap; // Enables tone-mapping const hdr10plus_api* m_hdr10plus_api; + x265_sei_payload m_prevTonemapPayload; Encoder(); - ~Encoder() {} + ~Encoder() + { + if (m_prevTonemapPayload.payload != NULL) + X265_FREE(m_prevTonemapPayload.payload); + } + void create(); void stopJobs(); void destroy(); diff -r 9c3ae5906579 -r 8dbdf0b6a8ff source/encoder/frameencoder.cpp --- a/source/encoder/frameencoder.cpp Tue Mar 28 10:53:31 2017 +0530 +++ b/source/encoder/frameencoder.cpp Wed Apr 19 16:40:23 2017 -0700 @@ -448,6 +448,40 @@ /* Get the QP for this frame from rate control. This call may block until * frames ahead of it in encode order have called rateControlEnd() */ m_rce.encodeOrder = m_frame->m_encodeOrder; + bool payloadChange = false; + bool writeSei = true; + if (m_param->bDhdr10opt) + { + for (int i = 0; i < m_frame->m_userSEI.numPayloads; i++) + { + x265_sei_payload *payload = &m_frame->m_userSEI.payloads[i]; + if(payload->payloadType == USER_DATA_REGISTERED_ITU_T_T35) + { + if (m_top->m_prevTonemapPayload.payload != NULL && payload->payloadSize == m_top->m_prevTonemapPayload.payloadSize) + { + if (memcmp(m_top->m_prevTonemapPayload.payload, payload->payload, payload->payloadSize) != 0) + payloadChange = true; + } + else + { + payloadChange = true; + if (m_top->m_prevTonemapPayload.payload != NULL) + x265_free(m_top->m_prevTonemapPayload.payload); + m_top->m_prevTonemapPayload.payload = (uint8_t*)x265_malloc(sizeof(uint8_t) * payload->payloadSize); + } + + if (payloadChange) + { + m_top->m_prevTonemapPayload.payloadType = payload->payloadType; + m_top->m_prevTonemapPayload.payloadSize = payload->payloadSize; + memcpy(m_top->m_prevTonemapPayload.payload, payload->payload, payload->payloadSize); + } + + bool isIDR = m_frame->m_lowres.sliceType == X265_TYPE_IDR; + writeSei = payloadChange || isIDR; + } + } + } int qp = m_top->m_rateControl->rateControlStart(m_frame, &m_rce, m_top); m_rce.newQp = qp; @@ -627,13 +661,16 @@ } else if (payload->payloadType == USER_DATA_REGISTERED_ITU_T_T35) { - SEICreativeIntentMeta sei; - sei.cim = payload->payload; - m_bs.resetBits(); - sei.setSize(payload->payloadSize); - sei.write(m_bs, *slice->m_sps); - m_bs.writeByteAlignment(); - m_nalList.serialize(NAL_UNIT_PREFIX_SEI, m_bs); + if (writeSei) + { + SEICreativeIntentMeta sei; + sei.cim = payload->payload; + m_bs.resetBits(); + sei.setSize(payload->payloadSize); + sei.write(m_bs, *slice->m_sps); + m_bs.writeByteAlignment(); + m_nalList.serialize(NAL_UNIT_PREFIX_SEI, m_bs); + } } else x265_log(m_param, X265_LOG_ERROR, "Unrecognized SEI type\n"); diff -r 9c3ae5906579 -r 8dbdf0b6a8ff source/x265.h --- a/source/x265.h Tue Mar 28 10:53:31 2017 +0530 +++ b/source/x265.h Wed Apr 19 16:40:23 2017 -0700 @@ -1388,6 +1388,9 @@ /* File containing the tone mapping information */ const char* toneMapFile; + /* Insert tone mapping information only for IDR frames and when the + * tone mapping information changes. */ + int bDhdr10opt; } x265_param; /* x265_param_alloc: * Allocates an x265_param instance. The returned param structure is not diff -r 9c3ae5906579 -r 8dbdf0b6a8ff source/x265cli.h --- a/source/x265cli.h Tue Mar 28 10:53:31 2017 +0530 +++ b/source/x265cli.h Wed Apr 19 16:40:23 2017 -0700 @@ -269,6 +269,8 @@ { "limit-sao", no_argument, NULL, 0 }, { "no-limit-sao", no_argument, NULL, 0 }, { "dhdr10-info", required_argument, NULL, 0 }, + { "dhdr10-opt", no_argument, NULL, 0}, + { "no-dhdr10-opt", no_argument, NULL, 0}, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, @@ -316,6 +318,7 @@ H1(" 3 - i444 (4:4:4)\n"); #if ENABLE_DYNAMIC_HDR10 H0(" --dhdr10-info <filename> JSON file containing the Creative Intent Metadata to be encoded as Dynamic Tone Mapping \n"); + H0(" --[no-]dhdr10-opt Insert tone mapping SEI only for IDR frames and when the tone mapping information changes. Default disabled"); #endif H0("-f/--frames <integer> Maximum number of frames to encode. Default all\n"); H0(" --seek <integer> First frame to encode\n"); _______________________________________________ x265-devel mailing list x265-devel@videolan.org https://mailman.videolan.org/listinfo/x265-devel