Can MPV Play YouTube Videos Directly with yt-dlp?
This article provides a quick overview and practical guide on how the
MPV media player integrates with yt-dlp to stream YouTube
videos directly from the command line or a graphical interface. We will
cover the core compatibility between these tools, how to configure them
for optimal performance, and how to troubleshoot common playback
issues.
Wait, the prompt says “Don’t create any horizontal rules in the article.” Let me remove that.
Can MPV Play YouTube Videos Directly with yt-dlp?
This article provides a quick overview and practical guide on how the
MPV media player integrates with yt-dlp to stream YouTube
videos directly from the command line or a graphical interface. We will
cover the core compatibility between these tools, how to configure them
for optimal performance, and how to troubleshoot common playback
issues.
Direct Playback and Integration
Yes, MPV can play YouTube videos directly out of the box by
leveraging yt-dlp (or its predecessor,
youtube-dl). When you pass a YouTube URL to MPV, it
automatically calls the backend downloader in the background to parse
the video streams, fetch the direct media links, and feed them into the
player.
To play a video, you simply need to run a basic command in your terminal:
mpv https://www.youtube.com/watch?v=dQw4w9WgXcQ
This native integration allows you to enjoy an ad-free, lightweight viewing experience without opening a resource-heavy web browser.
Requirements and Setup
For the integration to work seamlessly, you need both programs installed on your system, and MPV must be able to locate the downloader binary.
- Installation: Ensure both
mpvandyt-dlpare installed via your package manager (likeapt,brew, orpacman) or downloaded directly from their official repositories. - PATH Environment: The
yt-dlpexecutable must be in your system’s PATH so MPV can invoke it automatically. - Hook Configuration: By default, MPV is compiled
with a script called
ytdl_hook. This script manages the communication between the player and the extraction tool.
Configuring Video Quality
By default, MPV will request the best available quality from YouTube,
which often defaults to 4K or 1080p. If you have a slow internet
connection or want to save bandwidth, you can configure your preferred
resolution using the --ytdl-format flag.
Command Line Examples
- Play at a maximum of 1080p:
mpv --ytdl-format="bestvideo[height<=1080]+bestaudio/best" URL - Play at 720p to save data:
mpv --ytdl-format="bestvideo[height<=720]+bestaudio/best" URL
Permanent Configuration
To avoid typing these flags every time, you can add them to your
permanent MPV configuration file (mpv.conf), typically
located in ~/.config/mpv/ on Linux/macOS or
%APPDATA%/mpv/ on Windows:
ytdl-format=bestvideo[height<=1080]+bestaudio/best
Troubleshooting Common Issues
Because YouTube frequently updates its platform, the streaming integration can occasionally break. Here is how to handle the most common issues:
Playback Fails or Buffers Infinitely
This usually happens when YouTube changes its video delivery
algorithms. Because MPV relies on yt-dlp to parse these
URLs, keeping the downloader updated is essential. Update your extractor
using the following command:
yt-dlp -U
MPV Cannot Find yt-dlp
If MPV errors out stating it cannot parse the URL, it might be
looking for the older youtube-dl binary instead. You can
explicitly tell MPV to use yt-dlp by adding this line to
your mpv.conf:
script-opts=ytdl_hook-ytdl_path=yt-dlp