[FFmpeg-devel] [PATCH v1 5/5] avcodec/h264: create user data unregistered side data for H.264

lance.lmwang at gmail.com lance.lmwang at gmail.com
Tue Dec 17 12:22:17 EET 2019


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

Below is the sample message for -vf showinfo(need to apply the patchset):
[Parsed_showinfo_0 @ 0x7fac7b702080]   side data - User data unregistered:
[Parsed_showinfo_0 @ 0x7fac7b702080] UUID=186f369370304f2c603021492feee5b8
[Parsed_showinfo_0 @ 0x7fac7b702080] User Data=hello

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
 libavcodec/h264_sei.c   |  5 ++++-
 libavcodec/h264_sei.h   |  3 +++
 libavcodec/h264_slice.c | 11 +++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
index 46fe8692dd..c70a5122ec 100644
--- a/libavcodec/h264_sei.c
+++ b/libavcodec/h264_sei.c
@@ -50,6 +50,7 @@ void ff_h264_sei_uninit(H264SEIContext *h)
     h->frame_packing.present       = 0;
     h->display_orientation.present = 0;
     h->afd.present                 =  0;
+    h->unregistered.present        = 0;
 
     av_buffer_unref(&h->a53_caption.buf_ref);
 }
@@ -258,6 +259,8 @@ static int decode_unregistered_user_data(H264SEIUnregistered *h, GetBitContext *
         user_data[i] = get_bits(gb, 8);
 
     memset(user_data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+    h->user_data = user_data;
+    h->user_data_size = size;
 
     e = sscanf(user_data + 16, "x264 - core %d", &build);
     if (e == 1 && build > 0)
@@ -265,7 +268,7 @@ static int decode_unregistered_user_data(H264SEIUnregistered *h, GetBitContext *
     if (e == 1 && build == 1 && !strncmp(user_data+16, "x264 - core 0000", 16))
         h->x264_build = 67;
 
-    av_free(user_data);
+    h->present = 1;
     return 0;
 }
 
diff --git a/libavcodec/h264_sei.h b/libavcodec/h264_sei.h
index a75c3aa175..4bded8e579 100644
--- a/libavcodec/h264_sei.h
+++ b/libavcodec/h264_sei.h
@@ -121,6 +121,9 @@ typedef struct H264SEIA53Caption {
 
 typedef struct H264SEIUnregistered {
     int x264_build;
+    int present;
+    int user_data_size;
+    uint8_t *user_data;
 } H264SEIUnregistered;
 
 typedef struct H264SEIRecoveryPoint {
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index e24d41ca50..4fb99c9263 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1285,6 +1285,17 @@ static int h264_export_frame_props(H264Context *h)
         h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
     }
 
+    if (h->sei.unregistered.present) {
+        AVFrameSideData *sd = av_frame_new_side_data(cur->f, AV_FRAME_DATA_USER_DATA_UNREGISTERED,
+                                                     h->sei.unregistered.user_data_size);
+        if (sd)
+            memcpy(sd->data, h->sei.unregistered.user_data,
+                h->sei.unregistered.user_data_size);
+        av_freep(&h->sei.unregistered.user_data);
+        h->sei.unregistered.user_data_size = 0;
+        h->sei.unregistered.present = 0;
+    }
+
     if (h->sei.picture_timing.timecode_cnt > 0) {
         uint32_t tc = 0;
         uint32_t *tc_sd;
-- 
2.21.0



More information about the ffmpeg-devel mailing list