diff mbox series

[FFmpeg-devel,23/27] h265_metadata_bsf: Support HDR metadata

Message ID 20210101213537.169546-24-sw@jkqxz.net
State New
Headers show
Series Metadata handling in CBS
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Mark Thompson Jan. 1, 2021, 9:35 p.m. UTC
---
 doc/bitstream_filters.texi     | 17 +++++++++++++++++
 libavcodec/h265_metadata_bsf.c | 26 ++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
diff mbox series

Patch

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 695825d33f..4c9a42c24a 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.
 
+@item mastering_display
+@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:
+@table @samp
+@item insert
+Insert this type of message, taking the values from packet side-data.
+@item remove
+Remove all instances of this message.
+@item extract
+Extract the content of this type of message, attaching it to the packets
+as side-data.
+@end table
+
 @end table
 
 @section hevc_mp4toannexb
diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c
index c3eadee92b..4c84d4f5a8 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, "mdcv"),
+
+    BSF_ELEMENT_OPTIONS_PIRE("content_light_level",
+                             "Content light level information SEI",
+                             content_light_level, "cll"),
+
     { NULL }
 };