|
local mp = require 'mp' |
|
|
|
-- Configuration |
|
local autovsr_enabled = true -- Default to VSR enabled |
|
|
|
-- Function to apply VSR with dynamic scaling |
|
local function apply_vsr() |
|
-- Get video and display properties |
|
local video_width = mp.get_property_number("width") |
|
local video_height = mp.get_property_number("height") |
|
local display_width = mp.get_property_number("display-width") |
|
local display_height = mp.get_property_number("display-height") |
|
local codec = mp.get_property("video-codec", "") |
|
local pixelformat = mp.get_property("video-params/pixelformat", "") |
|
|
|
-- Validate properties |
|
if not (video_width and video_height and display_width and display_height and codec and pixelformat) then |
|
mp.osd_message("RTX VSR: Missing video properties, retrying...", 1) |
|
return |
|
end |
|
|
|
-- Calculate scale factor and round to nearest 0.1 |
|
local scale = math.max(display_width / video_width, display_height / video_height) |
|
scale = scale - (scale % 0.1) |
|
|
|
-- Remove existing filters only if they exist |
|
local vf_chain = mp.get_property("vf", "") |
|
if vf_chain:find("@format-nv12") then |
|
mp.commandv("vf", "remove", "@format-nv12") |
|
end |
|
if vf_chain:find("@vsr") then |
|
mp.commandv("vf", "remove", "@vsr") |
|
end |
|
|
|
-- Apply VSR if upscaling is needed |
|
if scale > 1 then |
|
-- Apply format=nv12 for Main 10 HEVC (H.265 + 10-bit formats: p10le or p010) |
|
if codec:lower():match("hevc") or codec:lower():match("h%.265") then |
|
if pixelformat:match("p10le$") or pixelformat == "p010" then |
|
mp.commandv("vf", "append", "@format-nv12:format=nv12") |
|
mp.osd_message("RTX VSR ON: Applied nv12 for Main 10 HEVC", 1) |
|
end |
|
end |
|
mp.commandv("vf", "append", "@vsr:d3d11vpp:scaling-mode=nvidia:scale=" .. scale) |
|
end |
|
end |
|
|
|
-- Function to toggle VSR |
|
local function toggle_vsr() |
|
autovsr_enabled = not autovsr_enabled |
|
|
|
if autovsr_enabled then |
|
apply_vsr() |
|
mp.observe_property("video-params", "native", apply_vsr) |
|
mp.observe_property("vf", "native", apply_vsr) |
|
mp.osd_message("RTX VSR ON") |
|
else |
|
mp.commandv("vf", "remove", "@format-nv12") |
|
mp.commandv("vf", "remove", "@vsr") |
|
mp.unobserve_property(apply_vsr) |
|
mp.osd_message("RTX VSR OFF") |
|
end |
|
end |
|
|
|
-- Apply VSR automatically on video load |
|
mp.register_event("file-loaded", function() |
|
if autovsr_enabled then |
|
apply_vsr() |
|
mp.observe_property("video-params", "native", apply_vsr) |
|
mp.observe_property("vf", "native", apply_vsr) |
|
end |
|
end) |
|
|
|
-- Keybinding for VSR toggle |
|
mp.add_key_binding("ctrl+shift+r", "autovsr", toggle_vsr) |