Skip to content
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

mpv slow download speed? #8655

Closed
erickyun opened this issue Mar 15, 2021 · 35 comments
Closed

mpv slow download speed? #8655

erickyun opened this issue Mar 15, 2021 · 35 comments

Comments

@erickyun
Copy link

erickyun commented Mar 15, 2021

mpv is downloading slow with every stream link?

My internet speed is normally 10MiB/s but mpv I'm getting 600-900KiB/s ?

Nornally downloading with youtube-dl Im getting fast speed but with mpv the speed is slow?

Edit:
I noticed when seek forward or backward the speed goes to 7MiB/s and then it goes fast down to 600-900KiB/s ?

@wiiaboo
Copy link
Member

wiiaboo commented Mar 15, 2021

If it's specifically on youtube links and some others, see #5806 and ytdl-org/youtube-dl#11476

@erickyun
Copy link
Author

If it's specifically on youtube links and some others, see #5806 and ytdl-org/youtube-dl#11476

The problem is youtube ,cr , viki.com etc... everything I tried has the same problem?

@CounterPillow
Copy link
Contributor

That's because those all use youtube-dl because they are not direct links?

@erickyun
Copy link
Author

That's because those all use youtube-dl because they are not direct links?

The problem is not youtube-dl it is with mpv!
Downloading separate with youtube-dl URL
I get 10MiB/s-12MiB/s but with mpv it is stuck with 600KiB-900KiB?

@wiiaboo
Copy link
Member

wiiaboo commented Mar 15, 2021

This is neither a youtube-dl nor an mpv issue.
youtube-dl has a mechanism to bypass bandwidth throttling, mpv (as in FFmpeg) doesn't.

If you use download through the same URL in FFmpeg as in mpv and FFmpeg is also throttled, the problem/feature request belongs in FFmpeg, not mpv, as already explained in the links I mentioned.

@erickyun
Copy link
Author

erickyun commented Mar 15, 2021

This is neither a youtube-dl nor an mpv issue.
youtube-dl has a mechanism to bypass bandwidth throttling, mpv (as in FFmpeg) doesn't.

I did a little research myself

ytdl-org/youtube-dl#15384 (comment)

https://github.com/yt-dlp/yt-dlp

and I don't know how much correct I am but with aria2 the download speed can be increased if I'm right with
--external-downloader aria2c --external-downloader-args:aria2c "-x 16 -s 16 -k 1M"

So if Im right?
How can make mpv use aria2?
And also how can I use the command above with mpv?
Do you maybe know? İs it with ytdl-raw-options= ?

Edit:

Would something like this work in the mpv.conf?
ytdl-raw-options=cookies="/storage/emulated/0/download/cookies.txt",external-downloader=aria2,external-downloader-args:aria2c="-x 16 -s 16 -k 1M"

@Akemi
Copy link
Member

Akemi commented Mar 15, 2021

you can't use an external downloaded with our youtube-dl lua script. youtube-dl returns an url to us and ffmpeg is doing the rest. it never downloads anything on disk.

if you want to use it you have to use youtube-dl on it's own and play the resulting file on the disk with mpv or pipe it to mpv.

@erickyun
Copy link
Author

erickyun commented Mar 15, 2021

you can't use an external downloaded with our youtube-dl lua script. youtube-dl returns an url to us and ffmpeg is doing the rest. it never downloads anything on disk.

if you want to use it you have to use youtube-dl on it's own and play the resulting file on the disk with mpv or pipe it to mpv.

İt would be great if mpv could use aria2c for sites like CR and viki.com since yt-dl does send ffmpeg to download and speed is really slow!

Could I make request like this? İs it possible?

@Akemi
Copy link
Member

Akemi commented Mar 15, 2021

i am not sure if this is something we want in our youtube-dl script. though that's not up to me.

like mentioned before and the other issues, this is something ffmpeg should add.

@erickyun
Copy link
Author

erickyun commented Mar 15, 2021

