profile=high-quality
user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
glsl-shaders="" # Disable heavy shaders for regular content
# glsl-shaders="~~/shaders/ArtCNN_C4F32_DS.glsl"
# glsl-shaders="~~/shaders/ArtCNN_C4F32.glsl"
scale=spline36 # Faster than ewa_lanczos for high-res video when shaders are off
dither=fruit # Lighter dithering aimed at 8-bit or FRC panels

# --- Window & interface ---
ontop=yes
border=no
no-border
# autofit=50% # Start at half of the screen to avoid oversized windows on UHD displays
geometry=1920x1080
osc=no
blend-subtitles=video # Keeps subtitles composited into the video plane
opengl-early-flush=no # Delay buffer flushes to reduce micro-stutter on some GPUs

# --- Subtitle defaults ---
sub-font="JetBrainsMono Nerd Font"
sub-font-size=45
sub-auto=fuzzy
slang=en,eng
subs-with-matching-audio=no
sub-fix-timing=yes
sub-ass-override=scale
sub-gauss=1.0
sub-gray=yes
sub-pos=95

# --- Audio chain ---
volume=75
ao=pipewire
# audio-spdif=ac3,dts-hd,truehd
audio-stream-silence=yes # Keep the device primed to avoid startup pops
audio-wait-open=0.1 # Shorten audio device warm-up for snappier playback

# --- Networking & remote sources ---
ytdl-format=bestvideo+bestaudio/best
ytdl-raw-options=sub-langs=en.*,write-auto-subs=
ytdl-raw-options-append=extractor-args=youtubepot-bgutilhttp:base_url=http://tubearchivist:4416

# --- Video output & decoding ---
vo=gpu-next
hwdec=nvdec
hwdec-codecs=all
gpu-api=vulkan
gpu-context=waylandvk
vulkan-queue-count=2
vulkan-async-compute=yes # Use independent compute queues for tone mapping/shaders
vulkan-async-transfer=yes # Parallelize frame uploads to free the graphics queue
vd-lavc-dr=yes # Direct rendering keeps frames resident on the GPU longer
vd-lavc-threads=0 # Let ffmpeg auto-pick the optimal thread count
video-sync=display-resample # Smoothly match video speed to the display refresh

# --- Scaling, interpolation, and dithering ---
scale=ewa_lanczossharp
dscale=catmull_rom
cscale=ewa_lanczos
tscale=oversample
interpolation=yes
interpolation-preserve=no
interpolation-threshold=0.5 # Only blend nearby frames to reduce SOE artifacts
sigmoid-upscaling=yes # Protect highlights when upscaling SDR video
temporal-dither=yes # Prefer temporal noise over spatial patterns on SDR panels
# Dithering presets reference:
#   fruit   -> 8-bit / 8-bit + FRC displays
#   ordered -> True 10-bit / 12-bit displays
#   error-diffusion -> High-end GPUs
dither=error-diffusion
dither-depth=auto
error-diffusion=sierra-lite # Balanced diffusion kernel for 8-bit panels

# --- Antiring controls ---
scale-antiring=0.5
dscale-antiring=0.5
cscale-antiring=0.5

# --- Post-processing ---
deband=yes
deband-iterations=2
deband-threshold=24
deband-range=16
deband-grain=4

# --- IPC & automation ---
input-ipc-server=/tmp/mpvsocket # Allows external tools (e.g., SVP) to control mpv

# --- Screenshot workflow ---
screenshot-format=webp
screenshot-webp-lossless=yes
screenshot-high-bit-depth=yes
screenshot-sw=no # Force GPU path so tone mapping stays consistent
screenshot-directory="/truenas/sudacode/pictures/mpv"
screenshot-template="%f-%wH.%wM.%wS.%wT-#%#00n"

# --- Session persistence ---
save-position-on-quit
watch-later-dir="~~/.watch-later"
resume-playback=yes
save-watch-history
watch-history-path="~~/state/watch_history.jsonl"

# --- HDR/SDR hints ---
target-colorspace-hint=yes

# --- Caching & buffers ---
cache=yes
demuxer-max-bytes=1GiB # Buffer up to 1 GiB for high-bitrate remuxes
demuxer-max-back-bytes=200MiB # Keep recent data handy for quick reverse seeks
cache-secs=30
demuxer-readahead-secs=30

# no, fatal, warn, info, v, debug, trace
msg-level=subs2srs,animecards,mpvacious=error
msg-level=subminer=warn

[anime]
profile-desc="Anime upscaling with ArtCNN"
glsl-shaders="~~/shaders/ArtCNN_C4F32_DS.glsl"
scale=ewa_lanczossharp
dither=error-diffusion
deband=yes # Crucial for anime gradients

[movies]
profile-desc="Movies and TV shows"
profile-cond=width >= 1920 and filename:match("mkv$|mp4$")
glsl-shaders=""
scale=ewa_lanczos
target-peak=800

[hdr]
profile-desc=HDR content
profile-cond=get("video-params/gamma", "") == "pq" or get("video-params/gamma", "") == "hlg"
profile-restore=copy
tone-mapping-param=0.5
tone-mapping-max-boost=2.0
allow-delayed-peak-detect=yes
# For SDR content on HDR display (or vice versa)
icc-profile-auto=yes

[sdr]
profile-desc=SDR content
profile-cond=get("video-params/gamma", "") ~= "pq" and get("video-params/gamma", "") ~= "hlg"
profile-restore=copy
# put SDR-only tweaks here
deband=yes
target-colorspace-hint=auto

[svp]
interpolation=no
input-ipc-server=/tmp/mpvsocket
hr-seek-framedrop=no
resume-playback=no

[Idle]
profile-cond=p["idle-active"]
profile-restore=copy-equal
title=' '
keepaspect=no

[subminer]
cookies=yes
cookies-file=/truenas/sudacode/japanese/youtube-cookies.txt
ytdl-format=bestvideo+bestaudio/best
ytdl-raw-options=mark-watched=
ytdl-raw-options-append=write-auto-subs=
ytdl-raw-options-append=sub-langs=ja.*|en|ja-en
ytdl-raw-options-append=cookies=/truenas/sudacode/japanese/youtube-cookies.txt
sub-auto=fuzzy
sid=auto
secondary-sid=auto
secondary-sub-visibility=no
alang=ja,jp,jpn,japanese,en,eng,english,English,enUS,en-US
slang=ja,jp,jpn,japanese,en,eng,english,English,enUS,en-US
vlang=ja,jpn
subs-with-matching-audio=yes
sub-font="M PLUS 1 Medium"
glsl-shaders="~~/shaders/ArtCNN_C4F32.glsl"
scale=ewa_lanczossharp
dither=error-diffusion
deband=yes # Crucial for anime gradients
input-ipc-server=/tmp/subminer-socket

[anime-subs]
profile-cond=p["slang"] == "ja" or p["slang"] == "ja.hi"
sub-font="M PLUS 1 Medium"
# sub-font="Source Han Sans JP"
sub-bold=no
sub-font-size=46
sub-color=1.0/1.0/1.0/0.98
sub-border-color=0.0/0.0/0.0/0.80
sub-border-size=1.3
sub-shadow-color=0.0/0.0/0.0/0.35
sub-shadow-offset=2
sub-back-color=0.0/0.0/0.0/0.12
sub-margin-x=24
sub-margin-y=18
sub-italic=no
sub-ass-override=strip
sub-line-spacing=0.3
sub-hinting=light
demuxer-mkv-subtitle-preroll=yes
