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

Brad Hards bradh at frogmouth.net
Sat May 1 05:23:01 EEST 2021


Signed-off-by: Brad Hards <bradh at frogmouth.net>
---
 libavcodec/libx264.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

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 {
-- 
2.27.0



More information about the ffmpeg-devel mailing list