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

Can someone help me identify my youtube streaming buffering issue #11402

Closed
bheeshmpita opened this issue Mar 3, 2023 · 7 comments
Closed

Can someone help me identify my youtube streaming buffering issue #11402

bheeshmpita opened this issue Mar 3, 2023 · 7 comments
Labels
down-upstream features and bugs that need to be implemented and fixed upstream

Comments

@bheeshmpita
Copy link

I stream videos through mpv (generally at 480p at 2x speed). I face buffering issue even at 480p. From what i have found out going through issues at github where downloading videos progresses isp speed while buffers while streaming is that ffmpeg has not implemented workarounds for youtube throttling videos >10MB size. Leaving yt-dlp current issue where all users are facing throttled speeds, i face the previously described problem. Kindly go through log file and help me identify and fix the issue. Here are some system details:

mpv 0.35.1
yt-dlp version 2023.02.17
ffmpeg version 4.4.2-0ubuntu0.22.04.1
OS Linux mint 21 xfce
CPU i3-3110m with igpu

mpvlog.txt

@Traneptora Traneptora added down-upstream features and bugs that need to be implemented and fixed upstream and removed meta:question labels Mar 6, 2023
@Traneptora
Copy link
Member

yt-dlp recently implemented a fix for the >10MB issue. Update your yt-dlp.

@bheeshmpita
Copy link
Author

bheeshmpita commented Mar 6, 2023

@thebombzen let me rephrase my issue. I am not downloading videos with yt-dlp instead I am streaming them using mpv. When I download videos they download at full ISP speed but buffers when i stream them (even @ 480/720p). That's the issue I am looking to fix. Kindly go through log text and help me identify the issue and fix it.
I have updated yt-dlp and the issue still persists.

mpvlog.txt
(updated log text with new yt-dlp)

@CounterPillow
Copy link
Contributor

There's no way for you to fix this short of writing code for FFmpeg to make its HTTP implementation do the workarounds to evade youtube's throttling

@bheeshmpita
Copy link
Author

bheeshmpita commented Mar 6, 2023

@CounterPillow Thanks. Can you help me explain a little bit more what actually is happening and ffmpeg needs to do (in layman terms) and does everyone faces this who streams with mpv?

@eljamm
Copy link

eljamm commented Mar 6, 2023

This may be related to #10745

Playing video-only formats seems to throttle the speed. Here are some tests that i did:

  • 398 (video-only) -> throttled
  • 250 (audio-only) -> unthrottled
  • 18 (video+audio) -> unthrottled
  • 22 (video+audio) -> unthrottled

Merging videos+audio with audio doesn't seem to throttle, but with video-only it does:

  • 22+250 -> unthrottled
  • bv[height<=?480]+ba -> throttled

Versions:


Logs:
398-throttled.txt
250-unthrottled.txt
18-unthrottled.txt
22-unthrottled.txt
22-250-unthrottled.txt
bv-480-ba-throttled.txt

@bheeshmpita
Copy link
Author

bheeshmpita commented Mar 7, 2023

Thanks so much @eljamm for pointing out this to me as this basically solves my issue else I had the presumption that lower the video quality the less will it be prone to throttling. I have some other queries too, please address them if you have time:

  1. I was able to stream video without throttling by giving command from terminal but as i generally dont use terminal to watch videos can you help me by pointing out what I am missing: I tried adding ytdl-format=22 in mpv.conf but no success, tried same in yt-dlp.conf still nothing. so basically it works from terminal but doesnt otherwise.

I had a similar issue earlier where i want to stream videos in h264 but adding stuff to mpv.conf wasnt working but when i added -S "codec:h264" to yt-dlp.conf and then it worked but this time when i add -f 22 to yt-dlp.conf it isnt loading video unthrottled.

  1. Can you rephrase the merging audio/video causes crippling bandwidth on YouTube streams #10745 (in easier terms), what I am able to understand is- streaming videos other than 360 and 720p will get throttled as the audio and video file have to be merged instead streaming them collectively. So does that mean if I want to stream in 480p it will throttle?
  2. Some easier understanding of  ytdl_hook: init fragment requires other fragments #11398 as i too get these errors and video plays without the audio.
    Thanks again.

Edit: found a solution to point no. 1. where i added --ytdl-format=22 in options>mpv arguments of playwithmpv extension. If you have something else to add on please feel free:)

@eljamm
Copy link

eljamm commented Mar 8, 2023

  1. This is the best comment that I found that describes the issue:
    mpv slow download speed? #8655 (comment)

Only the formats with the https protocol are not throttled, but they can only go up to 720p.
You can find them by using yt-dlp -F <URL>

Also, you can put them in order of preference. If one isn't available it will go to the next:

mpv --ytdl-format="22/18/17/bv+ba" <URL>

  1. This explanation is not 100% accurate, so please correct me if I'm wrong:

yt-dlp

There are two protocols in yt-dlp for downloading files:

  • https: Only one URL is needed.
  • dash: Multiple URLs, also called fragments, are needed.

Youtube throttled downloading dash files using the https protocol, which yt-dlp fixed by changing the query1, but which also caused issues with how mpv handles fragments.

mpv

There are two types of dash fragments:

  • init: Contains information about the file
  • data: Contains actual media data and the start time to play it (duration)

Before #11398, the first fragment without a duration was considered as init and the ones after it as data:

init + data + data + ...

However, yt-dlp splits fragments as 10MB chunks, so if the filesize is less than 10MB, it would be sent as 1 fragment. As a result, this fragment was considered to be init, and the data was left empty.

( As I understand, durations are used to order fragments, but if there is 1 fragment then this parameter is not included, as it's already in order. )

The fix here is to look for init fragments only if there are more than 1 fragments in total.

fragment + fragment + fragment + ... --> init + data + data + ...

fragment --> data

Without fix

  • Stream size >10MB (Usually Video): Played fine, aside from the EDL warnings.
  • Stream size <10MB (Usually Audio): Does not play

This explains the videos with no audio.

Applying fix

To apply this yourself, you must add the patched ytdl_hook file to ~/.config/mpv/scripts/2.

$ curl https://raw.githubusercontent.com/mpv-player/mpv/362256edbc4f95c63e69c1fa8c8dce9cc6c44288/player/lua/ytdl_hook.lua -o ~/.config/mpv/scripts/ytdl_hook.lua

You might also need to use --ytdl=no as mentioned in the PR.

Footnotes

  1. https://github.com/yt-dlp/yt-dlp/issues/6400#issuecomment-1455101468 | https://github.com/yt-dlp/yt-dlp/commit/5038f6d713303e0967d002216e7a88652401c22a

  2. https://mpv.io/manual/master/#lua-scripting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
down-upstream features and bugs that need to be implemented and fixed upstream
Projects
None yet
Development

No branches or pull requests

4 participants