
# Uses GPU-accelerated video output by default.
#vo=gpu
# Can cause performance problems with some GPU drivers and GPUs.
#profile=gpu-hq

# ===== REMOVE THE ABOVE FOUR LINES AND RESAVE IF YOU ENCOUNTER PLAYBACK ISSUES AFTER =====

# Source: https://github.com/hl2guide/better-mpv-config

# External Sources:
# * https://raw.githubusercontent.com/classicjazz/mpv-config/master/mpv.conf

# Enables best HW decoder; turn off for software decoding
hwdec=auto

border=no # hides the window title bar
msg-color=yes # color log messages on terminal
term-osd-bar=yes # displays a progress bar on the terminal
cursor-autohide=1000 # autohides the cursor after 1s

# Sets a custom font
osd-font='JetBrainsMono Nerd Font Light'
# osd-font-size=55
# osd-scale=0.5

# Saves the seekbar position on exit
save-position-on-quit=yes

# Uses a large seekable RAM cache even for local input.
cache=yes
# cache-secs=300
# Uses extra large RAM cache (needs cache=yes to make it useful).
demuxer-max-bytes=1800M
demuxer-max-back-bytes=1200M

# Sets the profile restore method to "copy if equal"
profile-restore=copy-equal

# ===== Audio =====

# Sets volume to 60%.
volume=60

# Normalizes audio
af-add='dynaudnorm=g=5:f=250:r=0.9:p=0.5'

# ===== Color Space =====
target-trc=auto
gamma-auto
vf=format=colorlevels=full:colormatrix=auto
video-output-levels=full

# ===== Dithering =====
dither-depth=auto
temporal-dither=yes
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 =====
glsl-shaders-clr
# luma upscaling
# note: any FSRCNNX above FSRCNNX_x2_8-0-4-1 is not worth the additional computional overhead
glsl-shaders="/home/matt/.config/mpv/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="/home/matt/.config/mpv/shaders/SSimDownscaler.glsl"
dscale=mitchell
linear-downscaling=no
# chroma upscaling and downscaling
glsl-shaders-append="/home/matt/.config/mpv/shaders/KrigBilateral.glsl"
cscale=mitchell
sigmoid-upscaling=yes

# ===== Custom Profiles =====
# Uses specific naming convensions for shorter easier typing.
# Naming Convensions:
# V = Very Low, L = Low, M = Medium, H = High, U = Ultra, S = Supreme
# Very Low = 480p, Low = 720p, Medium = 1080p, High = 1440p, Ultra = 2160p (4K), Supreme = 4320p (8K)
# 30 = 30 frames per second, 60 = 60 frames per second
# Use the switch e.g: --profile=H60
# 4320p (8K) 60 FPS
[S60]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc="Supereme - 4320p (8K) - 60 FPS"
ytdl-format=bestvideo[height<=?4320][fps<=?60][vcodec!=?vp9]+bestaudio/best
# 4320p (8K) 30 FPS
[S30]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc="Supereme - 4320p (8K) - 30 FPS"
ytdl-format=bestvideo[height<=?4320][fps<=?30][vcodec!=?vp9]+bestaudio/best
# 2160p (4K) 60 FPS
[U60]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc="Ultra - 2160p (4K) - 60 FPS"
ytdl-format=bestvideo[height<=?2160][fps<=?60][vcodec!=?vp9]+bestaudio/best
# 2160p (4K) 30 FPS
[U30]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc="Ultra - 2160p (4K) - 30 FPS"
ytdl-format=bestvideo[height<=?2160][fps<=?30][vcodec!=?vp9]+bestaudio/best
# 1440p 60 FPS
[H60]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc="High - 1440p - 60 FPS"
ytdl-format=bestvideo[height<=?1440][fps<=?60][vcodec!=?vp9]+bestaudio/best
# 1440p 30 FPS
[H30]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc="High - 1440p - 30 FPS"
ytdl-format=bestvideo[height<=?1440][fps<=?30][vcodec!=?vp9]+bestaudio/best
# 1080p 60 FPS
[M60]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc="Medium - 1080p - 60 FPS"
ytdl-format=bestvideo[height<=?1080][fps<=?60][vcodec!=?vp9]+bestaudio/best
# 1080p 30 FPS
[M30]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc="Medium - 1080p - 30 FPS"
ytdl-format=bestvideo[height<=?1080][fps<=?30][vcodec!=?vp9]+bestaudio/best
# 720p 60 FPS
[L60]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc="Low - 720p - 60 FPS"
ytdl-format=bestvideo[height<=?720][fps<=?60][vcodec!=?vp9]+bestaudio/best
# 720p 30 FPS
[L30]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc="Low - 720p - 30 FPS"
ytdl-format=bestvideo[height<=?720][fps<=?30][vcodec!=?vp9]+bestaudio/best
# 480p 60 FPS
[V60]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc="Very Low - 480p - 60 FPS"
ytdl-format=bestvideo[height<=?480][fps<=?60][vcodec!=?vp9]+bestaudio/best
# 480p 30 FPS
[V30]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc="Very Low - 480p - 30 FPS"
ytdl-format=bestvideo[height<=?480][fps<=?30][vcodec!=?vp9]+bestaudio/best

# Other Profiles

[4k60] # 2160p @ 60fps (3840x2160 UHDTV)
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
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-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc=4k30
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-restore=copy-equal # Sets the profile restore method to "copy if equal"
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-restore=copy-equal # Sets the profile restore method to "copy if equal"
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-restore=copy-equal # Sets the profile restore method to "copy if equal"
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-restore=copy-equal # Sets the profile restore method to "copy if equal"
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-restore=copy-equal # Sets the profile restore method to "copy if equal"
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-restore=copy-equal # Sets the profile restore method to "copy if equal"
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]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"

# ===== File Type Profiles =====
# GIF Files
[extension.gif]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc=gif
cache=no
no-pause
loop-file=yes
# WebM Files
[extension.webm]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc=webm
no-pause
loop-file=yes

# ===== Protocol Specific Configuration =====

[protocol.http]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc=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-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc=https
profile=protocol.http

[protocol.ytdl]
profile-restore=copy-equal # Sets the profile restore method to "copy if equal"
profile-desc=ytdl
profile=protocol.http