-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
merging audio/video causes crippling bandwidth on YouTube streams #10745
Comments
YouTube doesn't. If you read my tests closely, the bandwidth from YouTube is perfect. Piping video & audio streams separately gives unlimited downspeed. The fact is that YouTube itself works based on separated streams (except 360p & 720p) But MPV's way of handling streams is way fishy. It's trying to play them together synchronously. Try |
Please actually read the linked comment, it explains what's going on here. YouTube throttles based on the bitrate of the stream, that's why you get slower download speeds at lower resolution. |
That's not the case.
This statement is not true, if you test both streams separately. |
Oh yeah?
Sure looks to me like your download speed is also decreasing when you only download the video stream without audio. The only weird thing I see is that I currently can't test it myself, but I'll give it a try later. |
That's failure case. Read the "Temporary Resolution" part that I've wrote after that.
Nop. It's actually faster, caz yt-dlp downloads them separately & merges streams later. It's the issue in playback. 303 is 1080p 60fps. This, & 137 (1080p 30fps) are the most common streams of YouTube, that also affected by this. My analogy is that direct download of streams doesn't support seeking, which is the reason mpv utilizes some form of workaround that allows seeking which kinda defeats the faster bandwidths. |
This is because of the throttling from YouTube, as explained in the linked comment. yt-dlp has a workaround, mpv does not. |
Although I'm quite not sure it's a workaround. The direct links are fast enough even inside a browser. Afaik, there's no youtube-dl parameters in the url. As you suggested me to check the linked comment
I think this is where mpv's doing something to retrieve those metadata as well as leaving up some bandwidth away because of some workaround mpv did. Personally I would prefer piping over full metadata retrieval, because I constantly hit +10 forward in my daily content consumption. Seeking might be affected, but it wouldn't matter as I watch the whole stream anyways. |
The range headers are what makes yt-dlp faster. You can easily see it by making HTTP requests directly:
90MB/s on a VPS
1.6MB/s And mpv doesn't have any network code, it's ffmpeg that downloads streams, and it doesn't support downloading in chunks like yt-dlp yet.
Why are you piping the output of the first yt-dlp command if it downloads to a file? |
Just to get separated audio stream & use it with piped "video only". Do you know how to pipe audio too in conjunction with video, instead of downloading right away ? I think that command can be shortened a little more.
FFmpeg might be getting stream links, but the direct links from
That's strange. Both headers have same faster speeds here (38 mbps). And why VPS btw ? Any important role of it in playback ? |
Why would that require piping the first command? Why not use
To have fast download speed with mpv and 1080p+ youtube videos someone needs to implement downloading in chunks in ffmpeg. That is already known.
Just so I can test with a faster connection. |
Tq. I'm just learning bash scripting & few gnu tools, so I'm kinda newbie in this case.
Hold on. That mega bytes right? (which is faster caz do x8 for bits). I've just expressed it as bits before. Bits for Internet & bytes for storage. |
Yes, curl shows the megabytes. |
I do have resource monitor in my status bar showing megabits/sec, so it's cleaner. |
Most of my issues with buffering with ytdl in mpv is when the beginning of a video has a higher ABR than the overall ABR, which is common because a lot of videos will have more going on during an intro than the rest of the video overall. I don't know what causes this but it can often be bad enough that it requires downloading the entire video then watching it, which isn't a huge deal, but it would be nice if it wasn't broken in that way. I dunno if this is related to the issue here or not. |
Hmm. You sure it's a bitrate issue? Caz I don't think that's the case. As resolutions scale down, bitrates of the streams would also. So you should technically get even faster buffers as of your ISP speeds.
1080p+ streams have higher bitrates so their speeds are naturally scaling in the increased order. There must be some fetching issues in the codebase itself. Caz that's not how direct streams behave under browser right. I think it comes down to DRM issue. Browsers allow DRM playback, but MPV is a local media player so it doesn't (& just relies on partially buffered streams through https). |
They download slower because youtube chose to the throttle them like that.
There is no fetching issue in ffmpeg because you can reproduce the same throttling with curl or wget as long as you don't set a < 10MB range, while you can avoid the throttling with aria2 which lets you download in chunks. We already tested this on #mpv many months ago. Why else would yt-dlp have implemented the http-chunk-size?
Youtube videos don't have DRM, or they wouldn't play at all. |
I thought that might be the case, although it doesn't have DRM. Because browsers support it. I thought that hiding direct stream links of YouTube is some sort of DRM policy. I'm wrong though.
That's great btw. So if aria2 chunk playback is tested already ? |
I meant using aria2 from the command line. It doesn't have mpv integration. Also it's worth noticing that on my previous curl example it was a 100MB range that toggled the throttling, so it may increase with the video resolution. Still that doesn't change that implementing the chunking in ffmpeg is what's needed to increase the download speed. |
I believe YouTube bandwidth throttling and seeking to be two different issues. I have a proxy server script that breaks up a large HTTP request into multiple small HTTP requests and it greatly speeds up my YouTube speed with mpv. However, I find I still have issues with seeking. Say when I am watching a a YouTube video that has separated video and audio streams. When I try to seek, mpv will disconnect one of the streams from my proxy server and reconnect it with its new range. Video playing will stalls when this happens. Only after some quite noticeable delay, will mpv disconnect the other stream from my proxy server and reconnect it with its new range. Video playing finally resumes. Update: I found a bug in my script and fixing it fixed the AV sync issue I had. Everything works quite nicely with mpv+YouTube now |
This exact thing also happens when I pipe stream both audio & video separately. It's more of an av sync issue than the throttling itself. |
@stumpedatwork could you share some details on how you set up this proxy? |
@Roliga I have a |
I tried dynamically updating the http-header-fields and stream-lavf-o options with a lua script, but it seems that only the intial value for the option is used, even if the connection times out. Would it be possible to make mpv use the updated http-header-fields/stream-lavf-o? |
Hi, can you share your proxy script, it'll help a lot of users who are struggling with Youtube throttle ? Thanks! |
Hello, can you share your NodeJS fetch script ? Thanks! |
Can you share the script? |
Important Information
yt-dlp/youtude-dl streams have slower buffer / bandwidth speeds on reduced resolutions compared to direct stdin piping.
Provide following Information:
Linux arch 5.19.13-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC
https://archlinux.org/packages/community/x86_64/mpv/
If you're not using git master or the latest release, update.
Releases are listed here: https://github.com/mpv-player/mpv/releases
Reproduction steps
Try to reproduce your issue with --no-config first. If it isn't reproducible
with --no-config try to first find out which option or script causes your issue.
Describe the reproduction steps as precise as possible. It's very likely that
the bug you experience wasn't reproduced by the developer because the workflow
differs from your own.
Testing the popular example Costa Rica by Jacob + Katie Schwarz
Tried scenarios:
mpv 'https://www.youtube.com/watch?v=LXb3EKWsInQ'
ormpv --ytdl-format=bestaudio+bestvideo/best 'https://www.youtube.com/watch?v=LXb3EKWsInQ'
ormpv --ytdl-format=337 'https://www.youtube.com/watch?v=LXb3EKWsInQ'
Network downspeed: 50 mbps (ISP max speed utilized) at --ytdl-format=337 (4k 60fps, vp9.2) / 315 (4k 60fps, vp9)
Now the network downspeed results with different stream-id's :
--ytdl-format=336
: 34 mbps (1440p 60fps, vp9.2)--ytdl-format=308
: 21 mbps (1440p 60fps, vp9)--ytdl-format=335
: 14 mbps (1080p 60fps, vp9.2)--ytdl-format=699
: 11 mbps (1080p 60fps, av01.0.09M.10)--ytdl-format=303
: 7 mbps (1080p 60fps, vp9)... & so on. Basically downspeed decreases gradually on lower quality streams. Same issue when audio combined (336+251, 308+251), & so on.
Tested direct stream download links too (youtube-dl has
-g
option that provides direct download links)mpv $(yt-dlp -g -f 308 'https://www.youtube.com/watch?v=LXb3EKWsInQ')
Network downspeed: 21 mbps (same as above test cases)
Same issue with audio combined in this case.
TEMPORARY RESOLUTION (stdin piping) :
Direct downloading from yt-dlp has no downspeed issues. So I piped the output directly to mpv & had max downspeed bandwidth without any buffer restrictions.
yt-dlp -f <336/308/335/699/303... & so on> 'https://www.youtube.com/watch?v=LXb3EKWsInQ' -o - | mpv -
Network downspeed: 50 mbps (ISP max speed utilized)
Now here comes the tricky issue.
Only video streams have been tested. Combining them with audio brings the same exact issue again.
yt-dlp -f 308+251 'https://www.youtube.com/watch?v=LXb3EKWsInQ' -o - | mpv -
Network downspeed: 21 mbps (same as above test cases)
Concat streaming through audio somehow borks streaming bandwidth down. There's being some weird issue with
-f
or--ytdl-format
options in this regard.One possible workaround I had, is to pipe both streams separated into mpv
mpv --audio-file=<(yt-dlp -f 251 https://www.youtube.com/watch?v=LXb3EKWsInQ -o -) <(yt-dlp -f 336/308/335 https://www.youtube.com/watch?v=LXb3EKWsInQ -o -)
Network downspeed: 50 mbps (ISP max speed utilized)
Issue with this workaround is that seeking is not possible with stdin piping case.
Expected behavior
mpv should stream youtube-dl/yt-dlp (<= 1080p) streams with the same speed as they provide on downloads.
Actual behavior
Instead, mpv cripples bandwidth when lowering stream quality.
I've came into a conclusion that there are no issues with neither youtube's servers, nor youtube-dl / yt-dlp projects. Both are working fine. It's the mpv's bug that causes these streaming speed drops.
Log file
https://0x0.st/ovJL.log
The text was updated successfully, but these errors were encountered: