PR #23050 opened by vigneshvg
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23050
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23050.patch

If packets contain Smpte2094App5 metadata, pass it to
the libaom encoder.

Signed-off-by: Vignesh Venkat <[email protected]>


>From eea5b362e870847e7a939aed97813d7a2f5a27c9 Mon Sep 17 00:00:00 2001
From: Vignesh Venkat <[email protected]>
Date: Fri, 13 Feb 2026 10:48:41 -0800
Subject: [PATCH] avcodec/aomenc: Handle Smpte2094App5 metadata

If packets contain Smpte2094App5 metadata, pass it to
the libaom encoder.

Signed-off-by: Vignesh Venkat <[email protected]>
---
 libavcodec/libaomenc.c | 49 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 48ba4e1a9d..b6877401f0 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -372,6 +372,51 @@ static int add_hdr_plus(AVCodecContext *avctx, struct 
aom_image *img, const AVFr
     return 0;
 }
 
+static int add_hdr_smpte2094_app5(AVCodecContext *avctx, struct aom_image *img,
+                                  const AVFrame *frame)
+{
+    AVFrameSideData *side_data =
+        av_frame_get_side_data(frame, 
AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5);
+    if (!side_data)
+        return 0;
+
+    size_t payload_size;
+    AVDynamicHDRSmpte2094App5 *hdr = (AVDynamicHDRSmpte2094App5 
*)side_data->buf->data;
+    int res = av_dynamic_hdr_smpte2094_app5_to_t35(hdr, NULL, &payload_size);
+    if (res < 0) {
+        log_encoder_error(avctx, "Error finding the size of HDR 
SMPTE-2094-50");
+        return res;
+    }
+
+    uint8_t *hdr_buf;
+    // Extra bytes for the country code, provider code, provider oriented code.
+    const size_t hdr_buf_size = payload_size + 5;
+    hdr_buf = av_malloc(hdr_buf_size);
+    if (!hdr_buf)
+        return AVERROR(ENOMEM);
+
+    uint8_t *payload = hdr_buf;
+    bytestream_put_byte(&payload, ITU_T_T35_COUNTRY_CODE_US);
+    bytestream_put_be16(&payload, ITU_T_T35_PROVIDER_CODE_SMPTE);
+    bytestream_put_be16(&payload, 0x0001); // provider_oriented_code
+
+    res = av_dynamic_hdr_smpte2094_app5_to_t35(hdr, &payload, &payload_size);
+    if (res < 0) {
+        av_free(hdr_buf);
+        log_encoder_error(avctx, "Error encoding HDR SMPTE-2094-50 from side 
data");
+        return res;
+    }
+
+    res = aom_img_add_metadata(img, OBU_METADATA_TYPE_ITUT_T35,
+                               hdr_buf, hdr_buf_size, AOM_MIF_ANY_FRAME);
+    av_free(hdr_buf);
+    if (res < 0) {
+        log_encoder_error(avctx, "Error adding HDR SMPTE-2094-50 to aom_img");
+        return res;
+    }
+    return 0;
+}
+
 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
     defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
     defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
@@ -1324,6 +1369,10 @@ static int aom_encode(AVCodecContext *avctx, AVPacket 
*pkt,
         res = add_hdr_plus(avctx, rawimg, frame);
         if (res < 0)
             return res;
+
+        res = add_hdr_smpte2094_app5(avctx, rawimg, frame);
+        if (res < 0)
+            return res;
     }
 
     res = aom_codec_encode(&ctx->encoder, rawimg, timestamp, duration, flags);
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to