[FFmpeg-devel] [PATCH v2 13/18] h265_metadata_bsf: Support HDR metadata

Mark Thompson sw at jkqxz.net
Sun Feb 21 21:51:20 EET 2021


---
 doc/bitstream_filters.texi     | 17 +++++++++++++++++
 libavcodec/h265_metadata_bsf.c | 26 ++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 0ff76b86f0..e739832665 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -393,6 +393,23 @@ The argument must be the name of a level (for example, @samp{5.1}), a
 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.265 section D.3.28)
+and content light level info (see H.265 section D.3.35) 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 hevc_mp4toannexb
diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c
index 59325c0471..0986564237 100644
--- a/libavcodec/h265_metadata_bsf.c
+++ b/libavcodec/h265_metadata_bsf.c
@@ -23,6 +23,7 @@
 #include "cbs.h"
 #include "cbs_bsf.h"
 #include "cbs_h265.h"
+#include "cbs_metadata.h"
 #include "hevc.h"
 #include "h265_profile_level.h"
 
@@ -60,6 +61,9 @@ typedef struct H265MetadataContext {
     int level;
     int level_guess;
     int level_warned;
+
+    int mastering_display;
+    int content_light_level;
 } H265MetadataContext;
 
 
@@ -393,6 +397,20 @@ static int h265_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt,
         }
     }
 
+    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;
+    }
+
     return 0;
 }
 
@@ -484,6 +502,14 @@ static const AVOption h265_metadata_options[] = {
     { LEVEL("8.5", 255) },
 #undef LEVEL
 
+    BSF_ELEMENT_OPTIONS_PIRE("mastering_display",
+                             "Mastering display colour volume SEI",
+                             mastering_display, FLAGS),
+
+    BSF_ELEMENT_OPTIONS_PIRE("content_light_level",
+                             "Content light level information SEI",
+                             content_light_level, FLAGS),
+
     { NULL }
 };
 
-- 
2.30.0



More information about the ffmpeg-devel mailing list