[FFmpeg-devel] [PATCH] avcodec/nvenc: add udu_sei option to import user data unregistered SEIs

lance.lmwang at gmail.com lance.lmwang at gmail.com
Fri Dec 24 06:32:47 EET 2021


From: Limin Wang <lance.lmwang at gmail.com>

Note:
nvenc sdk will truncated user data unregistered SEI if the size > 503.
for example, hardcode its size to 504, trace_headers will report below error:
Invalid SEI message: payload_size too large (504 504 bytes).

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
 libavcodec/nvenc.c      | 2 +-
 libavcodec/nvenc.h      | 1 +
 libavcodec/nvenc_h264.c | 2 ++
 libavcodec/nvenc_hevc.c | 2 ++
 4 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index edc46ed..12ffcf0 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -2221,7 +2221,7 @@ static int prepare_sei_data_array(AVCodecContext *avctx, const AVFrame *frame)
         AVFrameSideData *side_data = frame->side_data[i];
         void *tmp;
 
-        if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
+        if (!(ctx->udu_sei && side_data->type == AV_FRAME_DATA_SEI_UNREGISTERED))
             continue;
 
         tmp = av_fast_realloc(ctx->sei_data,
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index 08531e1..b42a156 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -235,6 +235,7 @@ typedef struct NvencContext
     int intra_refresh;
     int single_slice_intra_refresh;
     int constrained_encoding;
+    int udu_sei;
 } NvencContext;
 
 int ff_nvenc_encode_init(AVCodecContext *avctx);
diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
index 7d78aa0..79b7aca 100644
--- a/libavcodec/nvenc_h264.c
+++ b/libavcodec/nvenc_h264.c
@@ -194,6 +194,8 @@ static const AVOption options[] = {
                                                             OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
     { "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
                                                             OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
+    { "udu_sei",      "Use user data unregistered SEI if available",
+                                                            OFFSET(udu_sei),   AV_OPT_TYPE_BOOL,   { .i64 = 0 }, 0, 1, VE },
     { NULL }
 };
 
diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
index a13ac5a..12b4e11 100644
--- a/libavcodec/nvenc_hevc.c
+++ b/libavcodec/nvenc_hevc.c
@@ -175,6 +175,8 @@ static const AVOption options[] = {
                                                             OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
     { "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
                                                             OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+    { "udu_sei",      "Use user data unregistered SEI if available",
+                                                            OFFSET(udu_sei),   AV_OPT_TYPE_BOOL,   { .i64 = 0 }, 0, 1, VE },
     { NULL }
 };
 
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list