Created
May 27, 2023 20:33
-
-
Save stt/9e55ffa7f5047605b2dd8af417cf36f0 to your computer and use it in GitHub Desktop.
mpv script for changing active screen based on video's aspect ratio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment