Skip to content

Instantly share code, notes, and snippets.

@stt
Created May 27, 2023 20:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stt/9e55ffa7f5047605b2dd8af417cf36f0 to your computer and use it in GitHub Desktop.
Save stt/9e55ffa7f5047605b2dd8af417cf36f0 to your computer and use it in GitHub Desktop.
mpv script for changing active screen based on video's aspect ratio
-- 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