Skip to content

Instantly share code, notes, and snippets.

@haasn
Last active March 11, 2024 06:57
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save haasn/7919afd765e308fa91cbe19a64631d0f to your computer and use it in GitHub Desktop.
Save haasn/7919afd765e308fa91cbe19a64631d0f to your computer and use it in GitHub Desktop.
mvi - set of configuration for turning mpv into an image viewer
-- Allow changing a property with by zoom-adjusted amount
function zoom_invariant_add(prop, amt)
amt = amt / 2 ^ mp.get_property_number("video-zoom")
mp.set_property_number(prop, mp.get_property_number(prop) + amt)
end
-- Resets the pan if the entire image would be visible
function zoom_check_center()
local zoom = mp.get_property_number("video-zoom")
local rot = mp.get_property_number("video-rotate") * math.pi / 180
local scaled = not mp.get_property_bool("video-unscaled")
local dw = mp.get_property_number("dwidth") * 2 ^ zoom
local dh = mp.get_property_number("dheight") * 2 ^ zoom
-- Adjust for rotation
local asr = math.abs(math.sin(rot)); acr = math.abs(math.cos(rot))
dw, dh = dw*acr + dh*asr, dh*acr + dw*asr
-- No property seems to exist for the actual window size, try this instead
local ow = mp.get_property_number("osd-width")
local oh = mp.get_property_number("osd-height")
if (dw <= ow and dh <= oh) or (scaled and zoom <= 0.0) then
mp.set_property_number("video-pan-x", 0)
mp.set_property_number("video-pan-y", 0)
end
end
-- Rotates the video while maintaining 0 <= prop < 360
function rotate_video(amt)
local rot = mp.get_property_number("video-rotate")
rot = (rot + amt) % 360
mp.set_property_number("video-rotate", rot)
end
mp.add_key_binding(nil, "zoom-invariant-add", zoom_invariant_add)
mp.add_key_binding(nil, "zoom-check-center", zoom_check_center)
mp.add_key_binding(nil, "rotate-video", rotate_video)
# Easier image navigation
h repeatable script-message zoom-invariant-add video-pan-x 0.2
l repeatable script-message zoom-invariant-add video-pan-x -0.2
k repeatable script-message zoom-invariant-add video-pan-y 0.2
j repeatable script-message zoom-invariant-add video-pan-y -0.2
ctrl+h repeatable script-message zoom-invariant-add video-pan-x 0.02
ctrl+l repeatable script-message zoom-invariant-add video-pan-x -0.02
ctrl+k repeatable script-message zoom-invariant-add video-pan-y 0.02
ctrl+j repeatable script-message zoom-invariant-add video-pan-y -0.02
+ add video-zoom 0.5
- add video-zoom -0.5; script-message zoom-check-center
= no-osd set video-zoom 0; script-message zoom-check-center
MOUSE_BTN3 add video-zoom 0.1
MOUSE_BTN4 add video-zoom -0.1
# sxiv compatibility
w no-osd set video-unscaled yes; keypress =
e no-osd set video-unscaled no; keypress =
BS repeatable playlist-prev
SPACE repeatable playlist-next
ENTER playlist-next force
ESC quit
RIGHT repeatable playlist-next
LEFT repeatable playlist-prev
UP ignore
DOWN ignore
CTRL+RIGHT script-message rotate-video 90
CTRL+LEFT script-message rotate-video -90
CTRL+DOWN no-osd set video-rotate 0
# Toggling between pixel-exact reproduction and interpolation
a cycle deband; cycle-values scale nearest ewa_lanczossharp
# Toggle color management on or off
c cycle icc-profile-auto
# Screenshot of the window output
S screenshot window
# For Argon-/mpv-stats (optional)
# J script_binding stats
# Toggle aspect ratio information on and off
A cycle-values video-aspect "-1" "no"
[nodir]
sub-auto=no
audio-file-auto=no
[image]
profile=nodir
profile=opengl-hq
mute=yes
scale=ewa_lanczossharp
background=0.1
input-conf=~~/input-image.conf
video-unscaled=yes
title="mvi - ${?media-title:${media-title}}${!media-title:No file}"
image-display-duration=inf
loop-file=yes
[extension.gif]
interpolation=no
# Ignore aspect ratio information for PNG and JPG, because it's universally bust
[extension.png]
video-aspect=no
[extension.jpg]
video-aspect=no
[extension.jpeg]
profile=extension.jpg
@haasn
Copy link
Author

haasn commented Jun 3, 2016

Oh btw, recommended usage:

alias mvi='mpv -profile image'

Copy link

ghost commented Dec 23, 2016

Could you make it work more like sxiv? (e.g. jump to first/last image, skip 10 images, and show left top corner automatically)

@haasn
Copy link
Author

haasn commented Dec 29, 2016

@kjnirlp: mpv doesn't expose commands for that (feel free to make an issue though), but in practice I just hold down the BS / space buttons and I'll end up on the first/last image after like a second. But I have a pretty high key repeat rate.

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