diff mbox series

[FFmpeg-devel,3/5] libavcodec: write out user data unregistered SEI for x265

Message ID 20210430113432.308139-4-bradh@frogmouth.net
State New
Headers show
Series [FFmpeg-devel,1/5] libavutil: add convenience accessors for frame side data
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Brad Hards April 30, 2021, 11:34 a.m. UTC
Signed-off-by: Brad Hards <bradh@frogmouth.net>
---
 libavcodec/libx265.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index a1bd205201..3dceb3d165 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -484,6 +484,8 @@  static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     int nnal;
     int ret;
     int i;
+    AVFrameSideData *sd;
+    int num_unregistered_sei;
 
     ctx->api->picture_init(ctx->params, &x265pic);
 
@@ -515,6 +517,17 @@  static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
             memcpy(x265pic.userData, &pic->reordered_opaque, sizeof(pic->reordered_opaque));
         }
+        num_unregistered_sei = av_frame_num_side_data(pic, AV_FRAME_DATA_SEI_UNREGISTERED);
+        x265pic.userSEI.payloads = av_realloc_array(x265pic.userSEI.payloads, x265pic.userSEI.numPayloads + num_unregistered_sei, sizeof(x265_sei_payload));
+        for (i = 0; i < num_unregistered_sei; i++) {
+            sd = av_frame_get_side_data_n(pic, AV_FRAME_DATA_SEI_UNREGISTERED, i);
+            if (sd) {
+                x265pic.userSEI.payloads[x265pic.userSEI.numPayloads + i].payload = sd->data;
+                x265pic.userSEI.payloads[x265pic.userSEI.numPayloads + i].payloadSize = sd->size;
+                x265pic.userSEI.payloads[x265pic.userSEI.numPayloads + i].payloadType = USER_DATA_UNREGISTERED;
+            }
+        }
+        x265pic.userSEI.numPayloads += num_unregistered_sei;
     }
 
     ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal,