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

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


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

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 0dcd93a99c..c7659975b9 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -2170,9 +2170,10 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame)
     NVENCSTATUS nv_status;
     NvencSurface *tmp_out_surf, *in_surf;
     int res, res2;
-    NV_ENC_SEI_PAYLOAD sei_data[8];
+    NV_ENC_SEI_PAYLOAD *sei_data = 0;
     int sei_count = 0;
     int i;
+    int total_unregistered_sei = 0;
 
     NvencContext *ctx = avctx->priv_data;
     NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
@@ -2238,6 +2239,7 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame)
             }
 
             if (a53_data) {
+                sei_data = av_realloc_array(sei_data, sei_count + 1, sizeof(NV_ENC_SEI_PAYLOAD));
                 sei_data[sei_count].payloadSize = (uint32_t)a53_size;
                 sei_data[sei_count].payloadType = 4;
                 sei_data[sei_count].payload = (uint8_t*)a53_data;
@@ -2254,6 +2256,7 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame)
             }
 
             if (tc_data) {
+                sei_data = av_realloc_array(sei_data, sei_count + 1, sizeof(NV_ENC_SEI_PAYLOAD));
                 sei_data[sei_count].payloadSize = (uint32_t)tc_size;
                 sei_data[sei_count].payloadType = SEI_TYPE_TIME_CODE;
                 sei_data[sei_count].payload = (uint8_t*)tc_data;
@@ -2261,6 +2264,25 @@ static int nvenc_send_frame(AVCodecContext *avctx, 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_unregistered_sei++;
+        }
+        if (total_unregistered_sei > 0) {
+            sei_data = av_realloc_array(sei_data,
+                                        sei_count + total_unregistered_sei,
+                                        sizeof(NV_ENC_SEI_PAYLOAD));
+            for (int j = 0; j < frame->nb_side_data; j++) {
+                AVFrameSideData *side_data = frame->side_data[j];
+                if (side_data->type == AV_FRAME_DATA_SEI_UNREGISTERED) {
+                    sei_data[sei_count].payloadSize = side_data->size;
+                    sei_data[sei_count].payloadType = SEI_TYPE_USER_DATA_UNREGISTERED;
+                    sei_data[sei_count].payload = av_memdup(side_data->data, side_data->size);
+                    sei_count ++;
+                }
+            }
+        }
+
         nvenc_codec_specific_pic_params(avctx, &pic_params, sei_data, sei_count);
     } else {
         pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
@@ -2274,6 +2296,7 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame)
 
     for ( i = 0; i < sei_count; i++)
         av_freep(&sei_data[i].payload);
+    av_free(sei_data);
 
     res = nvenc_pop_context(avctx);
     if (res < 0)
-- 
2.27.0



More information about the ffmpeg-devel mailing list