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

Mitigating long buffering on initial video playback #7919

Merged
merged 2 commits into from
Mar 1, 2022

Conversation

karyogamy
Copy link
Contributor

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

Hi team, long time no see.
I've long since had issue with the buffering time when starting out a new video in the built-in player. Sometimes this gets so bad, there's a 10 seconds wait before any picture would even show up. Of course, your experience might differ depending on the phones, network conditions, or luck etc.

After digging a bit, I found a continueLoadingCheckIntervalBytes parameter on ExoPlayer progressive media source that controls the size of data loaded per call from the playback loader. By default, ExoPlayer will load 1MB per call. Reducing this number seems to have solved the initial buffering woes on my side, though I have no idea how it affects other users. So if you have a similar issue with buffering under fast network speed, please give this a try and test extensively to see if it works and if lowering the values has any side effects.

Screenshots

Fixes the following issue(s)

APK testing

The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR.

Due diligence

Copy link
Member

@litetex litetex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preamble: I'm not sure if this fixes the above issues in the first place. Usually people have at least >1MB/s downlink - so transferring the required data should take 1-2s at worst.

Anyway a few more notes:

app/src/main/res/values/settings_keys.xml Outdated Show resolved Hide resolved
app/src/main/res/values/settings_keys.xml Show resolved Hide resolved
app/src/main/res/values/settings_keys.xml Outdated Show resolved Hide resolved
app/src/main/res/values/strings.xml Outdated Show resolved Hide resolved
app/src/main/res/values/strings.xml Outdated Show resolved Hide resolved
@TobiGr
Copy link
Member

TobiGr commented Feb 23, 2022

Welcome back!

@allgasno
Copy link

Hey @karyogamy whats your internet speed? I don't think theres much difference between 1mb and 256kb, but I'm willing to test could you please direct me to the test apk for myself and others, thank you. Have an internet speed around 250Mbps.

@karyogamy
Copy link
Contributor Author

karyogamy commented Feb 24, 2022

Preamble: I'm not sure if this fixes the above issues in the first place. Usually people have at least >1MB/s downlink - so transferring the required data should take 1-2s at worst.

Thanks for the review @litetex!
This fix is not really dealing with issues arising from network speed. On my side, many of the videos load and play quickly enough, but sometimes, a video would buffer for a long time (~10s) at the start. When this buffering happens, I'd fast forward once and the video would start playing right away instead of buffering for another few seconds. It also didn't make sense to me why this initial buffering is so pronounced here but not on other similar apps or platforms. Though like I mentioned, this might just be affecting a small number of users, but if possible, please try clicking on a variety of individual videos and see if this can be reprod on your devices too.

Hey @karyogamy whats your internet speed? I don't think theres much difference between 1mb and 256kb, but I'm willing to test could you please direct me to the test apk for myself and others, thank you. Have an internet speed around 250Mbps.

Thanks @allgasno, my internet is at 500Mbps so this is not really caused by speed, but perhaps something internal to the player like mentioned.
Please do test it, I will ask for help on the other issue threads as well. You can find the zipped app by going to https://github.com/TeamNewPipe/NewPipe/pull/7919/checks, click on CI on the left, and scroll down to Artifacts.
NOTE you need to enable the fix by going to Settings -> Video and audio -> Playback load interval size -> choose a small value (e.g. 16 KiB).

@karyogamy karyogamy mentioned this pull request Feb 24, 2022
4 tasks
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes buffer issues for me. I found all intervals have no difference in the latency.

@opusforlife2
Copy link
Collaborator

