diff mbox series

[FFmpeg-devel,v2,1/4] libavcodec: write out user data unregistered SEI for x264

Message ID 20210501022304.301425-2-bradh@frogmouth.net
State Superseded
Headers show
Series [FFmpeg-devel,v2,1/4] libavcodec: write out user data unregistered SEI for x264
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 May 1, 2021, 2:23 a.m. UTC
Signed-off-by: Brad Hards <bradh@frogmouth.net>
---
 libavcodec/libx264.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
diff mbox series

Patch

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 22c91d8df7..c19a9b2804 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -31,6 +31,7 @@ 
 #include "internal.h"
 #include "packet_internal.h"
 #include "atsc_a53.h"
+#include "sei.h"
 
 #if defined(_MSC_VER)
 #define X264_API_IMPORTS 1
@@ -303,6 +304,7 @@  static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
     int64_t wallclock = 0;
     X264Opaque *out_opaque;
     AVFrameSideData *sd;
+    int total_unreg_sei = 0;
 
     x264_picture_init( &x4->pic );
     x4->pic.img.i_csp   = x4->params.i_csp;
@@ -438,6 +440,25 @@  static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
                 }
             }
         }
+        for (int j = 0; j < frame->nb_side_data; j++) {
+            if (frame->side_data[j]->type == AV_FRAME_DATA_SEI_UNREGISTERED)
+                total_unreg_sei++;
+        }
+        if (total_unreg_sei > 0) {
+            x264_sei_t *sei = &(x4->pic.extra_sei);
+            sei->payloads = av_realloc_array(sei->payloads,
+                                             sei->num_payloads + total_unreg_sei,
+                                             sizeof(x264_sei_payload_t));
+            for (int j = 0; j < frame->nb_side_data; j++) {
+                if (frame->side_data[j]->type == AV_FRAME_DATA_SEI_UNREGISTERED) {
+                    x264_sei_payload_t *payload = &(sei->payloads[sei->num_payloads]);
+                    payload->payload = frame->side_data[j]->data;
+                    payload->payload_size = frame->side_data[j]->size;
+                    payload->payload_type = SEI_TYPE_USER_DATA_UNREGISTERED;
+                    sei->num_payloads++;
+                }
+            }
+        }
     }
 
     do {