-
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
Speeding up YouTube video loading and seeking? #10601
Comments
You can use yt-dlp on the first try with |
I think I'm going to try out #4793 is, unfortunate. Unfortunately Google is effectively a malicious or hostile actor, trying to fingerprint clients and harm the experience of alternative ones. Nonetheless, is downloading a different URL every few seconds (mirroring the YouTube web client, which I suspect changes video quality on file boundaries), rather than sending range HTTP headers, viable to implement (perhaps https://satadalsengupta.github.io/docs/papers/2017_nossdav_youtubedash.pdf)? |
That seems harder as you would have to instruct ffmpeg on which URLs to download. mpv already gets the 10M |
Also you can use #9042 (comment) to ensure fast yt-dlp playback without breaking media URLs. |
I used yt-dlp to get the video (not livestream) information, and it returned a VP9 URL. But YouTube Web uses range-based URLs even for non-livestream videos.
If my calculations are accurate it'll reduce startup time by 700ms or so. I haven't measured, but I'm happy with that part of the startup time. Ideally something like |
It doesn't get throttled as long as |
I find I have seeking issue when |
I suspect fast seeking in YouTube videos is related to DASH and #7033. It appears nontrivial to implement though. |
Is it possible to pass these options to mpv's libavformat demuxer using --demuxer-lavf-o=? |
Yes, but playing a single chunk isn't useful. |
Important Information
Provide following Information:
Reproduction steps
Regular settings:
hwdec
to mpv.conf (slightly slower startup, insignificant unless my testing is inaccurate).save-position-on-quit
:save-position-on-quit
to mpv.conf.Expected behavior
Loading videos in mpv should not be much slower than invoking yt-dlp to get the URL, and seeking should be as fast as seeking in the YouTube web UI (1 second).
Actual behavior
On my slow Ivy Bridge laptop with or without hardware decoding, loading URLs takes around 4.5 seconds for a window to appear and the play point to appear in the terminal. Around 2.6 seconds is spent waiting for yt-dlp, around 700ms before it trying and failing to play the HTML file, a second or two to buffer the URL, plus overhead.
save-position-on-quit
adds around 2.5 seconds (probably variable) to the startup time, spent seeking. Manually seeking after playback begins takes a variable amount of time depending on where you seek to, I've observed 3 and 6 seconds.Using https://www.youtube.com/watch?v=9ghnfSWKOgY as a seek time benchmark:
yt-dlp -j 'https://www.youtube.com/watch?v=9ghnfSWKOgY'|gron|less
) takes ~2.1 seconds to seek to 19:04 (eyeballed).&range=333999644-335298975&rn=5&rbuf=0
or&range=335298976-336678963&rn=7&rbuf=1813
etc.), eliminating the need to parse video metadata to seek quickly.Ideas
[open_demux_thread]
takes 700ms failing to play a html page before invoking yt-dlp. Hopefully this can be fixed; you could send certain urls straight to yt-dlp instead of trying to download them, or race direct playback and yt-dlp for URLs that don't end in a recognized media file extension, or when you see a text/html file you cancel demuxing it and invoke yt-dlp instead. I've applied this patch locally and it seems to help, but I don't know if it breaks compatibility with text/html pages which succeed in demuxing (I don't know if they exist). (Returning an error fromstream_create_instance
prints a loud red error message to terminal, which I felt was inappropriate in normal operation.)The biggest improvement in video resume and seek time would require either modifying yt-dlp or mpv to use range-based URLs to seek YouTube streams efficiently. I don't know if this is a standard practice in the metadata files specifying the URLs to download (what's it called,
m3u8? HLS?maybe DASH? see https://www.google.com/search?q=range+rn+rbuf), or specific to YouTube. Is implementing URL-based fast seeking practical?Log file
mpv-no-seek-no-hwdec.cast.txt
mpv-no-seek.cast.txt
mpv-seek.cast.txt
Sample files
https://www.youtube.com/watch?v=9ghnfSWKOgY
The text was updated successfully, but these errors were encountered: