diff mbox series

[FFmpeg-devel,v2,14/18] av1_metadata_bsf: Support HDR metadata

Message ID 20210221195125.1901683-14-sw@jkqxz.net
State New
Headers show
Series [FFmpeg-devel,v2,01/18] cbs_sei: Delete SEI NAL units containing no messages | expand

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 Feb. 21, 2021, 7:51 p.m. UTC
---
 doc/bitstream_filters.texi    | 17 +++++++++++++++++
 libavcodec/av1_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 e739832665..6a4c0cfe5e 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -90,6 +90,23 @@  has a fixed framerate.  Ignored if @option{tick_rate} is not also set.
 @item delete_padding
 Deletes Padding OBUs.
 
+@item hdr_cll
+@item hdr_mdcv
+Manipulate content light level (see AV1 section 6.7.3) and mastering
+display colour volume (see AV1 section 6.7.4) metadata 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 chomp
diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c
index 8cafe461d1..77062e0400 100644
--- a/libavcodec/av1_metadata_bsf.c
+++ b/libavcodec/av1_metadata_bsf.c
@@ -23,6 +23,7 @@ 
 #include "cbs.h"
 #include "cbs_bsf.h"
 #include "cbs_av1.h"
+#include "cbs_metadata.h"
 
 typedef struct AV1MetadataContext {
     CBSBSFContext common;
@@ -40,6 +41,9 @@  typedef struct AV1MetadataContext {
     int num_ticks_per_picture;
 
     int delete_padding;
+
+    int hdr_cll;
+    int hdr_mdcv;
 } AV1MetadataContext;
 
 
@@ -143,6 +147,20 @@  static int av1_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt,
         }
     }
 
+    if (pkt) {
+        err = ff_cbs_bsf_apply_metadata(bsf, pkt, frag,
+                                        CBS_METADATA_CONTENT_LIGHT_LEVEL,
+                                        ctx->hdr_mdcv);
+        if (err < 0)
+            return err;
+
+        err = ff_cbs_bsf_apply_metadata(bsf, pkt, frag,
+                                        CBS_METADATA_MASTERING_DISPLAY,
+                                        ctx->hdr_mdcv);
+        if (err < 0)
+            return err;
+    }
+
     return 0;
 }
 
@@ -203,6 +221,14 @@  static const AVOption av1_metadata_options[] = {
         OFFSET(delete_padding), AV_OPT_TYPE_BOOL,
         { .i64 = 0 }, 0, 1, FLAGS},
 
+    BSF_ELEMENT_OPTIONS_PIRE("hdr_cll",
+                             "HDR content light level metadata",
+                             hdr_cll, FLAGS),
+
+    BSF_ELEMENT_OPTIONS_PIRE("hdr_mdcv",
+                             "HDR mastering display colour volume metadata",
+                             hdr_mdcv, FLAGS),
+
     { NULL }
 };