diff mbox series

[FFmpeg-devel,v4,2/3] libavcodec/libx265: write out user data unregistered SEI

Message ID 20210517075557.33664-3-bradh@frogmouth.net
State Superseded
Headers show
Series [FFmpeg-devel,v4,1/3] libavcodec/libx264: write out user data unregistered SEI | expand

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 May 17, 2021, 7:55 a.m. UTC
Signed-off-by: Brad Hards <bradh@frogmouth.net>
---
 libavcodec/libx265.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index a1bd205201..d66506dda9 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -484,6 +484,7 @@  static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     int nnal;
     int ret;
     int i;
+    int total_unregistered_sei;
 
     ctx->api->picture_init(ctx->params, &x265pic);
 
@@ -515,6 +516,27 @@  static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
             memcpy(x265pic.userData, &pic->reordered_opaque, sizeof(pic->reordered_opaque));
         }
+        for (int j = 0; j < pic->nb_side_data; j++)
+            if (pic->side_data[j]->type == AV_FRAME_DATA_SEI_UNREGISTERED)
+                total_unregistered_sei++;
+        if (total_unregistered_sei > 0) {
+            x265_sei *sei = &(x265pic.userSEI);
+            sei->payloads = av_realloc_array(sei->payloads,
+                                             sei->numPayloads + total_unregistered_sei,
+                                             sizeof(x265_sei_payload));
+            if (!sei->payloads) {
+                sei->numPayloads = 0;
+                return AVERROR(ENOMEM);
+            } else
+                for (int j = 0; j < pic->nb_side_data; j++)
+                    if (pic->side_data[j]->type == AV_FRAME_DATA_SEI_UNREGISTERED) {
+                        x265_sei_payload *payload = &(sei->payloads[sei->numPayloads]);
+                        payload->payload = pic->side_data[j]->data;
+                        payload->payloadSize = pic->side_data[j]->size;
+                        payload->payloadType = USER_DATA_UNREGISTERED;
+                        sei->numPayloads++;
+                    }
+        }
     }
 
     ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal,