[FFmpeg-devel] [PATCH 1/4] avutil: add support for CUVA HDR Vivid metadata

lance.lmwang at gmail.com lance.lmwang at gmail.com
Tue Feb 15 01:44:17 EET 2022


From: Limin Wang <lance.lmwang at gmail.com>

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
 libavutil/Makefile                     |   2 +
 libavutil/frame.c                      |   1 +
 libavutil/frame.h                      |   7 +
 libavutil/hdr_dynamic_vivid_metadata.c |  47 ++++++
 libavutil/hdr_dynamic_vivid_metadata.h | 285 +++++++++++++++++++++++++++++++++
 libavutil/version.h                    |   2 +-
 6 files changed, 343 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/hdr_dynamic_vivid_metadata.c
 create mode 100644 libavutil/hdr_dynamic_vivid_metadata.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index d17876d..a8d7587 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -34,6 +34,7 @@ HEADERS = adler32.h                                                     \
           frame.h                                                       \
           hash.h                                                        \
           hdr_dynamic_metadata.h                                        \
+          hdr_dynamic_vivid_metadata.h                                  \
           hmac.h                                                        \
           hwcontext.h                                                   \
           hwcontext_cuda.h                                              \
@@ -130,6 +131,7 @@ OBJS = adler32.o                                                        \
        frame.o                                                          \
        hash.o                                                           \
        hdr_dynamic_metadata.o                                           \
+       hdr_dynamic_vivid_metadata.o                                     \
        hmac.o                                                           \
        hwcontext.o                                                      \
        imgutils.o                                                       \
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 8997c85..b035e28 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -723,6 +723,7 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type)
     case AV_FRAME_DATA_SPHERICAL:                   return "Spherical Mapping";
     case AV_FRAME_DATA_ICC_PROFILE:                 return "ICC profile";
     case AV_FRAME_DATA_DYNAMIC_HDR_PLUS: return "HDR Dynamic Metadata SMPTE2094-40 (HDR10+)";
