aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Birkbeck <neil.birkbeck@gmail.com>2016-01-21 10:56:50 -0800
committerMichael Niedermayer <michael@niedermayer.cc>2016-02-14 00:36:05 +0100
commit3b0974d3ef7f6f39a2e4c2af9ec2a2f9976ad46d (patch)
treeb1e031ec8d374cfd46eb0c30b1c688545418714d
parentc33ffc7b21b9531a971b5da1edcae0b308fe88aa (diff)
downloadffmpeg-3b0974d3ef7f6f39a2e4c2af9ec2a2f9976ad46d.tar.gz
lavc/hevc Parse SEI_TYPE_MASTERING_DISPLAY_INFO and propagate content into the AVMasteringDisplayMetadata side data.
Add support for parsing SEI_TYPE_MASTERING_DISPLAY_INFO and propagate contents into the AVMasteringDisplayMetadata side data. Primaries are ordered in RGB order and the values are converted to rationals ([0,1] for CEI 1931 Chroma coords, and cd/m^2 for luma). Signed-off-by: Neil Birkbeck <neil.birkbeck@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--libavcodec/hevc.c52
-rw-r--r--libavcodec/hevc.h7
-rw-r--r--libavcodec/hevc_sei.c26
3 files changed, 85 insertions, 0 deletions
diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index c245d3b7e9..203f90ab2e 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -28,6 +28,7 @@
#include "libavutil/common.h"
#include "libavutil/display.h"
#include "libavutil/internal.h"
+#include "libavutil/mastering_display_metadata.h"
#include "libavutil/md5.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
@@ -2580,6 +2581,57 @@ static int set_side_data(HEVCContext *s)
s->sei_hflip, s->sei_vflip);
}
+ // 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_mastering_display_info_present > 0 &&
+ IS_IRAP(s) && s->no_rasl_output_flag) {
+ s->sei_mastering_display_info_present--;
+ }
+ if (s->sei_mastering_display_info_present) {
+ // HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b
+ const int mapping[3] = {2, 0, 1};
+ const int chroma_den = 50000;
+ const int luma_den = 10000;
+ int i;
+ AVMasteringDisplayMetadata *metadata =
+ av_mastering_display_metadata_create_side_data(out);
+ if (!metadata)
+ return AVERROR(ENOMEM);
+
+ for (i = 0; i < 3; i++) {
+ const int j = mapping[i];
+ metadata->display_primaries[i][0].num = s->display_primaries[j][0];
+ metadata->display_primaries[i][0].den = chroma_den;
+ metadata->display_primaries[i][1].num = s->display_primaries[j][1];
+ metadata->display_primaries[i][1].den = chroma_den;
+ }
+ metadata->white_point[0].num = s->white_point[0];
+ metadata->white_point[0].den = chroma_den;
+ metadata->white_point[1].num = s->white_point[1];
+ metadata->white_point[1].den = chroma_den;
+
+ metadata->max_luminance.num = s->max_mastering_luminance;
+ metadata->max_luminance.den = luma_den;
+ metadata->min_luminance.num = s->min_mastering_luminance;
+ metadata->min_luminance.den = luma_den;
+ metadata->has_luminance = 1;
+ metadata->has_primaries = 1;
+
+ av_log(s->avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n");
+ av_log(s->avctx, AV_LOG_DEBUG,
+ "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
+ av_q2d(metadata->display_primaries[0][0]),
+ av_q2d(metadata->display_primaries[0][1]),
+ av_q2d(metadata->display_primaries[1][0]),
+ av_q2d(metadata->display_primaries[1][1]),
+ av_q2d(metadata->display_primaries[2][0]),
+ av_q2d(metadata->display_primaries[2][1]),
+ av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]));
+ av_log(s->avctx, AV_LOG_DEBUG,
+ "min_luminance=%f, max_luminance=%f\n",
+ av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
+ }
+
if (s->a53_caption) {
AVFrameSideData* sd = av_frame_new_side_data(out,
AV_FRAME_DATA_A53_CC,
diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
index 9d72555867..c91f815857 100644
--- a/libavcodec/hevc.h
+++ b/libavcodec/hevc.h
@@ -941,6 +941,13 @@ typedef struct HEVCContext {
uint8_t* a53_caption;
int a53_caption_size;
+ /** mastering display */
+ int sei_mastering_display_info_present;
+ uint16_t display_primaries[3][2];
+ uint16_t white_point[2];
+ uint32_t max_mastering_luminance;
+ uint32_t min_mastering_luminance;
+
} HEVCContext;
int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx,
diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index 07856f2414..40685fe5d8 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -78,6 +78,30 @@ static int decode_nal_sei_decoded_picture_hash(HEVCContext *s)
return 0;
}
+static int decode_nal_sei_mastering_display_info(HEVCContext *s)
+{
+ GetBitContext *gb = &s->HEVClc->gb;
+ int i;
+ // Mastering primaries
+ for (i = 0; i < 3; i++) {
+ s->display_primaries[i][0] = get_bits(gb, 16);
+ s->display_primaries[i][1] = get_bits(gb, 16);
+ }
+ // White point (x, y)
+ s->white_point[0] = get_bits(gb, 16);
+ s->white_point[1] = get_bits(gb, 16);
+
+ // Max and min luminance of mastering display
+ s->max_mastering_luminance = get_bits_long(gb, 32);
+ s->min_mastering_luminance = get_bits_long(gb, 32);
+
+ // 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_mastering_display_info_present = 2;
+ return 0;
+}
+
static int decode_nal_sei_frame_packing_arrangement(HEVCContext *s)
{
GetBitContext *gb = &s->HEVClc->gb;
@@ -278,6 +302,8 @@ static int decode_nal_sei_prefix(HEVCContext *s, int type, int size)
skip_bits(gb, 8 * size);
return ret;
}
+ case SEI_TYPE_MASTERING_DISPLAY_INFO:
+ return decode_nal_sei_mastering_display_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);