i am not sure if this is something we want in our youtube-dl script. though that's not up to me.

like mentioned before and the other issues, this is something ffmpeg should add.

I want to say all the things below for it just to be only idea or request. I hope that this maybe will happen someday.

I thank you for your help and understand it not only for you to decide but
I did look at the other issues dates saw that it is being more than 3-4 years and it looks like ffmpeg isn't doing anything about it☹️. so I thought it would be great actually if there was tentative solution with aria2c for now?
Cuz
Copy and paste url to mpv is more convient than separately downloading the file with yt-dl ffmpeg which download speed is slow.

There is this yt-dlc fork yt-dlp that does support aria2c as the external downloader for DASH(mpd) and HLS(m3u8) formats.
İt would be great if this was used for cr and viki.com for streaming directly with mpv.
This is what I was thinking and want to share it here.

https://github.com/yt-dlp/yt-dlp

@wiiaboo
Copy link
Member

wiiaboo commented Mar 15, 2021

youtube-dl literally has the same aria2c support. Those forks of it obviously have it too.
It still doesn't have anything to do with mpv.

@wiiaboo wiiaboo closed this as completed Mar 15, 2021
@avih
Copy link
Member

avih commented Mar 15, 2021

It's also possible that mpv fills the cache quickly, and then it keeps downloading at a rate which matches the playback speed.

To test: play with --speed=2 and observe whether the speed stabilizes on twice than with normal speed.

To increase the cache, for instance to 1G (the default is 150M forward), use --demuxer-max-bytes=1G .

@erickyun
Copy link
Author

youtube-dl literally has the same aria2c support. Those forks of it obviously have it too.

But when I try to download CR with youtube-dl it isn't using aria2c it uses ffmpeg?

Are you sure that youtube-dl does support aria2c as the external downloader for DASH(mpd) and HLS(m3u8) formats?

@garoto
Copy link
Contributor

garoto commented Mar 16, 2021

yt-dlp does indeed advertise having support for DASH and HLS downloads using an external, multi-threaded client like aria2c. But that's not the point of your initial question, which was most likely correctly answered by avih right above.

@erickyun
Copy link
Author

It's also possible that mpv fills the cache quickly, and then it keeps downloading at a rate which matches the playback speed.

To test: play with --speed=2 and observe whether the speed stabilizes on twice than with normal speed.

To increase the cache, for instance to 1G (the default is 150M forward), use --demuxer-max-bytes=1G .

This only work in the beginning later it goes down to slow speed again but thanks.

@garoto
Copy link
Contributor

garoto commented Mar 16, 2021

This issue reads like trying to walkthrough my mom in sending a WhatsApp text message: it goes nowhere.

@erickyun
Copy link
Author

This issue reads like trying to walkthrough my mom in sending a WhatsApp text message: it goes nowhere.

Sorry for my bad English I probably couldn't explained right.

@skorokithakis
Copy link

skorokithakis commented Oct 19, 2021

@erickyun's solution with yt-dlp worked great for me, thank you!

@garoto if you could take some time from coming up with snarky zingers, you'd realize that the issue that actual users are having is that YouTube playback with MPV is unusable. To that end, @erickyun's solution works fine, unless the point is to strictly and pedantically adhere to "the point of the initial question", which, even then, I'm sure @erickyun is more qualified to speak on, as he was the one who asked the question.

@antoniocascais
Copy link

Hi all!

Just want to share I have the same problem, can't play a youtube video with mpv. It's buffering all the time :/

