[FFmpeg-cvslog] lavc: Add Content Light Level side metadata found in HEVC

Steve Lhomme git at videolan.org
Thu Apr 6 17:42:47 EEST 2017


ffmpeg | branch: master | Steve Lhomme <robux4 at gmail.com> | Mon Apr  3 09:29:46 2017 +0200| [157e57a1810c6783779b046c1817a4f9737b2cb3] | committer: James Almer

lavc: Add Content Light Level side metadata found in HEVC

These data are necessary when transmitting HDR over HDMI.

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=157e57a1810c6783779b046c1817a4f9737b2cb3
---

 doc/APIchanges        |  3 +++
 libavcodec/avcodec.h  |  7 +++++++
 libavcodec/avpacket.c |  1 +
 libavcodec/hevc_sei.c | 15 +++++++++++++++
 libavcodec/hevcdec.c  | 18 ++++++++++++++++++
 libavcodec/hevcdec.h  |  5 +++++
 libavcodec/utils.c    |  1 +
 libavcodec/version.h  |  2 +-
 8 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index e2e6c90..1aced2f 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2016-04-06 - xxxxxxx - lavc 57.92.100 - avcodec.h
+  Add AV_PKT_DATA_CONTENT_LIGHT_LEVEL packet side data.
+
 2016-04-06 - xxxxxxx - lavu 55.60.100 - mastering_display_metadata.h
   Add AV_FRAME_DATA_CONTENT_LIGHT_LEVEL value, av_content_light_metadata_alloc()
   and av_content_light_metadata_create_side_data() API, and AVContentLightMetadata
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index f6bd90b..bffc169 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1584,6 +1584,13 @@ enum AVPacketSideDataType {
      * to the AVSphericalMapping structure.
      */
     AV_PKT_DATA_SPHERICAL,
+
+    /**
+     * Content light level (based on CTA-861.3). This metadata should be
+     * associated with a video stream and containts data in the form of the
+     * AVContentLightMetadata struct.
+     */
+    AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
 };
 
 #define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS //DEPRECATED
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index e633245..4bf830b 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -374,6 +374,7 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type)
     case AV_PKT_DATA_METADATA_UPDATE:            return "Metadata Update";
     case AV_PKT_DATA_MPEGTS_STREAM_ID:           return "MPEGTS Stream ID";
     case AV_PKT_DATA_MASTERING_DISPLAY_METADATA: return "Mastering display metadata";
+    case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:        return "Content light level metadata";
     case AV_PKT_DATA_SPHERICAL:                  return "Spherical Mapping";
     }
     return NULL;
diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index 8fc026c..bb299d5 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -102,6 +102,19 @@ static int decode_nal_sei_mastering_display_info(HEVCContext *s)
     return 0;
 }
 
+static int decode_nal_sei_content_light_info(HEVCContext *s)
+{
+    GetBitContext *gb = &s->HEVClc->gb;
+    // Max and average light levels
+    s->max_content_light_level     = get_bits_long(gb, 16);
+    s->max_pic_average_light_level = get_bits_long(gb, 16);
+    // As this SEI message comes before the first frame that references it,
+    // initialize the flag to 2 and decrement on IRAP access unit so it
+    // persists for the coded video sequence (e.g., between two IRAPs)
+    s-> sei_content_light_present = 2;
+    return  0;
+}
+
 static int decode_nal_sei_frame_packing_arrangement(HEVCContext *s)
 {
     GetBitContext *gb = &s->HEVClc->gb;
@@ -304,6 +317,8 @@ static int decode_nal_sei_prefix(HEVCContext *s, int type, int size)
         }
     case SEI_TYPE_MASTERING_DISPLAY_INFO:
         return decode_nal_sei_mastering_display_info(s);
+    case SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO:
+        return decode_nal_sei_content_light_info(s);
     case SEI_TYPE_ACTIVE_PARAMETER_SETS:
         active_parameter_sets(s);
         av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type);
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index f9e8ff0..af55416 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2644,6 +2644,24 @@ static int set_side_data(HEVCContext *s)
                "min_luminance=%f, max_luminance=%f\n",
                av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
     }
+    // Decrement the mastering display flag when IRAP frame has no_rasl_output_flag=1
+    // so the side data persists for the entire coded video sequence.
+    if (s->sei_content_light_present > 0 &&
+        IS_IRAP(s) && s->no_rasl_output_flag) {
+        s->sei_content_light_present--;
+    }
+    if (s->sei_content_light_present) {
+        AVContentLightMetadata *metadata =
+            av_content_light_metadata_create_side_data(out);
+        if (!metadata)
+            return AVERROR(ENOMEM);
+        metadata->MaxCLL  = s->max_content_light_level;
+        metadata->MaxFALL = s->max_pic_average_light_level;
+
+        av_log(s->avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n");
+        av_log(s->avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n",
+               metadata->MaxCLL, metadata->MaxFALL);
+    }
 
     if (s->a53_caption) {
         AVFrameSideData* sd = av_frame_new_side_data(out,
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 0c78812..e5879a5 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -596,6 +596,11 @@ typedef struct HEVCContext {
     uint32_t max_mastering_luminance;
     uint32_t min_mastering_luminance;
 
+    /* content light level */
+    int sei_content_light_present;
+    uint16_t max_content_light_level;
+    uint16_t max_pic_average_light_level;
+
 } HEVCContext;
 
 int ff_hevc_decode_nal_sei(HEVCContext *s);
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 0c68836..ff95cea 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -771,6 +771,7 @@ int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame)
         { AV_PKT_DATA_STEREO3D,                   AV_FRAME_DATA_STEREO3D },
         { AV_PKT_DATA_AUDIO_SERVICE_TYPE,         AV_FRAME_DATA_AUDIO_SERVICE_TYPE },
         { AV_PKT_DATA_MASTERING_DISPLAY_METADATA, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
+        { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,        AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
     };
 
     if (pkt) {
diff --git a/libavcodec/version.h b/libavcodec/version.h
index fc8ca2d..cb238dc 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  57
-#define LIBAVCODEC_VERSION_MINOR  91
+#define LIBAVCODEC_VERSION_MINOR  92
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list