If you have ever used the CLI tools yt-dlp or youtube-dl then you should know that youtube serves video and audio as separate files as shown below. By using yt-dlp with --get-url, we can feed the video and audio URLs to mpv.
If you are having problems getting this to work you can jump straight to Troubleshooting or How to Fix.
Example of Available Formats (youtube)
ID EXT RESOLUTION FPS CH β FILESIZE TBR PROTO β VCODEC VBR ACODEC ABR ASR MORE INFO
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
233-20 mp4 audio only β m3u8 β audio only unknown [en-US] American English - original (original)
234-20 mp4 audio only β m3u8 β audio only unknown [en-US] American English - original (original)
249-drc webm audio only 2 β 15.90MiB 51k https β audio only opus 51k 48k [en-US] English (US), low, DRC, webm_dash
250-20 webm audio only 2 β 21.16MiB 68k https β audio only opus 68k 48k [en-US] English (US), low, webm_dash
140-drc m4a audio only 2 β 40.30MiB 129k https β audio only mp4a.40.2 129k 44k [en-US] English (US), medium, DRC, m4a_dash
251-drc webm audio only 2 β 37.88MiB 122k https β audio only opus 122k 48k [en-US] English (US), medium, DRC, webm_dash
140-20 m4a audio only 2 β 40.30MiB 129k https β audio only mp4a.40.2 129k 44k [en-US] English (US), medium, m4a_dash
251-20 webm audio only 2 β 37.89MiB 122k https β audio only opus 122k 48k [en-US] English (US), medium, webm_dash
135 mp4 854x480 30 β 176.75MiB 568k https β avc1.4D401F 568k video only 480p, mp4_dash
136 mp4 1280x720 30 β 503.24MiB 1617k https β avc1.4D401F 1617k video only 720p, mp4_dash
247 webm 1280x720 30 β 333.80MiB 1072k https β vp9 1072k video only 720p, webm_dash
299 mp4 1920x1080 60 β 1.49GiB 4889k https β avc1.64002A 4889k video only 1080p60, mp4_dash
303 webm 1920x1080 60 β 881.79MiB 2833k https β vp9 2833k video only 1080p60, webm_dash
315 webm 3840x2160 60 β 7.83GiB 25762k https β vp9 25762k video only 2160p60, webm_dash
401 mp4 3840x2160 60 β 3.72GiB 12227k https β av01.0.13M.08 12227k video only 2160p60, mp4_dash
MPV has an --audio-file parameter and that URL can be obtained using the --get-url switch of yt-dlp (which we will obtain with bash command substitution):
Method #1: Ad-hoc Command
mpv --audio-file=$(yt-dlp -f "bestaudio[ext=webm][acodec^=opus]/bestaudio" --get-url https://youtu.be/3mhctWlXyV8) $(yt-dlp -f "bestvideo[height=1080][vcodec^=vp9]/bestvideo[vcodec^=avc1]/bestvideo" --get-url https://youtu.be/3mhctWlXyV8)
The following does exactly the same thing, but it includes some optional cache-related parameters.
mpv \
--cache=yes \
--demuxer-max-bytes=100MiB \
--cache-secs=30 \
--audio-file=$(yt-dlp -f "bestaudio[ext=webm][acodec^=opus]/bestaudio" --get-url https://youtu.be/3mhctWlXyV8) \
$(yt-dlp -f "bestvideo[height=1080][vcodec^=vp9]/bestvideo[vcodec^=avc1]/bestvideo" --get-url https://youtu.be/3mhctWlXyV8)
Method #2: Bash Function (preferred)
We can turn that into a bash function and increase functionality by utilizing xclip in addition to yt-dlp. Make sure you have both installed (sudo apt install xclip yt-dlp).
function mpvyt () {
YT_INPUT="${1:-$(xclip -o 2>/dev/null)}"
[ -n "$YT_INPUT" ] && mpv --cache=yes --demuxer-max-bytes=100MiB --cache-secs=30 --audio-file=$(yt-dlp -f "bestaudio[ext=webm][acodec^=opus]/bestaudio" --get-url "$YT_INPUT") $(yt-dlp -f "bestvideo[height=1080][vcodec^=vp9]/bestvideo[vcodec^=avc1]" --get-url "$YT_INPUT") || (echo "Either input Youtube URL or copy one to your clipboard";exit 1)
}
To use the function, either copy a youtube video link to your clipboard or provide the youtube URL as a positional parameter and then run the function by typing mpvyt.
Troubleshooting
If mpv is failing to play the youtube video and you are seeing errors such as:
β’ [ffmpeg] https: HTTP error 403 Forbidden
β’ [stream] Failed to open https://rr1---sn-qja5mc-5j.googlevideo.com
β’ [ytdl_hook] ERROR: [generic] videoplayback?expire=1795182203
β’ Unable to download webpage: HTTP Error 403: Forbidden (caused by <HTTPError 403: Forbidden>)
β’ [ytdl_hook] youtube-dl failed: unexpected error occurred
then the basic troubleshooting steps requires isolating the problem to either yt-dlp or mpv. Even though there are only 2 options, this can become complicated since mpv and yt-dlp both use similar libraries but with differing dependency levels.
Continue reading below for troubleshooting info and possible workarounds.
βοΈWhy It Happens Only with Certain YouTube Videos
When mpv passes a stream URL from yt-dlp to ffmpeg, YouTube may reject the ffmpeg request with HTTP 403 Forbidden due to expired/mismatched stream URLs, missing session context/cookies, or rate/bot checks on certain streams.
Increasingly this seems to be caused by YouTube restricting content that can be streamed without authentication.
YouTube now enforces Proof of Origin (PO) Tokens on web and mweb clientsβespecially when logged-in cookies are passed without a PO token provider, or when a JavaScript challenge solver is missing.
When yt-dlp extracts stream URLs using default,mweb with cookies-from-browser=chrome, YouTube allows the initial format lookup, then rejects ffmpeg's direct connection to googlevideo.com with HTTP error 403 Forbidden.
Recent yt-dlp builds rely on an external JavaScript runtime (like Deno or Node.js) to solve YouTube's n-parameter signature challenge. If that challenge fails, yt-dlp falls back to broken/403 URLs.
- Run
yt-dlp -vF <URL>in your terminal on one of the failing videos. - Look for
WARNING: [youtube] ... n challenge solving failed. - If you see it, install Deno (the default JS runtime yt-dlp looks for) via the official Deno Linux installation guide or
sudo apt install nodejson Debian/Ubuntu so yt-dlp can solve stream signatures cleanly.
π οΈ How to Fix
Update yt-dlp and mpv first, as youtube regularly updates playback restrictions and stream tokens that break older extractors or stream handling.
- Update yt-dlp: Run
yt-dlp -U(if installed via standalone binary/pip) or upgrade through your system package manager so stream URLs match YouTube's current requirements. - Update mpv: Install a recent build of mpv, as newer versions include stream/timeout fixes for YouTube playback. See Issue #18391 on mpv for details on recent yt-dlp and mpv fixes.
- Test yt-dlp directly: Run
yt-dlp -F <URL>or test downloading/playing through yt-dlp to confirm whether yt-dlp extracts valid formats for that specific video. - Check
mpv/yt-dlpflags and config: Review yourmpv.conforytdl-formatsettings to make sure no outdated format filters or custom headers/cookies options are conflicting withffmpeg. - Check network/IP blocks: If you use a VPN, proxy, or shared IP, YouTube may block certain stream requests with a
403. You can also compare notes in this Unix & Linux Stack Exchange thread on mpv 403 errors. [1, 2, 3]
- Update ytdl-raw-options in mpv.conf
Use the mpv.conf options below, or removeytdl-raw-optionsentirely and ensure you are not passing browser cookies (ytdl-raw-options=cookies-from-browser=chrome) unless you have a PO-token plugin installed. Test switching to clients that don't strictly require a desktop web PO token, such asweb_embeddedorandroid:
script-opts=ytdl_hook-ytdl_path=/usr/local/bin/yt-dlp
ytdl-raw-options=extractor-args="youtube:player_client=web_embedded,default"
- Check for Missing JS Runtime (EJS) Warnings
Recent yt-dlp builds rely on an external JavaScript runtime (like Deno or Node.js) to solve YouTube'sn-parameter signature challenge. If that challenge fails, yt-dlp falls back to broken/403 URLs. [1, 2]
β’ Runyt-dlp -vF <URL>in your terminal on one of the failing videos.
β’ Look forWARNING: [youtube] ... n challenge solving failed.
β’ If you see it, install Deno (the default JS runtime yt-dlp looks for) via the official Deno Linux installation guide orsudo apt install nodejson Debian/Ubuntu so yt-dlp can solve stream signatures cleanly. [1, 2] - If You Must Use Cookies (e.g., for Age-Restricted / Member Videos)
If you needcookies-from-browser=chrometo stay signed in,mwebandwebwill keep returning403unless you run a PO token provider alongside yt-dlp, such as the bgutil-ytdlp-pot-provider plugin on GitHub. [1, 2] - Test yt-dlp on Its Own (Checks JS Runtime & Extraction)
Run this command on one of the failing videos:yt-dlp -v -o - "<failing_url>" > /dev/null- If
yt-dlpitself fails withHTTP Error 403: Forbidden: Look near the top of the verbose output for:WARNING: [youtube] No supported JavaScript runtime could be foundorn challenge solving failed.
On Debian/Ubuntu, yt-dlp nightly needs Deno or Node.js to unscramble stream signatures for ad-monetized videos (which use stricter SABR/n-sig enforcement). Install Deno via the Deno Linux installation guide or Node viasudo apt install nodejs, clear yt-dlp's cache (yt-dlp --rm-cache-dir), and test again. - If yt-dlp downloads it fine, but mpv still throws
[ffmpeg] https: HTTP error 403 Forbidden:That means mpv's ytdl_hook script or ffmpeg is dropping session data or hitting a client (tv_simply / tv_samsung / ios / web) whose stream URLs ffmpeg can't open directly.
- If
- Bypass mpv's ytdl_hook / ffmpeg HTTP Layer
If yt-dlp works in step 4, test piping yt-dlp directly into mpv so yt-dlp handles the HTTP stream instead of ffmpeg:yt-dlp -v -o - "<failing_url>" | mpv -
If piping works: Your mpv build (likely fromapt, which lags behind upstream) has an olderytdl_hook.luaor ffmpeg build that triggers YouTube's 403 on googlevideo.com URLs. As a permanent workaround inmpv.conf, you can force a specific client that ffmpeg handles cleanlyβsuch asandroidβor exclude problematic TV clients as noted in GitHub discussion #16838 on mpv and this r/linuxquestions thread on Reddit:
script-opts=ytdl_hook-ytdl_path=/usr/local/bin/yt-dlp
ytdl-raw-options=extractor-args="youtube:player_client=android"(Or install the latest mpv via Flatpak (flatpak install flathub io.mpv.Mpv) so mpv and ffmpeg are current.)