I was googling around and ended up in youtube-viewer (https://github.com/trizen/youtube-viewer). I tested it and I can play a 1080p video without problems, so it's not a problem of my laptop or internet connection.

Writing this so that people are aware the problem is ongoing.

@avih
Copy link
Member

avih commented Feb 18, 2022

It's buffering all the time

#8779 (comment)

TL;DR: use yt-dlp instead of youtube-dl.

@TheBestPessimist
Copy link

TheBestPessimist commented Jul 29, 2022

Hello,

After reading this thread, i want to do a summary, to check if i understand things correctly:

  • mpv uses ytdl (or any of its forks) just to get the video url
  • mpv uses ffmpeg to download/stream the videos (from youtube, or other video platforms) and not ytdl
  • ffmpeg has issues with slow downloads/buffering of youtube videos
  • yt-dlp has (mostly? well, completely for me) solved the issue with youtube throttling/buffering, which yt-dl has not (at the time of writing at least)
  • ffmpeg has not implemented the same fixes that yt-dlp has implemented to assure fast downloads from youtube

Is my understanding correct?

In order to not have issues with buffering, we were suggested to 1. download a video fully using yt-dlp, 2. open that video file in mpv 3. watch without buffering.

My next question is: is there a possibility to instruct mpv to download via yt-dlp directly, and not via ffmpeg, and somehow pass the "download in progress" video stream from yt-dlp to ffmpeg or to mpv to do the rest of the processing? Basically, what i'm saying is: can we sidestep ffmpeg from downloading the video and leave this task to yt-dlp instead?

For the record, i have 1 GBps up and down, and when i download with yt-dlp (.\yt-dlp.exe https://youtu.be/CJbP71RI-V4 - no extra config), i get 100-150Mbps, while when i look at the same video in mpv (.\mpvnet.com https://youtu.be/CJbP71RI-V4) i get ~500kbps, as viewed by pressing t + 3 in the mpv window.

@guidocella
Copy link
Contributor

guidocella commented Jul 29, 2022

Youtube now throttles requests of more than 10MB at a time, yt-dlp works around it by making many requests of 10MB using Range HTTP headers (yt-dlp calls it the http-chunk-size), but ffmpeg which does the downloading for mpv doesn't support that yet.

You can let yt-dlp do the downloading with yt-dlp -f bv -o - https://... | mpv --audio-file=<(yt-dlp -f ba -o - https://...) -, but this breaks seeking to timestamps that haven't been cached yet, and doesn't set the media title, the chapter list or subtitles.

The lower the resolution you request the more you are throttled, so lowering the resolution doesn't let you download faster.

You can play the streams with both video and audio which are not throttled, but they're only up to 720p: mpv --ytdl-format='[height=360]' https://..., mpv --ytdl-format=best https://...

@Tsuchimikado
Copy link

You can also try the files with contain both video and audio which are throttled less

Thank you for this advice. I always watched 720p60 with ~600kB speed. But after switching to 720p30 stream that contains both video and audio the speed is now ~5mB (max speed of my wifi connection)

@ghost
Copy link

ghost commented Oct 14, 2022

Try this to unlock full ISP speeds
yt-dlp -f 251 'video-link' -o $XDG_RUNTIME_DIR/ytaudio | yt-dlp -f bestvideo 'video-link' -o - | mpv --audio-file="$XDG_RUNTIME_DIR/ytaudio" -
Although seeking would be an issue (I donno why).

@sun95n
Copy link

sun95n commented Dec 11, 2022

Thanks! My old options were ytdl-format=bestvideo[height<=?720][fps<=?30][vcodec!=?vp9]+bestaudio/best I relied on this comment. I guess bestvideo+bestaudio/best was the problem.

@sun95n
Copy link

sun95n commented Dec 13, 2022

but ffmpeg which does the downloading for mpv doesn't support that yet.

@guidocella Could the ffmpeg version fix it? I currently use 4.2.7 from the Ubuntu 20.04 repositories but 5.1.2 is in the works. Also, someone who used a Rolling distro could confirm if there is no problem with ffmpeg and YouTube.

@guidocella
Copy link
Contributor

No, someone needs to implement it.

@piyushgarg
Copy link

piyushgarg commented Dec 28, 2022

Just a small update for the script by @pc00per

#!/bin/bash
yt-dlp -N 8 --no-part -f "bestaudio" "$1" -o /tmp/ytaudio | yt-dlp -f "bestvideo" "$1" -o - | mpv --audio-file="/tmp/ytaudio" -
rm -rf /tmp/ytaudio

No seeking or chapters but it utilizes the network max speed.

@ghost
Copy link

ghost commented Dec 30, 2022

@piyushgarg btw I bash aliased all those commands

pp='fun(){
	rm $XDG_RUNTIME_DIR/yta >/dev/null
	yt-dlp -N $(nproc) --no-part -f "wa[acodec~=opus]/ba" $@ -o $XDG_RUNTIME_DIR/yta
	yt-dlp -f bv $@ -o - |\
	mpv --audio-file=$XDG_RUNTIME_DIR/yta -
	}; fun'

pp 'link'
I used worst audio for least initial waiting time. And it's opus, so the audio quality is very transparent & close to the source even with 54 kbps.

@Max-Enrik
Copy link

Try this to unlock full ISP speeds

Is it possible to use it in mpv.conf for playing youtube videos? I watch some videos at speed x4.

@Co3co
Copy link

Co3co commented Jul 17, 2023

Really hope ffmpeg is updated to support this eventually.

@ilya-indigo
Copy link

ilya-indigo commented Aug 26, 2023

#12254
I have a problem not only with youtube, but also with other video services.
Download and launch is not applicable to streaming and live broadcasts.
Why can't caching be hung on yt-dlp or make its own layer for that before ffmpeg?
Does the ffmpeg upstream know about the problem?

I realize that this sounds definitely not like an ffmpeg problem, since ffmpeg's job is encoding and decoding, not splitting requests into pieces to bypass video service limitations.
Maybe there is a layer in ffmpeg to take over the downloading, leaving ffmpeg only decoding?

@ilya-indigo
Copy link

ilya-indigo commented Aug 30, 2023

That's such a crutch...

u="video_url" && n="`yt-dlp -Otitle $u`" && f="/tmp/$n" && yt-dlp --max-filesize 1.8G --sub-langs 'en,ru' --embed-subs --embed-chapters --no-part -f'bestvideo[height<=1080][fps<=?60][vcodec^=?avc]+bestaudio/best[height<=1080][fps<=?60][vcodec^=?avc]' -o"$f" "$u" && mpv --slang=ru "$f"* && rm "$f"*

But in any case for streaming broadcasts neither this option nor the option with separate audio stream loading is not suitable and mpv should load via yt-dlp instead of ffmpeg itself by default!

@roninyymi
Copy link

If you think you can do this better or know much more than me, maybe you can show me and others how to do this correctly, thank you. Before saying this issue is already closed or everything in my message is done wrong way and whatever, I know this is that. I just wanted to use aria2 and yt-dlp with mpv, I don't know much about these things and did get this working for my own use and this now buffers my youtube videos instantly. If this helps temporarly even one person, here it is:

Create /usr/bin/yt-dlp_to_mpv with this:

#!/bin/bash
yt-dlp -o - $1 | mpv --title="$(yt-dlp -o '%(title)s' $1 --get-filename --skip-download --no-warnings)" --script-opts=osc-title="$(yt-dlp -o '%(title)s' $1 --get-filename --skip-download --no-warnings)" -

Then chmod +x /usr/bin/yt-dlp_to_mpv

Set this into ~/.config/yt-dlp/config (or whatever config location you use for yt-dlp:

--external-downloader=aria2c
--external-downloader-args "--min-split-size=1M --max-connection-per-server=16 --max-concurrent-downloads=16 --split=16"

Now you can use yt-dlp_to_mpv for any command that you want. For example args = ["yt-dlp_to_mpv", url] in ff2mpv.py with ff2mpv extension for your browser or you can open videos in ytfzf with setting load_url_handler "yt-dlp_to_mpv" to your ~/.config/ytfzf/conf.sh etc.

@rnhmjoj
Copy link
Contributor

rnhmjoj commented Mar 4, 2024

FFmpeg feature request: https://trac.ffmpeg.org/ticket/10381

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests