occivink / mpv-image-viewer

Configuration, scripts and tips for using mpv as an image viewer
The Unlicense
284 stars 23 forks source link

Switch between video (mpv) and image (mvi) mode on the fly | with proposed solution #1

Closed jgreco closed 5 years ago

jgreco commented 5 years ago

Problem

I should be able to load a mixed content playlist and have zoom/pan functionality when viewing images but not when viewing video: mpv image.png video.mp4

The 'obvious' way of implementing this doesn't work:

[extension.jpg]
input-conf=~~/input-image.conf

I opened an issue with mpv about this a while ago but haven't heard anything, so I went looking for a work-around.

Work Around

Using add_hook("on_load"...) I can run a function that checks the "stream-open-filename" property to see if it's file extension is an image extension or not. Then I can either add or remove key bindings for image-viewer functions on the fly. When switching between files in the playlist, mpv will switch between video and image mode seamlessly.

Here is my proof of concept for this: https://github.com/jgreco/mpv-image-viewer/commit/f6234b294b0feead7bbc470ad3b6c05402fb421c

Test (with nothing special in mpv.conf) using something to the effect of: mpv image.png video.mp4

(This proof of concept only creates/removes bindings for drag_to_pan_handler and cursor_centric_zoom_handler (because those are the ones I personally use) but I think it should work in general. Also my proof of concept has keybindings hardcoded, it doesn't read them from any input.conf. I'm not sure if there is a way around this.)

occivink commented 5 years ago

I just noticed that there is a concept of "input sections" in mpv. Bindings defined in input.conf can be added to a "section" and sections can be enabled/disabled at runtime. I think that would be a satisfying solution

occivink commented 5 years ago

Ok I'm happy with this solution, it should be somewhat reliable. If you try it out, let me know if you find issues