(This is speculation; I haven't tested yet) If it turns out that the 1MB value is better for general cases (loading other than the start of a stream) is it possible to use the smaller value for just the first few seconds, and 1MB (or something higher?) for the rest of the stream?

@karyogamy
Copy link
Contributor Author

karyogamy commented Feb 28, 2022

@opusforlife2 That's exactly the issue: This change adds a parameter that is passed directly from ProgressiveMediaSource factory to the media source and can't be changed on-the-fly unless we duplicate thousands of lines of code.

Also, this issue doesn't only affect the first video played, but every video in a play queue that hasn't been pre-buffered for seamless playback (e.g. when you skip a few songs videos, background player doesn't have this issue).

Honestly, I'm not sure how many users are affected by the same buffering issue, though my guess is a good majority are. That is why I agree with @litetex to keep the exoplayer setting (1MB) default for now. So if buffering complaint keeps coming in and gets fixed with this settings change, we can then consider making a smaller value default instead.

@teaerror
Copy link

teaerror commented Mar 1, 2022

Does anyone know why 1MB doesn't work for NewPipe, when ExoPlayer uses it?
Skipping 10 seconds resolves the issue but setting the playback load to 256 as default would help several users with buffering issues.
Also, this may help with the issue
https://exoplayer.dev/troubleshooting.html#why-do-some-mp4fmp4-files-play-incorrectly

@opusforlife2
Copy link
Collaborator

In my testing, none of the values give a consistently faster playback start. I've seen both slow and fast starts on every value. I'm assuming my internet latency isn't stable enough to test this. 🤷

@karyogamy
Copy link
Contributor Author

@teaerror Yup, that was the page that eventually led me to this solution.
The workaround flags didn't seem to make a difference though.
This comment might help with why continueLoadingCheckIntervalBytes worked: google/ExoPlayer#4014 (comment)

@opusforlife2 Interesting. Initial buffering should become more consistent with the change.
Would you mind sharing your internet speed?
Also, did you make sure the players were fully shutdown and restarted after changing the settings?

@opusforlife2
Copy link
Collaborator

It varies between 50-100 Mbps, but as I said, latency is quite an issue.

I was using the main player only, and I closed it before every time I opened settings.

karyogamy and others added 2 commits March 1, 2022 20:14
- added: preferences to allow user setting of above.
* Moved settings to a better section
* Made string a bit shorter
Copy link
Member

@litetex litetex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Test worked fine. I think the initial loading is a bit better now 😄

Applied minor changes:

  • Updated the branch
  • Moved the preference to a better matching section
  • Shortened a string

(@karyogamy you might also cleanup your repo's branches)

@sonarcloud
Copy link

sonarcloud bot commented Mar 1, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me, too, though it doesn't seem to make any difference for me, like opus

@Stypox Stypox merged commit b8e389c into TeamNewPipe:dev Mar 1, 2022
@opusforlife2
Copy link
Collaborator

Oh. I thought this was meant to be a test PR. To find out what the best value is and make that the default. Are we going to advise users to adjust the value based on their own experiences?

@Stypox
Copy link
Member

Stypox commented Mar 4, 2022

Oh, I didn't get that ;-)
Should the PR be reverted and should we choose a specific value for everyone? This makes sense so that we don't introduce a new setting without a clear meaning except for us.

@karyogamy
Copy link
Contributor Author

@opusforlife2 @Stypox I think the plan is to have the setting available to all for the time being, since there isn't a clear answer as to which value is best for everyone, especially now we know changing the value doesn't seem to make a difference for some. The side effect of choosing a smaller value is still unclear too. My guess is there has to be some kind of a trade-off.

We can either tell the users about this setting proactively, or when there's more buffering issues come in. A new default should be selected in a separate PR when the team is comfortable with it.

On a side note, would it make sense to have a separate settings section for these kind of fine-tuning details? e.g. Player internal buffer/cache size, extractor cache size, etc. Maybe a public Debug section if settings might disappear later?

@opusforlife2
Copy link
Collaborator

Sure. We can work with it in the blog. A temporary setting to poll our users. They could respond on our chosen platform(s), like here, Reddit, blog comments, etc.

On a side note, would it make sense to have a separate settings section for these kind of fine-tuning details? e.g. Player inter

#3192 (comment) ;)

@brnwlshubh brnwlshubh mentioned this pull request Mar 7, 2022
5 tasks
@litetex litetex mentioned this pull request Mar 20, 2022
@AudricV AudricV mentioned this pull request Apr 12, 2022
4 tasks
@ghost
Copy link

ghost commented Apr 16, 2022

The recent v0.22.2 still buffers like crazy, even though this fix claims to be merged. Something's strange.

@AudricV
Copy link
Member

AudricV commented Apr 16, 2022

Nothing strange, only the extractor version and the required app changes have been made (that's why 0.22.2 is a hotfix version and not a normal version). It will be included in version 0.23.0.

@Stypox Stypox mentioned this pull request Apr 16, 2022
12 tasks
@Stypox
Copy link
Member

Stypox commented Apr 16, 2022

This issue is present even on dev though. I added a TODO point to #8230. The cause might be completely different from the one this PR fixes, since switching resolution almost instantly loads the video, and this behaviour could be observed only after updating the NewPipeExtractor (since I could notice it in the player refactor PR before YouTube broke). #8224 is actually relevant (since I am experiencing this issue, too, on 0.23.0 builds). @karyogamy could you look into this?

@karyogamy
Copy link
Contributor Author

karyogamy commented Apr 16, 2022

@Stypox Behaviour still seems fine on my end, did you test by setting a lower interval size?
Also, is the problem reproducible on every video? IIRC, there are some exceptions where the videos would still take a while to load even with the settings changed. In those cases, I added a hack to skip the first frames, but left it out of this PR since I'd much prefer a proper solution like #8153.

But if you are interested, try adding these lines here and see if it does anything:

        if (newPosition.contentPositionMs == 0
                && simpleExoPlayer.getTotalBufferedDuration() < 500L) {
            Log.d(TAG, "Playback - skipping to initial keyframe.");
            simpleExoPlayer.setSeekParameters(SeekParameters.CLOSEST_SYNC);
            simpleExoPlayer.seekTo(1L);
            simpleExoPlayer.setSeekParameters(PlayerHelper.getSeekParameters(context));
        }

@litetex
Copy link
Member

litetex commented Apr 16, 2022

→ Might be related: #8238

@AudricV AudricV mentioned this pull request Apr 17, 2022
5 tasks
@SenorFusion SenorFusion mentioned this pull request Apr 25, 2022
5 tasks
@ColeWunderlich
Copy link

For what it's worth I am also having issues with very long buffer times on v0.22.0.

I am able to consistently fix this by:

  1. Attempting to play the video
  2. Immediately hitting the "background" button (ie audio only)
  3. Immediately switching back to full video after the background playback has started. Then everything works as normal.

This trick consistently works for me. Without the trick initial buffer times are usually over 30 sec for a video, but with this trick the video plays instantly without fail (background audio never takes more than a sec to kick in).

Perhaps this might provide some insight as to what's going on? I find it interesting that this "fix" doesn't involve changing any settings, which tells me the old defaults might be fine and something else might be going on.

PS. I have gigabit internet, so there's no way internet speed is causing buffering issues

ShareASmile added a commit to ShareASmile/FoxPipe that referenced this pull request Jun 14, 2024
…s of 15-01-2024 into pre-unified-legacy

This is a fork of TeamNewPipe/NewPipe-legacy that I have been patching for a few months now. There is no commit history as this has been a personal project up until today.

Pulled in a major chunk of related commits for NewPipe Preunified from upstream TeamNewPipe/NewPipe repository:
1. Update NewPipe extractor to fetch likes count Fix TeamNewPipe/NewPipe#10624
2. Access Background Player Queue from Main menu by HybridAU
TeamNewPipe/NewPipe#8419
3. Added Bandcamp Music Support Into NewPipeLegacy, Improve Bandcamp intent filters
TeamNewPipe/NewPipe#3741
TeamNewPipe/NewPipe#6373
TeamNewPipe/NewPipe#6456
4. Disable sending metrics to Google when using Android System WebView
TeamNewPipe/NewPipe#5337
5. Add basic resize functionality
TeamNewPipe/NewPipe#3948
6. [media.ccc.de] Add recent & live stream kiosk
TeamNewPipe/NewPipe#5251
TeamNewPipe/NewPipe#5286
[media.ccc.de] Fix service color
TeamNewPipe/NewPipe#5258
7. Ability to see Pinned Comment added by dkramer95
TeamNewPipe/NewPipe#7577
8. Clicking on Title In Background Player Should Open Video Details
TeamNewPipe/NewPipe#3808 by https://github.com/budde25
9. Added Swipe to Refresh for Channels New Videos in Subscription Feed
TeamNewPipe/NewPipe#4893
10. [peertube] implement sepia search
TeamNewPipe/NewPipe#5257
11. Allow installation on external storage by triallax in
TeamNewPipe/NewPipe#6037
12. Change UA to privacy.resistFingerprinting
TeamNewPipe/NewPipe#5649 by FireMasterK
13. Add formatting removal on paste for search TeamNewPipe/NewPipe#5912 by imericxu
14. Remember Last Selected Media Type For Downloads
TeamNewPipe/NewPipe#4038 by vmazoyer
15. Improve search suggestion experience when remote ones can't be fetched
TeamNewPipe/NewPipe#4029 by StyPox
16. Fix Download Button Not Visible After Playing Live Stream, Fix video detail controls visibility set inconsistently
Add this commit by StyPox
TeamNewPipe/NewPipe@dbb86d2 from
TeamNewPipe/NewPipe#4362
17. [Background Player] Fix very small thumbnails in Video Detail Page by TobiGR in
TeamNewPipe/NewPipe#5818
18. Add Always Expand Description In Appearance Settings
TeamNewPipe/NewPipe#2998 by B0pol
(Related) entries from search history Increased from 25 to 80 and Search Suggestions Entries from 3 to 60 commit copied from
TeamNewPipe/NewPipe#2666 thanks to ergor
20. Fixes snackbar error on disabled likes count
Fixes TeamNewPipe/NewPipe#7405 by TeamNewPipe/NewPipeExtractor#753
21. Fixed player controls not hiding after replay & Bluetooth headset button by Alexander--
TeamNewPipe/NewPipe#3547
22. update user agent in Downloader to firefox latest ESR 115 by Nickoriginal
TeamNewPipe/NewPipe#8269
23. Changed Dark Theme Colors To Darker Variant by sauravrao637
TeamNewPipe/NewPipe#6244
24. Support for PeerTube Short Links
TeamNewPipe/NewPipe#7353
25. Handle URLs for YouTube Shorts
TeamNewPipe/NewPipe#7181
26. Fix playback speed not being updated in Background Player & Fix TeamNewPipe/NewPipe#8058
Fixed Combinedly by TeamNewPipe/NewPipe#6421 by Tobius
and by seanzzy in
TeamNewPipe/NewPipe#8244
27. Added comments disabled functionallity by litetex in
TeamNewPipe/NewPipe#6483
28. [media.ccc.de] Fix service color
TeamNewPipe/NewPipe#5258
29. Ignore ContentNotSupportedException caused by Bandcamp fan pages
TeamNewPipe/NewPipeExtractor#1033
30. Crash when rotating device on unsupported channels
TeamNewPipe/NewPipe#6696
31. Correct Gigaget's license from GPLv2 to GPLv3
TeamNewPipe/NewPipe#4892
32. Add basic resize functionality [Samsung Dex Now Supported]
TeamNewPipe/NewPipe#3948
33. [Security] Update ktlint to 0.40.0
34. Fix security vulnerability update checkstyle / guava
35. Update ExoPlayer from 2.11.6 to 2.11.8
36. Update checkstyle, OkHttp, use Kotlin JDK8 by TacoTheDank added this commit
TeamNewPipe/NewPipe@79e2bb3
from TeamNewPipe/NewPipe#3909
37. Use user agent of DownloaderImpl also in ReCapthaActivity
TeamNewPipe/NewPipe#5215
38. Fix ACRA bug reports not containing stack trace, Do not init ACRA if inside its own process
TeamNewPipe/NewPipe#3982
39. Remove deprecated calls to set Sender class to ACRA
TeamNewPipe/NewPipe#3982
40.Use SubtitlesStream#getUrl instead of getURL
TeamNewPipe/NewPipe#4120
41. Remove pbj=1 parameter from YouYube urls in recaptcha activity
TeamNewPipe/NewPipe#5208
42. Set notification style in Android 11 to MediaStyle Thanks to XiangRongLin for Limted Support for preunified refer to this commit
XiangRongLin@aa55a09
43. Click on title in background player opens video details
TeamNewPipe/NewPipe#3808
44. Add 2K and 4K to the options list for default resolution
 TeamNewPipe/NewPipe#2968
45. Fix crash when opening video in local playlist tab
Fixes TeamNewPipe/NewPipe#3887
by TeamNewPipe/NewPipe#3892 by wb9688
46.  Handle ContentNotSupportedException
TeamNewPipe/NewPipe#3300
47. [YouTube] Improve download speed by Theta-dev
TeamNewPipe/NewPipe#9948
48. Disable commenter image when disabling thumbnails loading by 4D17Y4
Fixes TeamNewPipe/NewPipe#4205
TeamNewPipe/NewPipe#4350
49. Adapt opacity of popup close button to allow touches in other apps on Android >=11
Fixes TeamNewPipe/NewPipe#6770
TeamNewPipe/NewPipe#8279
50. Better error messages for SoundCloud and YouTube unavailable contents
TeamNewPipe/NewPipe#5385
51. Mitigating long buffering on initial video playback by using custom progress-load-interval in exoplayer,
Use 16 KiB as the default progressive load interval by karyogamy
TeamNewPipe/NewPipe#7919
52. Support for opening YouTube Live URLs
TeamNewPipe/NewPipe#9725

Co-Authored-By: Tobi <17365767+tobigr@users.noreply.github.com>
Co-Authored-By: Stypox <stypox@pm.me>
Co-Authored-By: Audric V. <74829229+audricv@users.noreply.github.com>
Co-Authored-By: bopol <58657617+b0pol@users.noreply.github.com>
Co-Authored-By: Isira Seneviratne <31027858+isira-seneviratne@users.noreply.github.com>
Co-Authored-By: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
Co-Authored-By: fynngodau <fynngodau@mailbox.org>
Co-Authored-By: David Kramer <6166095+dkramer95@users.noreply.github.com>
Co-Authored-By: Ethan Budd <budde25@protonmail.com>
Co-Authored-By: triallax <triallax@tutanota.com>
Co-Authored-By: Kavin <20838718+firemasterk@users.noreply.github.com>
Co-Authored-By: Eric Xu <xeric.2002@gmail.com>
Co-Authored-By: Vincent Mazoyer <17800856+vmazoyer@users.noreply.github.com>
Co-Authored-By: Erol Gorancic <erol@gorancic.no>
Co-Authored-By: Alexander-- <1107390+alexander--@users.noreply.github.com>
Co-Authored-By: Saurav Rao <56369484+sauravrao637@users.noreply.github.com>
Co-Authored-By: Nickoriginal <85299944+nickoriginal@users.noreply.github.com>
Co-Authored-By: Ziyan Zhang <71145592+seanzzy@users.noreply.github.com>
Co-Authored-By: litetex <40789489+litetex@users.noreply.github.com>
Co-Authored-By: XiangRongLin <41164160+xiangronglin@users.noreply.github.com>
Co-Authored-By: wb9688 <46277131+wb9688@users.noreply.github.com>
Co-Authored-By: Okan25 <92695587+okan25@users.noreply.github.com>
Co-Authored-By: Michael Van Delft <1610265+hybridau@users.noreply.github.com>
Co-Authored-By: Taco <32376686+tacothedank@users.noreply.github.com>
Co-Authored-By: ThetaDev <thetadev@magenta.de>
Co-Authored-By: Aditya-Srivastav <54016427+4d17y4@users.noreply.github.com>
Co-Authored-By: John Zhen Mo <zhenmogukl@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slow initial video buffer
9 participants