From 15ada7c41cdc3943666ddf281be69f58cddc1143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Tue, 29 Aug 2023 10:24:08 +0200 Subject: stats.lua: display hdr metadata and peak detection --- player/lua/stats.lua | 73 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 6 deletions(-) (limited to 'player/lua') diff --git a/player/lua/stats.lua b/player/lua/stats.lua index a1d881eefb..a003b1af0c 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -695,6 +695,66 @@ local function append_resolution(s, r, prefix, w_prop, h_prop) end +local function pq_eotf(x) + if not x then + return x; + end + + local PQ_M1 = 2610.0 / 4096 * 1.0 / 4 + local PQ_M2 = 2523.0 / 4096 * 128 + local PQ_C1 = 3424.0 / 4096 + local PQ_C2 = 2413.0 / 4096 * 32 + local PQ_C3 = 2392.0 / 4096 * 32 + + x = x ^ (1.0 / PQ_M2) + x = max(x - PQ_C1, 0.0) / (PQ_C2 - PQ_C3 * x) + x = x ^ (1.0 / PQ_M1) + x = x * 10000.0 + + return x +end + + +local function append_hdr(s, hdr) + if not hdr then + return + end + + if (hdr["max-cll"] and hdr["max-cll"] > 203) or + hdr["max-luma"] and hdr["max-luma"] > 203 then + append(s, "", {prefix="HDR10:"}) + if hdr["min-luma"] and hdr["max-luma"] and hdr["max-luma"] > 203 then + append(s, format("%.2g / %.0f", hdr["min-luma"], hdr["max-luma"]), + {prefix="Mastering display:", suffix=" cd/m²", nl=""}) + end + if hdr["max-cll"] and hdr["max-cll"] > 203 then + append(s, hdr["max-cll"], {prefix="maxCLL:", suffix=" cd/m²", nl=""}) + end + if hdr["max-fall"] and hdr["max-fall"] > 0 then + append(s, hdr["max-fall"], {prefix="maxFALL:", suffix=" cd/m²", nl=""}) + end + end + + if hdr["scene-max-r"] or hdr["scene-max-g"] or + hdr["scene-max-b"] or hdr["scene-avg"] then + append(s, "", {prefix="HDR10+:"}) + append(s, format("%.1f / %.1f / %.1f", hdr["scene-max-r"] or 0, + hdr["scene-max-g"] or 0, hdr["scene-max-b"] or 0), + {prefix="MaxRGB:", suffix=" cd/m²", nl=""}) + append(s, format("%.1f", hdr["scene-avg"] or 0), + {prefix="Avg:", suffix=" cd/m²", nl=""}) + end + + if hdr["max-pq-y"] and hdr["avg-pq-y"] then + append(s, "", {prefix="PQ(Y):"}) + append(s, format("%.2f cd/m² (%.2f%% PQ)", pq_eotf(hdr["max-pq-y"]), + hdr["max-pq-y"] * 100), {prefix="Max:", nl=""}) + append(s, format("%.2f cd/m² (%.2f%% PQ)", pq_eotf(hdr["avg-pq-y"]), + hdr["avg-pq-y"] * 100), {prefix="Avg:", nl=""}) + end +end + + local function add_video(s) local r = mp.get_property_native("video-params") local ro = mp.get_property_native("video-out-params") @@ -763,13 +823,14 @@ local function add_video(s) append(s, r["colormatrix"], {prefix="Colormatrix:"}) append(s, r["primaries"], {prefix="Primaries:", nl=""}) append(s, r["gamma"], {prefix="Transfer:", nl=""}) - -- Append HDR metadata conditionally (only when present and interesting) - local hdrpeak = r["sig-peak"] or 0 - if hdrpeak > 1 then - append(s, format("%.0f", hdrpeak * 203), - {prefix="(HDR peak", suffix=" nits)", nl="", - indent=" ", prefix_sep=": ", no_prefix_markup=true}) + + local hdr = mp.get_property_native("hdr-metadata") + if not hdr then + local hdrpeak = r["sig-peak"] or 0 + hdr = {["max-cll"]=math.floor(hdrpeak * 203)} end + + append_hdr(s, hdr) append_property(s, "packet-video-bitrate", {prefix="Bitrate:", suffix=" kbps"}) append_filters(s, "vf", "Filters:") end -- cgit v1.2.3