[FFmpeg-devel] [PATCH 22/27] h264_metadata_bsf: Support HDR metadata

Mark Thompson sw at jkqxz.net
Fri Jan 1 23:35:32 EET 2021


---
 doc/bitstream_filters.texi     | 17 +++++++++++++++++
 libavcodec/h264_metadata_bsf.c | 25 +++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 8a2f55cc41..695825d33f 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -285,6 +285,23 @@ level_idc value (for example, @samp{42}), or the special name @samp{auto}
 indicating that the filter should attempt to guess the level from the
 input stream properties.
 
+ at item mastering_display
+ at item content_light_level
+Manipulate mastering display colour volume (see H.264 section D.2.29)
+and content light level info (see H.264 section D.2.31) SEI messages in
+the stream.
+
+Possible actions:
+ at table @samp
+ at item insert
+Insert this type of message, taking the values from packet side-data.
+ at item remove
+Remove all instances of this message.
+ at item extract
+Extract the content of this type of message, attaching it to the packets
+as side-data.
+ at end table
+
 @end table
 
 @section h264_mp4toannexb
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index aae91a6e23..bdaee78d1e 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -78,6 +78,9 @@ typedef struct H264MetadataContext {
     int flip;
 
     int level;
+
+    int mastering_display;
+    int content_light_level;
 } H264MetadataContext;
 
 
@@ -449,6 +452,20 @@ static int h264_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt,
             return err;
     }
 
+    if (pkt) {
+        err = ff_cbs_bsf_apply_metadata(bsf, pkt, au,
+                                        CBS_METADATA_MASTERING_DISPLAY,
+                                        ctx->mastering_display);
+        if (err < 0)
+            return err;
+
+        err = ff_cbs_bsf_apply_metadata(bsf, pkt, au,
+                                        CBS_METADATA_CONTENT_LIGHT_LEVEL,
+                                        ctx->content_light_level);
+        if (err < 0)
+            return err;
+    }
+
     if (pkt)
         ctx->done_first_au = 1;
 
@@ -609,6 +626,14 @@ static const AVOption h264_metadata_options[] = {
     { LEVEL("6.2", 62) },
 #undef LEVEL
 
+    BSF_ELEMENT_OPTIONS_PIRE("mastering_display",
+                             "Mastering display colour volume SEI",
+                             mastering_display, "mdcv"),
+
+    BSF_ELEMENT_OPTIONS_PIRE("content_light_level",
+                             "Content light level information SEI",
+                             content_light_level, "cll"),
+
     { NULL }
 };
 
-- 
2.29.2



More information about the ffmpeg-devel mailing list