mpv script for changing active screen based on video's aspect ratio

May 27, 2023 ยท View on GitHub

-- change-screen-by-aspect-ratio.lua -- (c)2023, stt

-- mpv script for systems with 2+ monitors in portrait and landscape orientation, -- when new video starts in fullscreen the active screen is changed based on -- video's aspect ratio

-- NOTE: edit the script with screen numbers based on your screen configuration

function checkAspectRatio() local videoParams = mp.get_property_native("video-params") -- in case of e.g. lavfi-complex there can be no input video, only output if not videoParams then videoParams = mp.get_property_native("video-out-params") end if not videoParams then return end local width = videoParams["w"] local height = videoParams["h"] local aspectRatio = width / height -- mp.msg.warn("aspect", aspectRatio) if aspectRatio > 1 then -- landscape mp.set_property("fs-screen", "0") else -- portrait mp.set_property("fs-screen", "1") end end

function onFileLoaded() checkAspectRatio() end

mp.register_event("file-loaded", onFileLoaded)