From cee9f9628fb983ad9e1c84fb17570f297bc542d2 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Fri, 4 Jun 2021 16:06:38 +0200 Subject: [PATCH] avcodec/nvenc: write out user data unregistered SEI Signed-off-by: Brad Hards Signed-off-by: Timo Rothenpieler --- libavcodec/nvenc.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 5ae68b7101..e254c2983a 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -2282,6 +2282,34 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) } } + for (int j = 0; j < frame->nb_side_data; j++) { + AVFrameSideData *side_data = frame->side_data[j]; + void *tmp; + + if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED) + continue; + + tmp = av_fast_realloc(ctx->sei_data, + &ctx->sei_data_size, + (sei_count + 1) * sizeof(*ctx->sei_data)); + if (!tmp) { + res = AVERROR(ENOMEM); + goto sei_failed; + } else { + ctx->sei_data = tmp; + ctx->sei_data[sei_count].payloadSize = side_data->size; + ctx->sei_data[sei_count].payloadType = SEI_TYPE_USER_DATA_UNREGISTERED; + ctx->sei_data[sei_count].payload = av_memdup(side_data->data, side_data->size); + + if (!ctx->sei_data[sei_count].payload) { + res = AVERROR(ENOMEM); + goto sei_failed; + } + + sei_count++; + } + } + nvenc_codec_specific_pic_params(avctx, &pic_params, ctx->sei_data, sei_count); } else { pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;