Samillion/mpv-ytdlautoformat

A simple mpv script that automatically adjusts ytdl-format (yt-dlp) for specified domains.

Lua

60

97 commits

updated Apr 10, 2026

See the code

README

mpv-ytdlAutoFormat

Terminal

A simple mpv script that automatically adjusts ytdl-format (yt-dlp) for specified domains.

If a domain match is found, the script sets ytdl-format based on predefined options. It also has a fallback mode, in case the custom ytdl-format was not found.

How is this script useful?

Some streaming websites lack multi-format options, meaning if ytdl-format in mpv.conf is set to 480p or 720p only, mpv/yt-dlp may fail to play videos without matching formats.

This script allows you to set video quality and codec for specific websites while keeping the default setting for others, ensuring smooth playback without constantly editing mpv.conf.

Options

To adjust options, simply change the values inside ytdlautoformat.conf (recommended) or adjust local options within the script.

# which domains should ytdl-format change on?
# separate each domain with a comma
domains=youtu.be, youtube.com, twitch.tv

# set maximum video quality (on load/start)
# 240, 360, 480, 720, 1080, 1440, 2160, 4320
# use 0 to ignore quality
quality=720

# preferred codec: avc, hevc, vp9, av1, novp9, noav1, none
# novp9/av1: accept any codec except vp9/av1
# none: no codec preference
codec=none

# maximum video fps
# set 0 to ignore
fps=0

# force a specific extension
force_extension=no
extension_type=mp4

# rare: to avoid mpv shutting down if nothing is found with the specified format
# if true, and format not found, it'll use fallback_format
fallback=yes
# an alternative: bv+ba/b
fallback_format=b

# respect manual format changes (ie: by a quality selector script)
respect_manual_changes=yes

# regex to detect urls
# a simpler pattern: ^%a+://
url_pattern=^[%a][%a%d+.-]*://

[!NOTE] The options only affect matched URLs from the domains list.

[!TIP] You can set a default value in mpv.conf for non-matched domains. You don't have to, but this gives you more control on all streams you play.

Examples for mpv.conf:

  • ytdl-format=bv[vcodec!~='^(vp0?9)']+ba/b

  • ytdl-format=bv[height<=1080][vcodec!~='^(vp0?9)']+ba/b[height<=1080]

How to install

Simply place ytdlautoformat.lua in the corresponding mpv scripts folder of your operating system:

  • Windows: %APPDATA%\mpv\scripts\ or C:\users\USERNAME\AppData\Roaming\mpv\scripts\
  • Linux: ~/.config/mpv/scripts/ or /home/USERNAME/.config/mpv/scripts/
  • Mac: ~/.config/mpv/scripts/ or /Users/USERNAME/.config/mpv/scripts/
πŸ“ mpv/
β”œβ”€β”€ πŸ“ script-opts/
β”‚   └── πŸ“„ ytdlautoformat.conf
└── πŸ“ scripts/
    └── πŸ“„ ytdlautoformat.lua

[!NOTE] More information about files locations can be found here

Alternatives

I prefer a simple mpv configuration, so I created this script to fit my basic use case.

However, there are excellent alternatives offering more dynamic options, such as:

  • mpv-quality-menu: Lets you change streamed video and audio quality (ytdl-format) on the fly.
  • mpv-selectformat: Plugin for selecting the format of internet videos.

These can be used alongside ytdlautoformat.lua without conflicts.

mpv
mpv-player
mpv-script

Contributors

Samillion

97 commits

Samillion/mpv-ytdlautoformat

A simple mpv script that automatically adjusts ytdl-format (yt-dlp) for specified domains.

Lua

60

97 commits

updated Apr 10, 2026

See the code

README

mpv-ytdlAutoFormat

Terminal

A simple mpv script that automatically adjusts ytdl-format (yt-dlp) for specified domains.

If a domain match is found, the script sets ytdl-format based on predefined options. It also has a fallback mode, in case the custom ytdl-format was not found.

How is this script useful?

Some streaming websites lack multi-format options, meaning if ytdl-format in mpv.conf is set to 480p or 720p only, mpv/yt-dlp may fail to play videos without matching formats.

This script allows you to set video quality and codec for specific websites while keeping the default setting for others, ensuring smooth playback without constantly editing mpv.conf.

Options

To adjust options, simply change the values inside ytdlautoformat.conf (recommended) or adjust local options within the script.

# which domains should ytdl-format change on?
# separate each domain with a comma
domains=youtu.be, youtube.com, twitch.tv

# set maximum video quality (on load/start)
# 240, 360, 480, 720, 1080, 1440, 2160, 4320
# use 0 to ignore quality
quality=720

# preferred codec: avc, hevc, vp9, av1, novp9, noav1, none
# novp9/av1: accept any codec except vp9/av1
# none: no codec preference
codec=none

# maximum video fps
# set 0 to ignore
fps=0

# force a specific extension
force_extension=no
extension_type=mp4

# rare: to avoid mpv shutting down if nothing is found with the specified format
# if true, and format not found, it'll use fallback_format
fallback=yes
# an alternative: bv+ba/b
fallback_format=b

# respect manual format changes (ie: by a quality selector script)
respect_manual_changes=yes

# regex to detect urls
# a simpler pattern: ^%a+://
url_pattern=^[%a][%a%d+.-]*://

[!NOTE] The options only affect matched URLs from the domains list.

[!TIP] You can set a default value in mpv.conf for non-matched domains. You don't have to, but this gives you more control on all streams you play.

Examples for mpv.conf:

  • ytdl-format=bv[vcodec!~='^(vp0?9)']+ba/b

  • ytdl-format=bv[height<=1080][vcodec!~='^(vp0?9)']+ba/b[height<=1080]

How to install

Simply place ytdlautoformat.lua in the corresponding mpv scripts folder of your operating system:

  • Windows: %APPDATA%\mpv\scripts\ or C:\users\USERNAME\AppData\Roaming\mpv\scripts\
  • Linux: ~/.config/mpv/scripts/ or /home/USERNAME/.config/mpv/scripts/
  • Mac: ~/.config/mpv/scripts/ or /Users/USERNAME/.config/mpv/scripts/
πŸ“ mpv/
β”œβ”€β”€ πŸ“ script-opts/
β”‚   └── πŸ“„ ytdlautoformat.conf
└── πŸ“ scripts/
    └── πŸ“„ ytdlautoformat.lua

[!NOTE] More information about files locations can be found here

Alternatives

I prefer a simple mpv configuration, so I created this script to fit my basic use case.

However, there are excellent alternatives offering more dynamic options, such as:

  • mpv-quality-menu: Lets you change streamed video and audio quality (ytdl-format) on the fly.
  • mpv-selectformat: Plugin for selecting the format of internet videos.

These can be used alongside ytdlautoformat.lua without conflicts.

mpv
mpv-player
mpv-script

Contributors

Samillion

97 commits

Languages

Lua

100.0%