Skip to content

Instantly share code, notes, and snippets.

@natyusha
Forked from azumukupoe/autovsr.lua
Last active June 21, 2025 18:37
Show Gist options
  • Save natyusha/e230a176d41e3092676c4e941ded406a to your computer and use it in GitHub Desktop.
Save natyusha/e230a176d41e3092676c4e941ded406a to your computer and use it in GitHub Desktop.
AutoVSR for MPV w/ HEVC Main 10 Support

AutoVSR for MPV

This Lua script automatically enables NVIDIA Video Super Resolution (VSR) in MPV

Features:

  • Dynamically adjusts scaling based on display and video resolution
  • Applies nv12 pixel format to 10bit HEVC as it is unsupported by VSR otherwise
  • Toggle with Ctrl+Shift+R (default: on)

Usage:

  1. Enable "Super Resolution" under "RTX Video Enhancements" in the Nvidia App
  2. Place autovsr.lua in your MPV scripts folder
  3. Restart MPV
  4. Press Ctrl+Shift+R to toggle VSR

🔗 Original discussion comment: mpv-player/mpv#14804

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment