Using mpv with YouTube is a popular way to watch videos from the terminal with fewer ads, keyboard control, and high performance. mpv relies on yt-dlp (or sometimes youtube-dl) to fetch the stream.
Hereโs the full setup and usage.
โ 1) Install mpv and yt-dlp#
On Linux:
Debian / Ubuntu#
sudo apt install mpv yt-dlpArch#
sudo pacman -S mpv yt-dlpVoid Linux#
sudo xbps-install -S mpv yt-dlpAlpine#
sudo apk add mpv yt-dlpโถ๏ธ 2) Play a YouTube Video#
Just pass the URL:
mpv https://www.youtube.com/watch?v=VIDEO_IDmpv automatically calls yt-dlp and starts streaming.
๐บ 3) Play in Best Quality / Limit Resolution#
Force max 1080p:#
mpv --ytdl-format="bestvideo[height<=1080]+bestaudio/best" URL720p:#
mpv --ytdl-format="best[height<=720]" URL๐ 4) Audio Only (Music / Podcasts)#
mpv --no-video URLOr:
mpv --ytdl-format=bestaudio URL๐ 5) Play a Playlist#
mpv handles playlists automatically:
mpv https://www.youtube.com/playlist?list=XXXXXLimit number of videos:
mpv --playlist-start=1 --playlist-end=10 URLโฏ๏ธ Useful mpv Keys#
While playing:
| Key | Action |
|---|---|
| Space | Pause |
| โ / โ | Seek 5s |
| โ / โ | Seek 1 min |
| 9 / 0 | Volume |
| f | Fullscreen |
| q | Quit |
| s | Screenshot |
โ๏ธ 6) Recommended Config#
Create:
mkdir -p ~/.config/mpv
nano ~/.config/mpv/mpv.confExample:
hwdec=auto
ytdl-format=bestvideo+bestaudio/best
cache=yes
cache-secs=30โ If YouTube Stops Working#
Usually YouTube changes somethingโupdate yt-dlp:
yt-dlp -Uor via package manager:
sudo xbps-install -Su yt-dlp๐ง Extra Tips#
Use cookies (for age-restricted/private videos):#
Export cookies from your browser, then:
mpv --cookies --cookies-file cookies.txt URLDownload instead of stream:#
yt-dlp URL