<div dir="ltr">Ping</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 1, 2023 at 10:10 AM Damiano Galassi <<a href="mailto:damiog@gmail.com">damiog@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">---<br>
 source/common/param.cpp    |  6 ++++++<br>
 source/encoder/encoder.cpp |  9 +++++++++<br>
 source/encoder/sei.h       | 19 +++++++++++++++++++<br>
 source/x265.h              |  9 +++++++++<br>
 4 files changed, 43 insertions(+)<br>
<br>
diff --git a/source/common/param.cpp b/source/common/param.cpp<br>
index 1a4df4cdc..d63c36786 100755<br>
--- a/source/common/param.cpp<br>
+++ b/source/common/param.cpp<br>
@@ -378,6 +378,7 @@ void x265_param_default(x265_param* param)<br>
     param->preferredTransferCharacteristics = -1;<br>
     param->pictureStructure = -1;<br>
     param->bEmitCLL = 1;<br>
+    param->bEmitAmbientViewingEnvironment = 0;<br>
<br>
     param->bEnableFrameDuplication = 0;<br>
     param->dupThreshold = 70;<br>
@@ -1880,6 +1881,7 @@ int x265_check_params(x265_param* param)<br>
                      || param->bEmitIDRRecoverySEI<br>
                    || !!param->interlaceMode<br>
                      || param->preferredTransferCharacteristics > 1<br>
+                     || param->bEmitAmbientViewingEnvironment<br>
                      || param->toneMapFile<br>
                      || param->naluFile);<br>
<br>
@@ -2768,6 +2770,10 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>
     dst->bEmitCLL = src->bEmitCLL;<br>
     dst->maxCLL = src->maxCLL;<br>
     dst->maxFALL = src->maxFALL;<br>
+    dst->ambientIlluminance = src->ambientIlluminance;<br>
+    dst->ambientLightX = src->ambientLightX;<br>
+    dst->ambientLightY = src->ambientLightY;<br>
+    dst->bEmitAmbientViewingEnvironment = src->bEmitAmbientViewingEnvironment;<br>
     dst->log2MaxPocLsb = src->log2MaxPocLsb;<br>
     dst->bEmitVUIHRDInfo = src->bEmitVUIHRDInfo;<br>
     dst->bEmitVUITimingInfo = src->bEmitVUITimingInfo;<br>
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp<br>
index 8ec01bebe..c5043341e 100644<br>
--- a/source/encoder/encoder.cpp<br>
+++ b/source/encoder/encoder.cpp<br>
@@ -3276,6 +3276,15 @@ void Encoder::getStreamHeaders(NALList& list, Entropy& sbacCoder, Bitstream& bs)<br>
         }<br>
     }<br>
<br>
+    if (m_param->bEmitAmbientViewingEnvironment)<br>
+    {<br>
+        SEIAmbientViewingEnvironment ambientsei;<br>
+        ambientsei.ambientIlluminance = m_param->ambientIlluminance;<br>
+        ambientsei.ambientLightX = m_param->ambientLightX;<br>
+        ambientsei.ambientLightY = m_param->ambientLightY;<br>
+        ambientsei.writeSEImessages(bs, m_sps, NAL_UNIT_PREFIX_SEI, list, m_param->bSingleSeiNal);<br>
+    }<br>
+<br>
     if (m_param->bEmitInfoSEI)<br>
     {<br>
         char *opts = x265_param2string(m_param, m_sps.conformanceWindow.rightOffset, m_sps.conformanceWindow.bottomOffset);<br>
diff --git a/source/encoder/sei.h b/source/encoder/sei.h<br>
index 03e210639..712e4efb4 100644<br>
--- a/source/encoder/sei.h<br>
+++ b/source/encoder/sei.h<br>
@@ -242,6 +242,25 @@ public:<br>
     }<br>
 };<br>
<br>
+class SEIAmbientViewingEnvironment : public SEI<br>
+{<br>
+public:<br>
+    SEIAmbientViewingEnvironment()<br>
+    {<br>
+        m_payloadType = AMBIENT_VIEWING_ENVIRONMENT;<br>
+        m_payloadSize = 8;<br>
+    }<br>
+    uint32_t ambientIlluminance;<br>
+    uint16_t ambientLightX;<br>
+    uint16_t ambientLightY;<br>
+    void writeSEI(const SPS&)<br>
+    {<br>
+        WRITE_CODE(ambientIlluminance, 32, "ambient_illuminance");<br>
+        WRITE_CODE(ambientLightX,      16, "ambient_light_x");<br>
+        WRITE_CODE(ambientLightY,      16, "ambient_light_y");<br>
+    }<br>
+};<br>
+<br>
 class SEIDecodedPictureHash : public SEI<br>
 {<br>
 public:<br>
diff --git a/source/x265.h b/source/x265.h<br>
index fb1a5dca7..86d68bd7a 100644<br>
--- a/source/x265.h<br>
+++ b/source/x265.h<br>
@@ -371,6 +371,7 @@ typedef enum<br>
     MASTERING_DISPLAY_INFO               = 137,<br>
     CONTENT_LIGHT_LEVEL_INFO             = 144,<br>
     ALTERNATIVE_TRANSFER_CHARACTERISTICS = 147,<br>
+    AMBIENT_VIEWING_ENVIRONMENT          = 148,<br>
 } SEIPayloadType;<br>
<br>
 typedef struct x265_sei_payload<br>
@@ -1906,6 +1907,11 @@ typedef struct x265_param<br>
      * value to that value. */<br>
     uint16_t maxLuma;<br>
<br>
+    /* ISO/IEC 23008-2:2017, D.2.39 ambient viewing environment SEI message */<br>
+    uint32_t ambientIlluminance;<br>
+    uint16_t ambientLightX;<br>
+    uint16_t ambientLightY;<br>
+<br>
     /* Maximum of the picture order count */<br>
     int log2MaxPocLsb;<br>
<br>
@@ -2117,6 +2123,9 @@ typedef struct x265_param<br>
     /*Emit content light level info SEI*/<br>
     int         bEmitCLL;<br>
<br>
+    /* Emit ambient viewing environment SEI */<br>
+    int         bEmitAmbientViewingEnvironment;<br>
+<br>
     /*<br>
     * Signals picture structure SEI timing message for every frame<br>
     * picture structure 7 is signalled for frame doubling<br>
-- <br>
2.39.3 (Apple Git-145)<br>
<br>
</blockquote></div>