I know how to set the initial player widow size by autofit=100%x100%
But, is there a way to create a hotkey in input.conf to achieve this?
I am on a Mac. Hope this feature can be added using "CMD+3" to "Fit the screen size", but not in full screen mode.
Thanks.
Use fullscreen mode?
Or rather, what's the problem with fullscreen mode?
hmm, consider it a low-priority feature request :dango:
Well, I still don't understand the purpose. Fullscreen mode does this, as far as I understand.
I will have to keep monitoring the servers tasking all time by getting a visual UL/DL speed on Menubar/Dock.
I think he doesn't want the video to be enveloped when fullscreen if the aspect is longer than his display.
I was trying to find this feature, too. For me, instead of binding set window-scale 1 with command+1, I would rather bind it with something which is same as autofit=50%x50% and bind command+2 with autofit=90%x90%, or some other ratio. It could be in pixels, too. Thanks for considering to add this feature.
Try --panscan=1.0
mpc-hc allows this using alt+4 (or alt+5) bindings, which can roughly be translated to --autofit=75%x75% and --autofit-larger=80%x80% (when considering entire window size and usually constrained by heigth) respectively.
I would love to have the ability to define commands for these "options" and thus hotkeys.
I made a script which looks like this:
function fit_to_screen()
scale = 1440.0 / mp.get_property("width")
mp.set_property("window-scale", scale)
end
mp.add_key_binding("meta+9", "Fit_Screen", fit_to_screen)
You can change "1440.0" to your screen width -- if you are using a macbook it should be the scaled resolution, not the native resolution.
Two problem remaining:
Hope it helps.
Shouldn't the window manager be doing this? On xmonad I just hit meta+f and my current window will cover the entire display (sans the informational bar at the top).
I am not so sure about xmonad on OSX...
I think Cmd-Z (Window » Zoom) already does this. Testing on 10.12.1 / mpv-0.22.0, it will shrink or grow the window such that it is as large as possible without going off the edge of the screen. Or am I misunderstanding the feature request?
@FrostedMint you are absolutely right, except that cmd+z won't work if you use the "border=no" option.
In fact, I think that the real problem is the native window manager in OSX will become invalid when using "border=no" option.
@FrostedMint This is just brilliant 💃
Edit: The final version of the script has been published on the wiki, along with a few other scripts:
https://github.com/mpv-player/mpv/wiki/User-Scripts
auto-keep-gui-open
Intelligently switches mpv's "keep-open" behavior based on whether you are running in video-mode or audio-only mode.
cycle-video-rotate
Allows you to perform video rotation which perfectly cycles through all 360 degrees without any glitches.
multi-command-if
Very powerful conditional logic and multiple action engine for your keybindings, without having to write a single line of code!
quick-scale
Quickly scale the video player to a target size, with full control over target scale and max scale. Helps you effortlessly resize a video to fit on your desktop, or any other video dimensions you need!
Old post:
@asd123cqp You're right... Cmd+Z does nothing in MPV for OS X if No-border mode is used...
I am therefore instead using the code you created. But I modified it to check the screen width AND height (to support VERTICAL videos) and to choose the smallest scale necessary to fit the video within the screen. There's no dock/menubar taken into account but whatever, this is better than having NO ability to "zoom to fit" when in no-border mode!
function fit_to_screen()
-- supports both horizontal and vertical videos and picks smallest scale
-- IMPORTANT: SET THIS TO YOUR NON-RETINA SCREEN RESOLUTION.
widthscale = 1680.0 / mp.get_property("width")
heightscale = 1050.0 / mp.get_property("height")
scale = (widthscale < heightscale and widthscale or heightscale)
mp.set_property_number("window-scale", scale)
end
mp.add_key_binding("meta+9", "Fit_Screen", fit_to_screen)
Save it to ~/.config/mpv/scripts/fit_to_screen.lua, so that it is auto-loaded every time mpv runs. Then just use Cmd+9 to "fit to screen".
PS: Another VERY worthwhile thing is to edit your mpv.conf and add these two lines:
geometry=50%:50%
autofit-larger=100%x100%
The first line ensures that the player starts in a centered position on the screen.
The second line means that if you open a video that would have been LARGER than your current screen's resolution, MPV will automatically scale it to be no wider/taller than 100% of your screen width/height (without changing aspect ratio). "autofit-larger" doesn't do anything at all if the video is smaller than the desktop. So this is a great solution for ensuring that massive videos (like 4K videos) don't play larger than your desktop size whenever you open MPV.
I tried to extend the script to also center the player. I think I may have found a bug.
I won't open a separate ticket about this, until I know whether this is a BUG on OS X:
mp.set_property("geometry", "50%:50%")
Does nothing. It's supposed to center the player. But maybe it doesn't work on ANY OS after the playback has already begun? Or does it work on Windows/Linux and this is just an OS X bug?
Edit: Also tried with input.conf. Fails there too. Does nothing except show "geometry: +50%+50%" on the OSD:
Meta+5 set geometry 50%:50%
geometry is normally only read when the window is first shown, on all platforms.
@wm4 Thanks for clarifying that it isn't a bug.
Edit: The final version of the script has been published on the wiki, along with a few other scripts:
https://github.com/mpv-player/mpv/wiki/User-Scripts
auto-keep-gui-open
Intelligently switches mpv's "keep-open" behavior based on whether you are running in video-mode or audio-only mode.
cycle-video-rotate
Allows you to perform video rotation which perfectly cycles through all 360 degrees without any glitches.
multi-command-if
Very powerful conditional logic and multiple action engine for your keybindings, without having to write a single line of code!
quick-scale
Quickly scale the video player to a target size, with full control over target scale and max scale. Helps you effortlessly resize a video to fit on your desktop, or any other video dimensions you need!
Old post:
@asd123cqp Here's the final code I came up with. Lets me scale the window to any bounds, automatically. Fullscreen. Small box. Etc. It is all easy.
--- Quickly scale the video player to a target size.
--
-- Parameters:
-- targetwidth = How wide you want the target area to be.
-- targetheight = How tall you want the target area to be.
-- targetscale = If this is 1, we use your target width/height
-- as-is, but if it's another value then we scale your provided
-- target size by that amount. This parameter is great if you want
-- a video to be a certain percentage of your desktop resolution.
-- In that case, just set targetwidth/targetheight to your
-- desktop resolution, and set this targetscale to the percentage
-- of your desktop that you want to use for the video, such as
-- "0.25" to resize the video to 25% of your desktop resolution.
-- maxvideoscale = If this is a positive number (anything above 0),
-- then the final video scale cannot exceed this number.
-- This is useful if you for example set the target to 25%
-- of your desktop resolution. If the video is smaller than that,
-- then it would be scaled up (enlarged) to the size of the target.
-- To control that behavior, simply set this parameter.
-- Here are some examples:
-- -1, 0, or any other non-positive number: We'll enlarge
-- too-small videos and shrink too-large videos. Small videos
-- will be enlarged as much as needed to match target size.
-- 1: Video will only be allowed to enlarge to 100% of its natural size.
-- This means that small videos won't become big and blurry.
-- 1.5: Video will only be allowed to enlarge to 150% of its natural size.
function quick_scale(targetwidth, targetheight, targetscale, maxvideoscale)
-- Check parameter existence.
if (targetwidth == nil or targetheight == nil
or targetscale == nil or maxvideoscale == nil)
then
mp.osd_message("Quick_Scale: Missing parameters")
return nil -- abort
end
-- Ensure that the incoming strings are valid numbers.
targetwidth = tonumber(targetwidth)
targetheight = tonumber(targetheight)
targetscale = tonumber(targetscale)
maxvideoscale = tonumber(maxvideoscale)
if (targetwidth == nil or targetheight == nil
or targetscale == nil or maxvideoscale == nil)
then
mp.osd_message("Quick_Scale: Non-numeric parameters")
return nil -- abort
end
-- If the target scale isn't 1 (100%), we'll re-calculate target size.
if (targetscale ~= 1) then
targetwidth = targetwidth * targetscale
targetheight = targetheight * targetscale
end
-- Find smallest video scale that fits target size in both width and height.
-- This only looks at video and doesn't take window borders into account!
widthscale = targetwidth / mp.get_property("width")
heightscale = targetheight / mp.get_property("height")
local scale = (widthscale < heightscale and widthscale or heightscale)
-- If we arrived at a target width/height that is larger than the video's
-- natural "100%" scale, then we may want to limit it to a maximum amount.
if (maxvideoscale > 0 and scale > maxvideoscale) then
scale = maxvideoscale
end
-- Apply the new video scale.
mp.set_property_number("window-scale", scale)
end
-- Bind this via input.conf. Examples:
-- To fit a video to 100% of a 1680x1050 desktop size, with unlimited video enlarging:
-- Alt+9 script-message Quick_Scale "1680" "1050" "1" "-1"
-- To fit a video to 80% of a 1680x1050 desktop size, but disallowing the
-- video from becoming larger than 150% of its natural size:
-- Alt+9 script-message Quick_Scale "1680" "1050" "0.8" "1.5"
-- To fit a video to a 200x200 box, with unlimited video enlarging:
-- Alt+9 script-message Quick_Scale "200" "200" "1" "-1"
mp.register_script_message("Quick_Scale", quick_scale)
@FichteFoll @Hrxn @homever Hey guys, I saw your thumbs up and thought I'd therefore let you know in case any of you have started using the script: I edited the message above to extend it with the super useful ability to set a "maxvideoscale".
It's very useful if you want to prevent the rescaling from ever going larger than the video's natural size.
For example, one of the things I do is: Resize the video to 80% of my 1680x1050 desktop, but never allow the video to become larger than 150% of its natural size. That prevents getting too much blurry enlarging if the video was low resolution.
You can still set the new max video scale parameter to -1 to allow unlimited enlarging, to literally fill up the whole requested target size even if your original video was only a postage-sized 5x5 pixels ;)
In terms of mpv, the new parameter _basically_ corresponds to:
# forcing a video to always become 90% of the screen.
# will enlarge small videos, and shrink large videos:
--autofit=90%x90%
script-message Quick_Scale "1680" "1050" "0.9" "-1"
# shrinking videos that are >90% of the screen
# to become max 90% of the screen. but keeping
# any smaller videos at their natural 1:1 scale:
--autofit-larger=90%x90%
script-message Quick_Scale "1680" "1050" "0.9" "1"
I've now published this and a few other scripts on the wiki:
https://github.com/mpv-player/mpv/wiki/User-Scripts
auto-keep-gui-open
Intelligently switches mpv's "keep-open" behavior based on whether you are running in video-mode or audio-only mode.
cycle-video-rotate
Allows you to perform video rotation which perfectly cycles through all 360 degrees without any glitches.
multi-command-if
Very powerful conditional logic and multiple action engine for your keybindings, without having to write a single line of code!
quick-scale
Quickly scale the video player to a target size, with full control over target scale and max scale. Helps you effortlessly resize a video to fit on your desktop, or any other video dimensions you need!
They're all finalized and working perfectly. But if there are ever updated versions, they'll be published there too.
@SteveJobzniak great job man! I wish geometry is modifiable via hotkey – then your script would be perfect!
@asd123cqp Glad I could help.
And geometry being modifiable via hotkey (so that we can move mpv's window with just the keyboard/a script), is what this other ticket is about: https://github.com/mpv-player/mpv/issues/3872. Please give your votes/comments/+1 there to give your support for that feature. ;-)
sounds like this was solved with a script.
@chella1cm it's work for me,many thanks
Most helpful comment
Try --panscan=1.0