From: Neil Birkbeck <neil.birkb...@gmail.com> Adding mastering display metadata struct to avutil. The mastering display metadata contains information about the mastering display color volume (SMPTE 2086:2014).
This info comes from HEVC in the SEI_TYPE_MASTERING_DISPLAY_INFO and is soon to be included in MKV: https://mailarchive.ietf.org/arch/search/?email_list=cellar&gbt=1&index=sZyfPTM-QY69P-0omfOIiTN622o so it is similar to SEI FPA / stereo_mode in MKV and as such this patch follows how AVStereo3D is implemented. I'll add support to HEVC in a follow-up (and MKV when spec is approved). Signed-off-by: Neil Birkbeck <neil.birkb...@gmail.com> Signed-off-by: Michael Niedermayer <mich...@niedermayer.cc> --- doc/APIchanges | 5 ++ libavutil/Makefile | 2 + libavutil/frame.h | 6 +++ libavutil/mastering_display_metadata.c | 43 ++++++++++++++++ libavutil/mastering_display_metadata.h | 89 ++++++++++++++++++++++++++++++++++ libavutil/version.h | 2 +- 6 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 libavutil/mastering_display_metadata.c create mode 100644 libavutil/mastering_display_metadata.h diff --git a/doc/APIchanges b/doc/APIchanges index a0ca3b7ac0..5ce112262a 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,11 @@ libavutil: 2017-03-23 API changes, most recent first: +2017-04-xx - xxxxxxx - lavu 56.1.0 - mastering_display_metadata.h + Add mastering_display_metadata.h/c, av_mastering_display_metadata_alloc() + and av_mastering_display_metadata_create_side_data() API, and AVMasteringDisplayMetadata + type to export mastering metadata video properties. + 2017-03-xx - xxxxxxx - lavc 57.37.0 - avcodec.h Add AVCodecContext.hwaccel_flags field. This will control some hwaccels at a later point. diff --git a/libavutil/Makefile b/libavutil/Makefile index 60e180c79d..3c5aca49e4 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -38,6 +38,7 @@ HEADERS = adler32.h \ log.h \ macros.h \ mathematics.h \ + mastering_display_metadata.h \ md5.h \ mem.h \ opt.h \ @@ -94,6 +95,7 @@ OBJS = adler32.o \ log.o \ log2_tab.o \ mathematics.o \ + mastering_display_metadata.o \ md5.o \ mem.o \ opt.o \ diff --git a/libavutil/frame.h b/libavutil/frame.h index f9ffb5bbbf..881d8f0051 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -99,6 +99,12 @@ enum AVFrameSideDataType { * libavutil/spherical.h. */ AV_FRAME_DATA_SPHERICAL, + /** + * Mastering display metadata associated with a video frame. The payload is + * an AVMasteringDisplayMetadata type and contains information about the + * mastering display color volume. + */ + AV_FRAME_DATA_MASTERING_DISPLAY_METADATA, }; enum AVActiveFormatDescription { diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c new file mode 100644 index 0000000000..e1683e55c7 --- /dev/null +++ b/libavutil/mastering_display_metadata.c @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2016 Neil Birkbeck <neil.birkb...@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 <stdint.h> +#include <string.h> + +#include "mastering_display_metadata.h" +#include "mem.h" + +AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc(void) +{ + return av_mallocz(sizeof(AVMasteringDisplayMetadata)); +} + +AVMasteringDisplayMetadata *av_mastering_display_metadata_create_side_data(AVFrame *frame) +{ + AVFrameSideData *side_data = av_frame_new_side_data(frame, + AV_FRAME_DATA_MASTERING_DISPLAY_METADATA, + sizeof(AVMasteringDisplayMetadata)); + if (!side_data) + return NULL; + + memset(side_data->data, 0, sizeof(AVMasteringDisplayMetadata)); + + return (AVMasteringDisplayMetadata *)side_data->data; +} diff --git a/libavutil/mastering_display_metadata.h b/libavutil/mastering_display_metadata.h new file mode 100644 index 0000000000..936533fec4 --- /dev/null +++ b/libavutil/mastering_display_metadata.h @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2016 Neil Birkbeck <neil.birkb...@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_MASTERING_DISPLAY_METADATA_H +#define AVUTIL_MASTERING_DISPLAY_METADATA_H + +#include "frame.h" +#include "rational.h" + + +/** + * Mastering display metadata capable of representing the color volume of + * the display used to master the content (SMPTE 2086:2014). + * + * To be used as payload of a AVFrameSideData or AVPacketSideData with the + * appropriate type. + * + * @note The struct should be allocated with av_mastering_display_metadata_alloc() + * and its size is not a part of the public ABI. + */ +typedef struct AVMasteringDisplayMetadata { + /** + * CIE 1931 xy chromaticity coords of color primaries (r, g, b order). + */ + AVRational display_primaries[3][2]; + + /** + * CIE 1931 xy chromaticity coords of white point. + */ + AVRational white_point[2]; + + /** + * Min luminance of mastering display (cd/m^2). + */ + AVRational min_luminance; + + /** + * Max luminance of mastering display (cd/m^2). + */ + AVRational max_luminance; + + /** + * Flag indicating whether the display primaries (and white point) are set. + */ + int has_primaries; + + /** + * Flag indicating whether the luminance (min_ and max_) have been set. + */ + int has_luminance; + +} AVMasteringDisplayMetadata; + +/** + * Allocate an AVMasteringDisplayMetadata structure and set its fields to + * default values. The resulting struct can be freed using av_freep(). + * + * @return An AVMasteringDisplayMetadata filled with default values or NULL + * on failure. + */ +AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc(void); + +/** + * Allocate a complete AVMasteringDisplayMetadata and add it to the frame. + * + * @param frame The frame which side data is added to. + * + * @return The AVMasteringDisplayMetadata structure to be filled by caller. + */ +AVMasteringDisplayMetadata *av_mastering_display_metadata_create_side_data(AVFrame *frame); + +#endif /* AVUTIL_MASTERING_DISPLAY_METADATA_H */ diff --git a/libavutil/version.h b/libavutil/version.h index b8425ea2c8..fd72ff431d 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -54,7 +54,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 56 -#define LIBAVUTIL_VERSION_MINOR 0 +#define LIBAVUTIL_VERSION_MINOR 1 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ -- 2.11.1 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel