From daa36731ef860e8303c6905b3defb3e3a81a0320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 21 Dec 2021 16:22:08 +0800 Subject: [PATCH] Use FFMPEG to check for mastering display metadata, for enabling Display-P3 primaries Ref: https://github.com/mpv-player/mpv/issues/9620 --- iina/VideoView.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/iina/VideoView.swift b/iina/VideoView.swift index a7cb353d8a..c50ea7e4d7 100644 --- a/iina/VideoView.swift +++ b/iina/VideoView.swift @@ -284,7 +284,20 @@ extension VideoView { return false; } - guard let primaries = mpv.getString(MPVProperty.videoParamsPrimaries), let gamma = mpv.getString(MPVProperty.videoParamsGamma) else { return false } + guard var primaries = mpv.getString(MPVProperty.videoParamsPrimaries), var gamma = mpv.getString(MPVProperty.videoParamsGamma) else { return false } + + // Because MPV won't check for mastering display metadata, we have to check it ourselves + // TODO: Supports multi-track video source. Maps MPV `player.info.vid` to FFMPEG `streamIndex` + if primaries == "bt.2020" && !player.info.isNetworkResource && player.info.videoTracks.count == 1 { + if let path = mpv.getString(MPVProperty.path), let colorspaceData = FFmpegController.getColorSpaceMetadata(forFile: path) { + if let _primaries = colorspaceData["primaries"] as? String { + primaries = _primaries + } + if let _gamma = colorspaceData["color-trc"] as? String { + gamma = _gamma + } + } + } var name: CFString? = nil; switch primaries {