diff mbox series

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

Message ID 20210430113432.308139-3-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/libx264.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 22c91d8df7..6d4cee55c0 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 num_unregistered_sei;
 
     x264_picture_init( &x4->pic );
     x4->pic.img.i_csp   = x4->params.i_csp;
@@ -438,6 +440,19 @@  static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
                 }
             }
         }
+        num_unregistered_sei = av_frame_num_side_data(frame, AV_FRAME_DATA_SEI_UNREGISTERED);
+        x4->pic.extra_sei.payloads = av_realloc_array(x4->pic.extra_sei.payloads,
+                                                      x4->pic.extra_sei.num_payloads + num_unregistered_sei,
+                                                      sizeof(x264_sei_payload_t));
+        for (int i = 0; i < num_unregistered_sei; i++) {
+            sd = av_frame_get_side_data_n(frame, AV_FRAME_DATA_SEI_UNREGISTERED, i);
+            if (sd) {
+                x4->pic.extra_sei.payloads[x4->pic.extra_sei.num_payloads + i].payload = sd->data;
+                x4->pic.extra_sei.payloads[x4->pic.extra_sei.num_payloads + i].payload_size = sd->size;
+                x4->pic.extra_sei.payloads[x4->pic.extra_sei.num_payloads + i].payload_type = SEI_TYPE_USER_DATA_UNREGISTERED;
+            }
+        }
+        x4->pic.extra_sei.num_payloads += num_unregistered_sei;
     }
 
     do {