+    case AV_FRAME_DATA_DYNAMIC_HDR_VIVID: return "HDR Dynamic Metadata CUVA 005.1 2021 (Vivid)";
     case AV_FRAME_DATA_REGIONS_OF_INTEREST: return "Regions Of Interest";
     case AV_FRAME_DATA_VIDEO_ENC_PARAMS:            return "Video encoding parameters";
     case AV_FRAME_DATA_SEI_UNREGISTERED:            return "H.26[45] User Data Unregistered SEI message";
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 18e239f..32cde3c 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -158,6 +158,13 @@ enum AVFrameSideDataType {
     AV_FRAME_DATA_DYNAMIC_HDR_PLUS,
 
     /**
+     * HDR Vivid dynamic metadata associated with a video frame. The payload is
+     * an AVDynamicHDRVivid type and contains information for color
+     * volume transform - CUVA 005.1-2021.
+     */
+    AV_FRAME_DATA_DYNAMIC_HDR_VIVID,
+
+    /**
      * Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of
      * array element is implied by AVFrameSideData.size / AVRegionOfInterest.self_size.
      */
diff --git a/libavutil/hdr_dynamic_vivid_metadata.c b/libavutil/hdr_dynamic_vivid_metadata.c
new file mode 100644
index 0000000..32da01f
--- /dev/null
+++ b/libavutil/hdr_dynamic_vivid_metadata.c
@@ -0,0 +1,47 @@
+/**
+ * Copyright (c) 2021 Limin Wang <lance.lmwang at gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "hdr_dynamic_vivid_metadata.h"
+#include "mem.h"
+
+AVDynamicHDRVivid *av_dynamic_hdr_vivid_alloc(size_t *size)
+{
+    AVDynamicHDRVivid *hdr_vivid = av_mallocz(sizeof(AVDynamicHDRVivid));
+    if (!hdr_vivid)
+        return NULL;
+
+    if (size)
+        *size = sizeof(*hdr_vivid);
+
+    return hdr_vivid;
+}
+
+AVDynamicHDRVivid *av_dynamic_hdr_vivid_create_side_data(AVFrame *frame)
+{
+    AVFrameSideData *side_data = av_frame_new_side_data(frame,
+                                                        AV_FRAME_DATA_DYNAMIC_HDR_VIVID,
+                                                        sizeof(AVDynamicHDRVivid));
+    if (!side_data)
+        return NULL;
+
+    memset(side_data->data, 0, sizeof(AVDynamicHDRVivid));
+
+    return (AVDynamicHDRVivid *)side_data->data;
+}
diff --git a/libavutil/hdr_dynamic_vivid_metadata.h b/libavutil/hdr_dynamic_vivid_metadata.h
new file mode 100644
index 0000000..832f7f9
--- /dev/null
+++ b/libavutil/hdr_dynamic_vivid_metadata.h
@@ -0,0 +1,285 @@
+/*
+ * Copyright (c) 2021 Limin Wang <lance.lmwang at gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_HDR_DYNAMIC_VIVID_METADATA_H
+#define AVUTIL_HDR_DYNAMIC_VIVID_METADATA_H
+
+#include "frame.h"
+#include "rational.h"
+
+/**
+ * Color tone mapping parameters at a processing window in a dynamic metadata for
+ * CUVA 005.1:2021.
+ */
+typedef struct AVHDRVividColorToneMappingParams {
+    /**
+     * The nominal maximum display luminance of the targeted system display,
+     * in multiples of 1.0/4095 candelas per square metre. The value shall be in
+     * the range of 0.0 to 1.0, inclusive.
+     */
+    AVRational targeted_system_display_maximum_luminance;
+
+    /**
+     * This flag indicates that transfer the base paramter(for value of 1)
+     */
+    int base_enable_flag;
+
+    /**
+     * base_param_m_p in the base parameter,
+     * in multiples of 1.0/16383. The value shall be in
+     * the range of 0.0 to 1.0, inclusive.
+     */
+    AVRational base_param_m_p;
+
+    /**
+     * base_param_m_m in the base parameter,
+     * in multiples of 1.0/10. The value shall be in
+     * the range of 0.0 to 6.3, inclusive.
+     */
+    AVRational base_param_m_m;
+
+    /**
+     * base_param_m_a in the base parameter,
+     * in multiples of 1.0/1023. The value shall be in
+     * the range of 0.0 to 1.0 inclusive.
+     */
+    AVRational base_param_m_a;
+
+    /**
+     * base_param_m_b in the base parameter,
+     * in multiples of 1/1023. The value shall be in
+     * the range of 0.0 to 1.0, inclusive.
+     */
+    AVRational base_param_m_b;
+
+    /**
+     * base_param_m_n in the base parameter,
+     * in multiples of 1.0/10. The value shall be in
+     * the range of 0.0 to 6.3, inclusive.
+     */
+    AVRational base_param_m_n;
+
+    /**
+     * indicates k1_0 in the base parameter,
+     * base_param_k1 <= 1: k1_0 = base_param_k1
+     * base_param_k1 > 1: reserved
+     */
+    int base_param_k1;
+
+    /**
+     * indicates k2_0 in the base parameter,
+     * base_param_k2 <= 1: k2_0 = base_param_k2
+     * base_param_k2 > 1: reserved
+     */
+    int base_param_k2;
+
+    /**
+     * indicates k3_0 in the base parameter,
+     * base_param_k3 == 1: k3_0 = base_param_k3
+     * base_param_k3 == 2: k3_0 = maximum_maxrgb
+     * base_param_k3 > 2: reserved
+     */
+    int base_param_k3;
+
+    /**
+     * This flag indicates that delta mode of base paramter(for value of 1)
+     */
+    int base_param_Delta_enable_mode;
+
+    /**
+     * base_param_Delta in the base parameter,
+     * in multiples of 1.0/127. The value shall be in
+     * the range of 0.0 to 1.0, inclusive.
+     */
+    AVRational base_param_Delta;
+
+    /**
+     * indicates 3Spline_flag in the base parameter,
+     * This flag indicates that transfer three Spline of base paramter(for value of 1)
+     */
+    int three_Spline_flag;
+
+    /**
+     * The number of three Spline. The value shall be in the range
+     * of 1 to 2, inclusive.
+     */
+    int three_Spline_num;
+
+    /**
+     * The mode of three Spline. the value shall be in the range
+     * of 0 to 3, inclusive.
+     */
+    int three_Spline_TH_mode;
+
+    /**
+     * three_Spline_TH_enable MB is in the range of 0.0 to 1.0, inclusive
+     * and in multiples of 1.0/255.
+     *
+     */
+    AVRational three_Spline_TH_enable_MB;
+
+    /**
+     * 3Spline_TH_enable of three Spline.
+     * The value shall be in the range of 0.0 to 1.0, inclusive.
+     * and in multiples of 1.0/4095.
+     */
+    AVRational three_Spline_TH;
+
+    /**
+     * 3Spline_TH_Delta1 of three Spline.
+     * The value shall be in the range of 0.0 to 0.25, inclusive,
+     * and in multiples of 0.25/1023.
+     */
+    AVRational three_Spline_TH_Delta1;
+
+    /**
+     * 3Spline_TH_Delta2 of three Spline.
+     * The value shall be in the range of 0.0 to 0.25, inclusive,
+     * and in multiples of 0.25/1023.
+     */
+    AVRational three_Spline_TH_Delta2;
+
+    /**
+     * 3Spline_enable_Strength of three Spline.
+     * The value shall be in the range of 0.0 to 1, inclusive,
+     * and in multiples of 1.0/255.
+     */
+    AVRational three_Spline_enable_Strength;
+} AVHDRVividColorToneMappingParams;
+
+
+/**
+ * Color transform parameters at a processing window in a dynamic metadata for
+ * CUVA 005.1:2021.
+ */
+typedef struct AVHDRVividColorTransformParams {
+    /**
+     * Indicates the minimum brightness of the displayed content.
+     * The values should be in the range of 0.0 to 1.0,
+     * inclusive and in multiples of 1/4095.
+     */
+    AVRational minimum_maxrgb;
+
+    /**
+     * Indicates the average brightness of the displayed content.
+     * The values should be in the range of 0.0 to 1.0,
+     * inclusive and in multiples of 1/4095.
+     */
+    AVRational average_maxrgb;
+
+    /**
+     * Indicates the variance brightness of the displayed content.
+     * The values should be in the range of 0.0 to 1.0,
+     * inclusive and in multiples of 1/4095.
+     */
+    AVRational variance_maxrgb;
+
+    /**
+     * Indicates the maximum brightness of the displayed content.
+     * The values should be in the range of 0.0 to 1.0, inclusive
+     * and in multiples of 1/4095.
+     */
+    AVRational maximum_maxrgb;
+
+    /**
+     * This flag indicates that the metadata for the tone mapping function in
+     * the processing window is present (for value of 1).
+     */
+    int tone_mapping_mode_flag;
+
+    /**
+     * The number of tone mapping param. The value shall be in the range
+     * of 1 to 2, inclusive.
+     */
+    int tone_mapping_param_num;
+
+    /**
+     * The color tone mapping parameters.
+     */
+    AVHDRVividColorToneMappingParams tm_params[2];
+
+    /**
+     * This flag indicates that the metadata for the color saturation mapping in
+     * the processing window is present (for value of 1).
+     */
+    int color_saturation_mapping_flag;
+
+    /**
+     * The number of color saturation param. The value shall be in the range
+     * of 0 to 7, inclusive.
+     */
+    int color_saturation_num;
+
+    /**
+     * Indicates the color correction strength parameter.
+     * The values should be in the range of 0.0 to 2.0, inclusive
+     * and in multiples of 1/128.
+     */
+    AVRational color_saturation_gain[8];
+} AVHDRVividColorTransformParams;
+
+/**
+ * This struct represents dynamic metadata for color volume transform -
+ * CUVA 005.1:2021 standard
+ *
+ * To be used as payload of a AVFrameSideData or AVPacketSideData with the
+ * appropriate type.
+ *
+ * @note The struct should be allocated with
+ * av_dynamic_hdr_vivid_alloc() and its size is not a part of
+ * the public ABI.
+ */
+typedef struct AVDynamicHDRVivid {
+    /**
+     * The system start code. The value shall be set to 0x01.
+     */
+    uint8_t system_start_code;
+
+    /**
+     * The number of processing windows. The value shall be set to 0x01
+     * if the system_start_code is 0x01.
+     */
+    uint8_t num_windows;
+
+    /**
+     * The color transform parameters for every processing window.
+     */
+    AVHDRVividColorTransformParams params[3];
+} AVDynamicHDRVivid;
+
+/**
+ * Allocate an AVDynamicHDRVivid structure and set its fields to
+ * default values. The resulting struct can be freed using av_freep().
+ *
+ * @return An AVDynamicHDRVivid filled with default values or NULL
+ *         on failure.
+ */
+AVDynamicHDRVivid *av_dynamic_hdr_vivid_alloc(size_t *size);
+
+/**
+ * Allocate a complete AVDynamicHDRVivid and add it to the frame.
+ * @param frame The frame which side data is added to.
+ *
+ * @return The AVDynamicHDRVivid structure to be filled by caller or NULL
+ *         on failure.
+ */
+AVDynamicHDRVivid *av_dynamic_hdr_vivid_create_side_data(AVFrame *frame);
+
+#endif /* AVUTIL_HDR_DYNAMIC_VIVID_METADATA_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index a9c9bc6..c80e9d7 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  57
-#define LIBAVUTIL_VERSION_MINOR  21
+#define LIBAVUTIL_VERSION_MINOR  22
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list