Skip to content
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

Closed
porsager opened this issue Dec 8, 2020 · 15 comments · Fixed by #13626
Closed

Dynamic change of geometry, autofit, autofit-larger, autofit-smaller #8379

porsager opened this issue Dec 8, 2020 · 15 comments · Fixed by #13626

Comments

@porsager
Copy link
Contributor

porsager commented Dec 8, 2020

Setting geometry, autofit, autofit-larger or autofit-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.

@avih
Copy link
Member

avih commented Dec 8, 2020

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.

@porsager
Copy link
Contributor Author

porsager commented Dec 8, 2020

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.

@guidocella
Copy link
Contributor

The branch where wm4 implemented geometry runtime updates for X11 is still around if someone wants to start from that: e615e51

@Dudemanguy
Copy link
Member

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.

@poxu
Copy link

poxu commented Jan 19, 2021

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.

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.

@avih
Copy link
Member

avih commented Jan 19, 2021

Is it supposed to work under Windows?

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.

@poxu
Copy link

poxu commented Jan 27, 2021

Yes, and it does work (gets applied to the next loaded file) when set via a (mpv) script

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); 

@avih
Copy link
Member

avih commented Jan 27, 2021

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.

@poxu
Copy link

poxu commented Jan 28, 2021

I don't know if move works, I was mainly referring to the size.

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); 

@avih
Copy link
Member

avih commented Jan 28, 2021

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.

@poxu
Copy link

poxu commented Jan 28, 2021

Why so complex testing?

Just in case mpv doesn't react if geometry is set to the same value, even if window size was changed manually.

If you want to test whether geometry applies to the next loaded file, then just set two key binding

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

mpv 0.33.0-62-ga3e440c611 Copyright © 2000-2020 mpv/MPlayer/mplayer2 projects
 built on Sun Jan 17 21:07:40 +08 2021

@poxu
Copy link

poxu commented Jan 30, 2021

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 commands

If 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 hand

If 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.

@bananakid
Copy link

I support this feature request, I'd love to be able to cycle through common video sizes and get best scaling quality. Cycling via window-scale can't return correct sizes due to window-scale ratio precision limit. Hope this request gets implemented eventually!

@ahaoboy
Copy link

ahaoboy commented Jan 17, 2024

This feature could potentially change the ecosystem of mpv UI scripts. If we can control the window position through IPC, we can implement a UI using a different technology stack, such as using Tauri to create widgets for mpv. The current main issues with AssUI are its inability to extend beyond the screen and the performance and usability issues with mujs. Taking the UI of potplayer as an example, the middle video area could use a transparent background div, allowing the mpv player to be positioned beneath the Tauri window. This way, the entire web ecosystem can be utilized to provide a UI interface for mpv. Additionally, certain plugins could benefit from this, like thumbfast.lua, eliminating the need for capturing, saving, and then drawing images to the screen. It would only require configuring the position, size, and event axis of a UI-less mpv player.
image

@Kagami
Copy link
Contributor

Kagami commented Jan 17, 2024

@ahaoboy you can embed libmpv into Electron/Tauri, rendering mpv window with OpenGL API. Take a look at Electron example:
https://github.com/Kagami/mpv.js
https://github.com/Kagami/mpv.js#applications-using-mpvjs
More libmpv examples here: https://github.com/mpv-player/mpv-examples/tree/master/libmpv

But I don't like this approach much because of the reasons described here #5500 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants