# MPV - mpv.conf
# classicjazz - 2022-07-02

# Details about configuring MPV for high quality video are covered here: https://freetime.mikeconnelly.com/archives/5371
# The latest version of this file is located here: https://github.com/classicjazz/mpv-config

# All MPV options are covered here: https://github.com/mpv-player/mpv/blob/master/DOCS/man/options.rst
# All of my upscaling calculations assume a native 4K resolution display
# Additionally, my target displays all support HDR, so tone-mapping for SDR is not necessary

# I am slowly incorporating changes anticipating using vo=gpu-next in the future
# https://github.com/mpv-player/mpv/wiki/GPU-Next-vs-GPU

# This config file assumes that you are using a version of MPV that supports Conditional Profiles (i.e. auto-profiles.lau is no longer required). Tested with mpv v0.34.1

###########
# General #
###########

# Default profile
# vo=libmpv # used for MacOS
# macos-force-dedicated-gpu=yes # comment this out for any OS other than MacOS
profile=gpu-hq # used for any other OS on modern hardware
# profile=gpu-next # for future use

# Selected API: select either Vulkan (preferred) or OpenGL
# Note: MacOS devices are currently limited to OpenGL v4.1 (which is deprecated). For iOS/tvOS/MacOS devices, Metal v2 would be preferred but there is not currently a Metal backend. In the future, a workaround may be to use mpv + libplacebo + MoltenVK

# OpenGL settings
# gpu-api=opengl

# Vulkan settings
gpu-api=vulkan
gpu-context=wayland
vulkan-async-compute=yes
vulkan-async-transfer=yes
vulkan-queue-count=1
vd-lavc-dr=yes

hwdec=auto # enable best HW decoder; turn off for software decoding
reset-on-next-file=audio-delay,pause,speed,sub-delay,video-aspect-override,video-pan-x,video-pan-y,video-rotate,video-zoom,mute,volume


######
# UI #
######

# border=no # hide the window title bar
# macos-title-bar-material=dark
msg-color=yes # color log messages on terminal
term-osd-bar=yes # display a progress bar on the terminal
# no-hidpi-window-scale # used on 5K iMac to prevent scaling by OSX
force-window=immediate
cursor-autohide=1000 # autohide the curser after 1s
# geometry=3840x2160 # force 4k resolution output from on Macs, rather than using MacOS upscaling
fullscreen = yes # start in fullscreen mode by default
loop-file=yes

save-position-on-quit=no
volume=100
mute=yes


############
# Playback #
############

deinterlace=no # global reset of deinterlacing to off


##############
# Colorspace #
##############

# see https://github.com/mpv-player/mpv/wiki/Video-output---shader-stage-diagram
target-prim=auto
# target-prim=bt.709 # target Rec.709 for SDR TVs
# target-prim=bt.2020 # target Rec.2020 (wide color gamut) for HDR TVs
target-trc=auto
gamma-auto
vf=format=colorlevels=full:colormatrix=auto
# vf=format=yuv420p,vapoursynth=~~/motioninterpolation.vpy:4:4 # Interpolate by default
video-output-levels=full


##########
# Dither #
##########

dither-depth=auto
temporal-dither=yes
# dither=error-diffusion # preferable... mpv will fallback on fruit if compute shaders are not supported
dither=fruit

#############
# Debanding #
#############

deband=yes # enabled by default
deband-iterations=4 # deband steps
deband-threshold=48 # deband strength
deband-range=16 # deband range
deband-grain=48 # dynamic grain: set to "0" if using the static grain shader


#############
# Subtitles #
#############

blend-subtitles=yes


#########################
# Motion Interpolation  #
#########################

override-display-fps=60
# video-sync=display-resample
# interpolation=yes
# tscale=oversample # smoothmotion


################
# Anti-Ringing #
################

scale-antiring=0.7 # luma upscale deringing
dscale-antiring=0.7 # luma downscale deringing
cscale-antiring=0.7 # chroma upscale deringing


#############################################################
# Upscaling & Processing Based on Source Video's Resolution #
#############################################################

# Chroma subsampling means that chroma information is encoded at lower resolution than luma
# In MPV, chroma is upscaled to luma resolution (video size) and then the converted RGB is upscaled to target resolution (screen size)
# For detailed analysis of upscaler/downscaler quality, see https://artoriuz.github.io/blog/mpv_upscaling.html

# fbo-format=rgba16f # use with gpu-api=opengl
fbo-format=rgba16hf # use with gpu-api=vulkan
# fbo-format is not not supported in gpu-next profile

# NOTE: I don't know why but these shaders don't make any noticable difference to me (am I blind?)...
# glsl-shaders-clr
# luma upscaling
# note: any FSRCNNX above FSRCNNX_x2_8-0-4-1 is not worth the additional computional overhead
# glsl-shaders-append="~~/shaders/FSRCNNX_x2_8-0-4-1.glsl"
# scale=ewa_lanczos

# luma downscaling
# note: ssimdownscaler is tuned for mitchell and downscaling=no
# glsl-shaders-append="~~/shaders/SSimDownscaler.glsl"
# dscale=mitchell
# linear-downscaling=no

# chroma upscaling and downscaling
# glsl-shaders-append="~~/shaders/KrigBilateral.glsl"
# cscale=mitchell # ignored with gpu-next
# sigmoid-upscaling=yes

# NOTE: FSR makes a clearly visible difference so use that
glsl-shaders-append="~~/shaders/FSR.glsl"

############
# Profiles #
############

# [4k60] # 2160p @ 60fps (3840x2160 UHDTV)
# profile-desc=4k60
# profile-cond=((width ==3840 and height ==2160) and p["estimated-vf-fps"]>=31)
# # deband=yes # necessary to avoid blue screen with KrigBilateral.glsl
# deband=no # turn off debanding because presume wide color gamut
# interpolation=no # turn off interpolation because presume 60fps
# # UHD videos are already 4K so no luma upscaling is needed
# # UHD videos are YUV420 so chroma upscaling is still needed
# glsl-shaders-clr
# # glsl-shaders="~/.config/mpv/shaders/KrigBilateral.glsl" # enable if your hardware can support it
# interpolation=no # no motion interpolation required because 60fps is hardware ceiling
# # no deinterlacer required because progressive
#
# [4k30] # 2160p @ 24-30fps (3840x2160 UHDTV)
# profile-cond=((width ==3840 and height ==2160) and p["estimated-vf-fps"]<31)
# # deband=yes # necessary to avoid blue screen with KrigBilateral.glsl
# deband=no # turn off debanding because presume wide color gamut
# # UHD videos are already 4K so no luma upscaling is needed
# # UHD videos are YUV420 so chroma upscaling is still needed
# glsl-shaders-clr
# # glsl-shaders="~/.config/mpv/shaders/KrigBilateral.glsl" # enable if your hardware can support it
# # apply motion interpolation
# # no deinterlacer required because progressive
#
# [full-hd60] # 1080p @ 60fps (progressive ATSC)
# profile-desc=full-hd60
# profile-cond=((width ==1920 and height ==1080) and not p["video-frame-info/interlaced"] and p["estimated-vf-fps"]>=31)
# # apply all luma and chroma upscaling and downscaling settings
# interpolation=no # no motion interpolation required because 60fps is hardware ceiling
# # no deinterlacer required because progressive
#
# [full-hd30] # 1080p @ 24-30fps (NextGen TV/ATSC 3.0, progressive Blu-ray)
# profile-desc=full-hd30
# profile-cond=((width ==1920 and height ==1080) and not p["video-frame-info/interlaced"] and p["estimated-vf-fps"]<31)
# # apply all luma and chroma upscaling and downscaling settings
# # apply motion interpolation
# # no deinterlacer required because progressive
#
# [full-hd-interlaced] # 1080i @ 24-30fps (HDTV, interlaced Blu-rays)
# profile-desc=full-hd-interlaced
# profile-cond=((width ==1920 and height ==1080) and p["video-frame-info/interlaced"] and p["estimated-vf-fps"]<31)
# # apply all luma and chroma upscaling and downscaling settings
# # apply motion interpolation
# vf=bwdif # apply FFMPEG's bwdif deinterlacer
#
# [hd] # 720p @ 60 fps (HDTV, Blu-ray - progressive)
# profile-desc=hd
# profile-cond=(width ==1280 and height ==720)
# # apply all luma and chroma upscaling and downscaling settings
# interpolation=no # no motion interpolation required because 60fps is hardware ceiling
# # no deinterlacer required because progressive
#
# [sdtv-ntsc] # 640x480, 704x480, 720x480 @ 30fps (NTSC DVD - interlaced)
# profile-desc=sdtv-ntsc
# profile-cond=((width ==640 and height ==480) or (width ==704 and height ==480) or (width ==720 and height ==480))
# # apply all luma and chroma upscaling and downscaling settings
# # apply motion interpolation
# vf=bwdif # apply FFMPEG's bwdif deinterlacer
#
# [sdtv-pal] # 352x576, 480x576, 544x576, 720x576 @ 30fps (PAL broadcast or DVD - interlaced)
# profile-desc=sdtv-pal
# profile-cond=((width ==352 and height ==576) or (width ==480 and height ==576) or (width ==544 and height ==576) or (width ==720 and height ==576))
# # apply all luma and chroma upscaling and downscaling settings
# # apply motion interpolation
# vf=bwdif # apply FFMPEG's bwdif deinterlacer
#
# [default]
#
#
# ###################################
# # Protocol Specific Configuration #
# ###################################
#
# [protocol.http]
# hls-bitrate=max # use max quality for HLS streams
# cache=yes
# no-cache-pause # don't pause when the cache runs low
#
# [protocol.https]
# profile=protocol.http
#
# [protocol.ytdl]
# profile=protocol.http
