-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic change of geometry, autofit, autofit-larger, autofit-smaller #8379
Comments
At the very least geometry can be set via IPC, as a property, though it doesn't apply to the currently-playing file, so you need to set it before loading the first file, or change it and then save watch later config and reload the current playlist. I don't know about autofit etc, but I imagine they might work too. |
Oh interesting. I tried setting it via IPC, but didn't wait to see that it changed at the next file. I'll just give that a try. It might be good enough for my use case, even though it'll need some extra work. |
The branch where wm4 implemented geometry runtime updates for X11 is still around if someone wants to start from that: e615e51 |
As that wm4 commit shows, it's not hard to implement this now (well ignoring any potential quirks from the windowing backend). Incidentally, I actually somewhat implemented this in wayland just yesterday (geometry/autofit/etc. updates if you change monitor). It would just take a few more lines to make it fully runtime. |
Is it supposed to work under Windows? Currently I am trying to send set geometry 100:100 through IPC pipe and then loadfile <filename> replace . And all I get is geometry: +100:+100 on player screen, just before the new file is loaded. |
Yes, and it does work (gets applied to the next loaded file) when set via a (mpv) script, so I'd imagine you're doing something wrong with your IPC commands. |
So, this snippet should move mpv window to x = 30 and y = 30 every time I play a new file? The file ( d:/new ) is successfully created each time I load new video. function on_start_video(event) {
mp.set_property("geometry", "30:30");
mp.utils.write_file("file://d:/new", "here");
}
mp.register_event("start-file", on_start_video); |
I don't know if move works, I was mainly referring to the size. As for whether it would work, probably not, because the event is delivered a-sync to the script, and by the time it's handled at the script - the file could have already started. A hook might be able to change it before the file is actually loaded. |
This changes size if used inside hook and inside event. But only for the first opened file. The code is supposed set window size to 400x400 for the first file and to 800x800 for the second and so on. But it only works for the first file, even though variable values are correctly set to 400 or 800. Am I doing something wrong? mp_size = 1;
function on_start_video(event) {
var width = 400;
var height = 400;
if (mp_size == 1) {
height = 800;
width = 800;
mp_size = 2;
} else {
mp_size = 1;
}
mp.set_property("geometry", width + "x" + height);
mp.utils.write_file("file://d:/logfile", "geometry = " + width + "x" + height);
}
mp.add_hook('on_load', 50, on_start_video)
//mp.register_event("start-file", on_start_video); |
Why so complex testing? Trying to change the size just when the file gets loaded could be racy (definitely with an event, not sure about hook, possibly depends on which hook, and maybe other factors). If you want to test whether geometry applies to the next loaded file, then just set two key bindings - one which sets one geometry size, and another which sets another size, then press the key, switch to the next file, and observe if it applied or not. |
Just in case mpv doesn't react if geometry is set to the same value, even if window size was changed manually.
Like that? Still works for the first opened file only. function resize_400x400(event) {
mp.set_property("geometry", "400x400");
mp.utils.write_file("file://d:/logfile", "geometry = 400x400");
}
function resize_800x800(event) {
mp.set_property("geometry", "800x800");
mp.utils.write_file("file://d:/logfile", "geometry = 800x800");
}
mp.add_key_binding("x", "resize_800x800", resize_800x800);
mp.add_key_binding("c", "resize_400x400", resize_400x400); I use this version of mpv
|
I have performed several experiments and look what I found out about mpv behaviour on Windows. Mpv only applies new geometry settings to a new file, if the new file has different resolution. If window is resized manually after that, mpv will keep the new window size. That is the behaviour I want, except for one small issue. I can't change aspect ration, when I resize the window. So I have to choose one aspect ratio, and then live with it. Maybe there's a way to resize mpv window manually, and not keep aspect ratio? Or, even better, maybe mpv could change aspect ratio, when opening files, but preserve window height? Here's a more detailed description of what I have discovered.Changing geometry with commandsIf I open mpv, then set geometry and then load file, mpv is going to resize the window according to geometry settings. And if I resize window by hand after that, mpv is not going to resize the window, when next file is loaded. But it's also not going to resize the window, if I change geometry. But if I change geometry, and then load a new file, having different resolution, mvp is going to apply new geometry settings. After I load the first file again, mpv will only resize the window, if I set new geometry value before loading the file. Resizing window by handIf I open mpv and then resize the window by hand and the load file, mpv will resize window to be exactly file size. mpv will keep window size, until I load a video, having different resolution. Mpv will resize the window every time a video with new resolution is loaded. |
I support this feature request, I'd love to be able to cycle through common video sizes and get best scaling quality. Cycling via |
@ahaoboy you can embed libmpv into Electron/Tauri, rendering mpv window with OpenGL API. Take a look at Electron example: But I don't like this approach much because of the reasons described here #5500 (comment) |
Setting
geometry
,autofit
,autofit-larger
orautofit-smaller
though IPC or scripts would be a very useful addition to have in MPV for a cross platform way to manage the window.Currently it is only possible to set at startup, which prevents programmatically changing the window position and size at runtime.
There are numerous use cases where this would be beneficial, and some useful discussion was had in #3872, but that unfortunately died out.
NB. I'd be willing to pay / sponsor to have this feature added if anyone would be interested in that.
The text was updated successfully, but these errors were encountered: