Skip to main content

Watch YouTube Videos with mpv Player - Complete Guide

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-dlp

Arch
#

sudo pacman -S mpv yt-dlp

Void Linux
#

sudo xbps-install -S mpv yt-dlp

Alpine
#

sudo apk add mpv yt-dlp

โ–ถ๏ธ 2) Play a YouTube Video
#

Just pass the URL:

mpv https://www.youtube.com/watch?v=VIDEO_ID

mpv 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" URL

720p:
#

mpv --ytdl-format="best[height<=720]" URL

๐Ÿ”Š 4) Audio Only (Music / Podcasts)
#

mpv --no-video URL

Or:

mpv --ytdl-format=bestaudio URL

๐Ÿ“ƒ 5) Play a Playlist
#

mpv handles playlists automatically:

mpv https://www.youtube.com/playlist?list=XXXXX

Limit number of videos:

mpv --playlist-start=1 --playlist-end=10 URL

โฏ๏ธ Useful mpv Keys
#

While playing:

KeyAction
SpacePause
โ† / โ†’Seek 5s
โ†‘ / โ†“Seek 1 min
9 / 0Volume
fFullscreen
qQuit
sScreenshot

โš™๏ธ 6) Recommended Config#

Create:

mkdir -p ~/.config/mpv
nano ~/.config/mpv/mpv.conf

Example:

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 -U

or 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 URL

Download instead of stream:
#

yt-dlp URL

Youcef
Author
Youcef
My name is youcef and i’m linux user who fool in love with linux , like free and open software .