# options, profiles, etc:
# - example config: <https://thewiki.moe/tutorials/mpv/>
# - example config: <https://iamscum.wordpress.com/guides/videoplayback-guide/mpv-conf/>
# - available options and their defaults: `mpv --list-options`
#   or `man mpv`
# - default profiles: <https://github.com/mpv-player/mpv/blob/master/etc/builtin.conf>
#   or: `mpv --profile=help`
#   or: `mpv --show-profile=high-quality` (etc)
#   - about auto profiles: <https://mpv.io/manual/stable/#conditional-auto-profiles>

# write ~/.local/state/mpv/watch_later on exit, to allow resume
save-position-on-quit=yes
# identify resumed files by filename only, since i use so many symlinks and doubt mpv does well with that.
ignore-path-in-watch-later-config

# keep-open: don't exit on completion of last file in playlist
keep-open=yes
# seeking once at the end of the file causes auto-resume
keep-open-pause=no

# force GUI, even for tracks w/o album art
# see: <https://www.reddit.com/r/mpv/comments/rvrrpt/oscosdgui_and_arch_linux/>
# player-operation-mode=pseudo-gui
# actually, prefer just a subset of what's enabled by pseudo-gui, else logging breaks
force-window=yes

# no mouse-drag-to-reposition-mpv, since that doesn't work on most tiling managers and it interferes with image-positioning.lua
window-dragging=no
# input-preprocess-wheel=no

# use uosc instead (for On Screen Controls)
osc=no
# uosc provides its own seeking/volume indicators, so you also don't need this
osd-bar=no
# uosc will draw its own window controls if you disable window border
border=no

# # ao=alsa so that uosc can work with ao-volume (see my uosc patch)
# ao=alsa
# # with `ao-volume`, the max actually is 100.
# # to go higher you'll have to use the system's native controls.
# volume-max=100

# backend compatibility (2023/10/22):
# run with `--vo=help` to see a list of all output options.
# non-exhaustive (W=works, F=fails, A=audio-only, U=audio+ui only (no video))
# ? null             Null video output
# A (default)
# A dmabuf-wayland   Wayland dmabuf video output
# A libmpv           render API for libmpv  (mpv plays the audio, but doesn't even render a window)
# A vdpau            VDPAU with X11
# F drm              Direct Rendering Manager (software scaling)
# F gpu-next         Video output based on libplacebo
# F vaapi            VA API with X11
# F x11              X11 (software scaling)
# F xv               X11/Xv
# U gpu              Shader-based GPU Renderer
# W caca             libcaca  (terminal rendering)
# W sdl              SDL 2.0 Renderer
# W wlshm            Wayland SHM video output (software scaling)
# vo=wlshm

# audio and subtitle language preferences
alang=en,eng,ja,jp,jpn
slang=en,eng
# show subtitles more immediately when seeking through video
demuxer-mkv-subtitle-preroll=yes
# sub-auto=exact (default)|fuzzy|all
# fuzzy means to load subs if their filename includes the filename of the video, even if it contains extras
sub-auto=fuzzy

cache=yes
# how many forward bytes into the video (stream or file) to cache
demuxer-max-bytes=1024MiB
# how many bytes backward into the video (stream or file) to keep in memory
demuxer-max-back-bytes=2048MiB
# demuxer-readahead-secs=20
prefetch-playlist=yes

# don't auto-play the next image
# N.B.: i override this later in case the playlist looks like an album
image-display-duration=inf

# debanding: good test case is 2001: A Space Oddyssey at 54:00
deband=yes
# iterations: 1-16 (default: 1). quality v.s. compute tradeoff. values > 4 are "practically useless".
# - each iteration increases the range, but decreases the threshold
# on lappy: i can notice a difference between 1 and 4 (4 is def better),
# on lappy: the difference between 2 and 4 is there but very subtle.
# on lappy: everything above 3 looks *basically* the same as 3. maybe relevant for HDR displays
# on lappy, there is an observable perf difference between 1 and 3. it's irrelevant for 1080p h.264, but comes into play for 4K h.265.
#   so, default the iterations count to `1`, and selectively increase it on more capable devices/profiles.
deband-iterations=1
# threshold: 0-4096 (default: 48). higher value = higher strength, but lose details.
deband-threshold=72
# range: 1-64 (default: 16). a higher radius finds more gradients, but a lower radius smooths more aggressively. this is increased per iteration, so one should lower this here if using a high iteratio count.
# OTOH, i find that a higher range lets me get away with a higher threshold without losing real detail.
deband-range=20
# grain: 0-4096 (default: 32): inject noise (post-deband; across the whole image) to mask remaining quantization artifacts. higher values needed for poor sources.
# i'm disabling that, because it's not really the job of a deband filter to cover up block artifacts
deband-grain=0

# set e.g. `profile=fast` to make that the default profile.
# in fact, it's more like inheriting everything from that profile into the default profile.
# toplevel `profile=fast` does not work, AND, [default]profile=default doesn't work,
profile=@defaultProfile@

[high-quality]
# this extends the builtin `high-quality` profile
# - <https://github.com/mpv-player/mpv/blob/e8d14cd3142b117eabf23df026ee946cfded6424/etc/builtin.conf#L53>
deband-iterations=3

[mid-range]
# keep this here even if empty. `profile=default` is NOT supported by mpv, so we have to do `profile=mid-range` if we want to be general

[fast]
# this extends the builtin `fast` profile
# - <https://github.com/mpv-player/mpv/blob/e8d14cd3142b117eabf23df026ee946cfded6424/etc/builtin.conf#L43>
deband=no

[audio]
# when playing an album, and we hit album art, just automatically skip it.
# in a playlist setting this activates when an audio/video item becomes the active playlist item,
# and the config updates here persist across future playlist items (until/unless they're overriden by those items profiles)
# `p["audio-codec"]` parameter can be found in <repo:mpv-player/mpv:player/command.c>
profile-cond=get("audio-codec", "")
image-display-duration=2

[music]
# never resume music files (but still resume other audio files e.g. podcasts)
profile-cond=(get("working-directory", "") .. "/" .. get("path", "")):find("Music/")
watch-later-options-remove=start
# XXX(2024/11/25): resume-playback option is processed early -- before auto-profiles are fully evaluated,
#   but watch-later-options-remove=... or save-position-on-quit=... are processed later
# resume-playback=no
