From deb93707791092e608b1e5f8f1d1773b0057ce59 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Sat, 10 Jun 2017 14:02:55 +0200 Subject: vd: use ST.2086 / HDR10 MaxCLL in addition to mastering metadata MaxCLL is the more authoritative source for the metadata we are interested in. The use of mastering metadata is sort of a hack anyway, since there's no clearly-defined relationship between the mastering peak brightness and the actual content. (Unlike MaxCLL, which is an explicit relationship) Also move the parameter fixing to `fix_image_params` I don't know if the avutil check is strictly necessary but I've included it anyway to be on the safe side. --- video/decode/dec_video.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'video/decode/dec_video.c') diff --git a/video/decode/dec_video.c b/video/decode/dec_video.c index bd20dbe312..f7ca6cc477 100644 --- a/video/decode/dec_video.c +++ b/video/decode/dec_video.c @@ -188,6 +188,11 @@ bool video_init_best_codec(struct dec_video *d_video) return !!d_video->vd_driver; } +static bool is_valid_peak(float sig_peak) +{ + return !sig_peak || (sig_peak >= 1 && sig_peak <= 100); +} + static void fix_image_params(struct dec_video *d_video, struct mp_image_params *params) { @@ -258,8 +263,16 @@ static void fix_image_params(struct dec_video *d_video, } p.stereo_out = opts->video_stereo_mode; - // Detect colorspace from resolution. mp_colorspace_merge(&p.color, &c->color); + + // Sanitize the HDR peak. Sadly necessary + if (!is_valid_peak(p.color.sig_peak)) { + MP_WARN(d_video, "Invalid HDR peak in stream: %f\n", p.color.sig_peak); + p.color.sig_peak = 0.0; + } + + // Guess missing colorspace fields from metadata. This guarantees all + // fields are at least set to legal values afterwards. mp_image_params_guess_csp(&p); d_video->last_format = *params; -- cgit v1.2.3