summaryrefslogtreecommitdiffstats
path: root/player/lua/stats.lua
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-08-29 10:24:08 +0200
committerNiklas Haas <github-daiK1o@haasn.dev>2023-08-29 20:58:44 +0200
commit15ada7c41cdc3943666ddf281be69f58cddc1143 (patch)
tree43d985ab7226098a323667c233a09120f8af198c /player/lua/stats.lua
parent3cf71fd7c7f5d4052b67ebdf11ff416a9beffbeb (diff)
downloadmpv-15ada7c41cdc3943666ddf281be69f58cddc1143.tar.bz2
mpv-15ada7c41cdc3943666ddf281be69f58cddc1143.tar.xz
stats.lua: display hdr metadata and peak detection
Diffstat (limited to 'player/lua/stats.lua')
-rw-r--r--player/lua/stats.lua73
1 files changed, 67 insertions, 6 deletions
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