Floorp-Projects / Floorp

All of source code of version 10 or later of Floorp Browser, the most Advanced and Fastest Firefox derivative 🦊
https://floorp.app
Other
5.65k stars 158 forks source link

Buffer full video, increase network cache and disable disk cache for smooth streaming #131

Closed trimechee closed 1 year ago

trimechee commented 1 year ago

Hello, I already proposed this option in the past and apparently it seems impossible in chromium because chromium removed the media source extension flag.....that's why I prefer use Firefox and Browsers inspired by Firefox so I post my request here please: sometimes the internet connection becomes very weak and the playback of the video streaming becomes painful and jerk and manu interruptions because there is no full buffering of streaming video, it will be great if our beleoved pale moon browser adds an option that can be activated quickly through The toolbar to activate or disavow the Full Buffering of the Whole Video Until The End, I did some research to try to make the full buffering on Firefox, here is the result of my research and i succeed to buffer whole video even on YouTube, by setting "media.mediasource.eabled" to false,

but some times, some rare videos on my favorite streaming sites do not play if media.mediasource.eabled " = false that is why I asked for an option to be quickly able to enable /disable the full buffer of the video if we meet a playback problem: here in my favorite streaming site where I have tested these parameters, sometimes when Iser

browser.cache.disk.enable, browser.cache.disk.smart_size.enabled, browser.cache.disk_cache_ssl and browser.cache.offline.enable to false,

I can buffer full video when i disable cache ssl ..... thank you very much!

here my favorite streaming site where i test these settings : https: //wiflix.studio/

so It will also be awesome please to add an option to quickly increase the size of the network cache and media cache because maybe it can be effective for live streaming when we watch live football or basketball games and we have a low connection, and also add quick option in the toolbar to enable/disable the Disk cache and just use the RAM Memory because sometimes we have an old worn HDD hard drive which can be slow so put the cache in the RAM Memory becomes an inexpensive option! Thanks a lot

I also discovered after a lot of research some tips and ideas to increase the network media cache for smoother streaming or live streaming when wifi or 4G is very weak but we have to go dig into the advanced settings and we hope that Floorp will add an option or a button that we can add in the main bar in order to activate or deactivate these options, thank you very much!

"Buffer full video or make buffer bigger

There is an easy fix for it just increase media.cache_readhead_limit to 9999 and media.cache_resume_treshold also to 9999. This was also puzzling me since firefox 54 would buffer till the end of the video but firefox 55 wouldn't, so I went trough the about:config and found those two lines once I chagned their values from (60, 30) to those above every single video I opened in firefox so far buffered till the end, you don't even need to restart the firefox just refresh the page for changes to take the effect. Hope this helped.

cache_readahead_limit: 999999 cache_resume_threshold: 999999

to

cache_readahead_limit: 60 cache_resume_threshold: 30

set " media.cache_size " to 2147483647

media.cache_readahead_limit media.cache_readahead_limit.cellular

media.cache_resume_threshold media.cache_resume_threshold.cellular

Increase the size of media.cache_size (default 512000 cellular 32768)

Maximize your "browser.cache.disk.capacity" (type "about:config" in Firefox) if you are loading long videos

You can set media.mediasource.enabled to false. If a site's video playback breaks, try to revert this option back to the default, before anything else. Set media.mediasource.enabled to false so it works on Youtube"

Firefox only on RAM Switched browser cache from disk (SSD) to RAM, about:cache still displaying in disk too

set browser.cache.disk.enable, browser.cache.disk.smart_size.enabled, browser.cache.disk_cache_ssl and browser.cache.offline.enable to false

activate the entry browser.cache.memory.enable -> true

set the entry browser.cache.memory.capacity to -1 for automatic adjustment

Reason: Writing down every data to the HDD/SSD is slow & costs lifetime (SSD). Using DRAM is much faster than fastest M.2 SSDs and saves TBW of SSDs!

It speeds up the internet traffic, but you need enough RAM to use this option with many tabs and other tasks! And when crashs happend, some more data could get lost.

  1. (optional) set browser.cache.cache_isolation to true for safety of your personal data.

Type in about:cache to see the result. You could compare before and after with that. 1

There are some cache max prefs on the about:config page that would suggest 50 MB.

I've always disabled browser.cache.disk.smart_size.enabled and set browser.cache.disk.capacity to 1048576

browser.cache.disk.max browser.cache.disk.max_entry_size = 51200 // 50 MB

turn off [browser.cache.disk.smart_size.enabled] and [browser.cache.disk.enable],

If you increase [browser.cache.memory.max_entry_size] to 1048576

I set browser.cache.disk.capacity = 0 and my Win10 Firefox is much faster Discussion

https://www.developpez.net/forums/d2053 ... n-firefox/

I set browser.cache.disk.capacity = 0 and my Win10 Firefox is much faster "

trimechee commented 1 year ago

Another tip i find and i tested to cache data in memory cache and avoid heavy hard disk writes : " the reason of Memory Cache Capacity is Firefox seems to have chosen an outdated automatic value because -1 For Automatic Cache Size Selection (Skipping this Step Has the Sans Effect AS Setting The Value To -1)

The "Automatic" Size Selection is based on Decade-Ob Table that only contains setings for system at or below 8gb of system memory .....

I have enough Memory RAM and I changed the automatic value of Memory Cache at 2000,000 kb and I checked in About: Cache that the default limit of Memory Cache Storage Size which is from 29696 KB was exceeded and Firefox used more than The automatic limit 29696 kb When I changed the size of the Memory Cache at 2000,000 kb ..... "

trimechee commented 1 year ago

i find another tip to more speed that may be can be added as option : " Move disk cache to RAM

An alternative is to move the "disk" cache to a RAM disk, giving you a solution in between the two above. The cache will now be preserved between Firefox runs (including Firefox crash recovery), but will be discarded upon reboot (including OS crash).

To do this, go to about:config and set browser.cache.disk.parent_directory to /run/user/UID/firefox, where UID is your user's ID which can be obtained by running id -u.

Open about:cache to verify the new disk cache location. "

https://wiki.archlinux.org/title/Firefox/Tweaks#Move_disk_cache_to_RAM

surapunoyousei commented 1 year ago

Implement these features. Add the setting "Reduce writing to disk" to the settings.

trimechee commented 1 year ago

Hello @surapunoyousei , i find this very surprinsing Japanese article and new revolutinary sensational discovery about possible problems about youtube cache buffering in firefox and offical documentation about throttling and buffering videos, may be it can help :

Japanese press article FirefoxでYoutube見続けるとSSDが早死にする問題とその対処法 If you continue to watch Youtube on Firefox, SSD dies prematurely and how to deal with it

https://kanasys.com/tech/892

Only throttle download of src=url video if the download is 'fast' on desktop. r=jwwang https://hg.mozilla.org/mozilla-central/rev/b597ea8f9bb4

Our canplaythrough logic is opaque to the users, so I expect that our recent change to throttle when we hit the readahead limit would be confusing to users; those on a slow connection would want their media to prebuffer, and not expect the download to stop part way through. They would think that Firefox had stalled at an arbitrary point for some unknown reason, i.e., they'd think Firefox was broken. So I think we're better to instead only throttle if the network is good enough that the user probably doesn't worry about the download not keeping up with playback.

We should restore the previous behaviour on mobile of throttling when the download reached the readaheadd limit regardless of canplaythrough or network speed, as the calculus is different on mobile; the user may also be concerned about battery life, or hitting their data cap. And often the faster the cellular network is, the more expensive data on it is.

So this patch changes us to throttle when we reach the readahead limit only if the network is fast, where fast is defined as being able to stream at twice the rate estimated to be required to playback without stalling.

It also adds a pref to revert to the old behaviour of not considering the network speed, which we enable on mobile to restore it to its previous behaviour.

We throttle the download if either the throttle override pref is set

bool ShouldThrottleDownload(); + // This should only ever be accessed from the main thread. // It is set in the constructor and cleared in Shutdown when the element goes // away. The decoder does not add a reference the element. MediaDecoderOwner* mOwner;

pref("browser.meta_refresh_when_inactive // prevent video elements from preloading too much data pref("media.preload.default", 1); // default to preload none pref("media.preload.auto", 2); // preload metadata if preload=auto pref("media.cache_size", 32768); // 32MB media cache // Try to save battery by not resuming reading from a connection until we fall // below 10s of buffered data. pref("media.cache_resume_threshold", 10); pref("media.cache_readahead_limit", 30); +// On mobile we'll throttle the download once the readahead_limit is hit, +// even if the download is slow. This is to preserve battery and data. +pref("media.throttle-regardless-of-download-rate", true);

// Number of video frames we buffer while decoding video. // On Android this is decided by a similar value which varies for // each OMX decoder |OMX_PARAM_PORTDEFINITIONTYPE::nBufferCountMin|. This // number must be less than the OMX equivalent or gecko will think it is // chronically starved of video frames. All decoders seen so far have a value // of at least 4. pref("media.video-queue.default-size", 3);

When a network connection is suspended, don't resume it until the // amount of buffered data falls below this threshold (in seconds). pref("media.cache_resume_threshold", 30); // Stop reading ahead when our buffered data is this many seconds ahead // of the current playback position. This limit can stop us from using arbitrary // amounts of network bandwidth prefetching huge videos. pref("media.cache_readahead_limit", 60);

+// We'll throttle the download if the download rate is throttle-factor times +// the estimated playback rate, AND we satisfy the cache readahead_limit +// above. The estimated playback rate is time_duration/length_in_bytes. +// This means we'll only throttle the download if there's no concern that +// throttling would cause us to stop and buffer. +pref("media.throttle-factor", 2); +// By default, we'll throttle media download once we've reached the the +// readahead_limit if the download is fast. This pref toggles the "and the +// download is fast" check off, so that we can always throttle the download +// once the readaheadd limit is reached even on a slow network. +pref("media.throttle-regardless-of-download-rate", false); + // Master HTML5 media volume scale. pref("media.volume_scale", "1.0");

// Timeout for wakelock release pref("media.wakelock_timeout", 2000);

// Whether we should play videos opened in a "video document", i.e. videos // opened as top-level documents, as opposed to inside a media element.

Japanese press article FirefoxでYoutube見続けるとSSDが早死にする問題とその対処法 If you continue to watch Youtube on Firefox, SSD dies prematurely and how to deal with it

What happens if you continue to watch Youtube on Firefox If you open Task Manager and look at Youtube in Firefox, you will see something is wrong.

Even though you are just watching a video, writing to the SSD occurs continuously.

As a test, try setting the cache location to USB memory or the like with browser.cache.disk.parent_directory with about:config, which will be described later.

You can also check the cached contents by typing about:cache in the address bar.

And what we found out.

Firefox stores all Youtube videos as a disk cache.

Videos are rarely watched many times, so there should be little point in caching.

This will cause SSD writes to occur endlessly, which is likely to affect the lifespan of the SSD.

How Firefox caching works You can change the settings by typing about:config in the address bar.

If you type cache in the search, the settings related to the cache will appear.

The settings related to this issue are as follows.

establishment explanation browser.cache.disk.enable Whether to enable disk caching browser.cache.disk.capacity Enabled when disk cache size KB (smart_size is disabled browser.cache.disk.smart_size.enabled Automatically set disk cache from disk space browser.cache.disk.max_entry_size Maximum size of content to cache on disk KB browser.cache.disk.content_type_media_limit Maximum % to store media data browser.cache.disk.parent_directory Full path to cache folder (additional required) browser.cache.memory.enable Whether to enable memory caching browser.cache.memory.capacity Memory cache size KB browser.cache.memory.max_entry_size Maximum size to memory cache KB The problem is that Youtube videos are cut into chunks and are not recognized as media data, and the browser.cache.disk.capacity is originally too large (51200=51.2MB!). That's it.

This means that all chunks of Youtube videos are disk cached.

Also, even if you disable the disk cache by setting browser.cache.disk.enable to false, the browser.cache.memory.max_entry_size is 5MB, so the memory cache will be eaten up immediately by video data.

By the way, Firefox will prioritize recording in the disk cache if the disk cache is enabled. It is cached in memory only when the lifetime is short, such as session cache.

So the memory cache is rarely used in practice.

How to deal with SSD premature death when you keep watching Youtube on Firefox Now, we will show you how to fix it.

Open about:config and set the following items to 128:

browser.cache.disk.max_entry_size This is the maximum size KB of content to cache on disk, which defaults to 51.2 MB. Since the chunk of Youtube video data always exceeds 128KB, Javascript, HTML and image data below that will be cached, and video data will not be cached safely.

By the way, even if you do this, data exceeding 128 KB will not enter the memory cache, fortunately or unfortunately, so there is no need to worry about eating up the memory cache.

To change the Firefox cache folder of entries on

You can change the Firefox cache folder by adding the full path to the browser.cache.disk.parent_directory cache folder.

For example, if you plug a USB portable SSD into the T drive and dedicate it to caching.

If you set the browser.cache.disk.parent_directory to something like this, it will be OK.T:\

If you are concerned about the overall lifespan of the C: SSD, you can reduce the write frequency by setting the environment variables TEMP and TMP in the system settings to the temporary drive above.

By the way, this setting requires restarting Firefox.

Summary So, if you continue to watch Youtube on Firefox, it was a solution to the problem that SSD dies prematurely.

Since it is a software with a long history, the settings have been carried over from the days when the Internet line was a very bottleneck. Nowadays, optical lines may be faster than HDD disk caches.

(By the way, in the 2018 update, a function called Race Cache With Network = RCWN was added, and a mechanism was introduced to make a network request and win the first person even if there is a cache in case of slow spin-up time, etc.) This can also be cut by setting network.http.rcwn.enabled to false in about:config. In the case of a metered line, this seems to be better)

digression In fact, is SSD easy to break if there are many writes in the first place? Isn't there a problem and the effect of wear leveling to distribute writes? There is an argument.

Empirically, SSDs will gradually break depending on the individual if there are many writes, but unlike HDDs, they are almost invisible in appearance. Wear leveling, which shifts so as not to concentrate on one more block, has a certain effect.

Because I wrote a NAND flash wear leveling driver at a manufacturer in the past lol

If you look at the physical block level of SSDs, in fact, some physical blocks may already be broken when they are delivered. This probability is given by the manufacturer, and the driver hides those blocks at the time of shipment on the assumption that it is the case. It's just like a pixel chipped in a liquid crystal.

So, this fragility varies considerably depending on the flash of the same model number and the individual. So, if you look at the map of the physical blocks of the memory you have been using, you can see that the blocks are dead and missing.

However, from the user's point of view, this is due to the extra reserved space provided, so it is not recognized that it is broken at all. Even if the reserved area runs out, the capacity will gradually decrease, and it will not appear as bad sectors handled by the file system like HDDs.

Also, wear leveling is just a mechanism to ensure that physical blocks are not biased when erasing local data (writing and erasing one file repeatedly), so the "I erased the entire drive over and over again, but there was no effect of wear leveling" that I see on the Internet seems to misunderstand the purpose of wear leveling in the first place.

So I digress. This is just a story of the past and it is a story due to individual differences and design of NAND flash, so it may not be so severe now."

trimechee commented 1 year ago

So i tried to read article but it is too complex and i don't unerdstand which setting use to avoid streaming throttling and make buffer media bigger, i think it may be these settings :

https://hg.mozilla.org/mozilla-central/rev/b597ea8f9bb4

Increase the size of

media.cache_size 2147483647

Increase

browser.cache.disk.content_type_media_limit

browser.cache.disk.capacity

cache_readahead_limit: 999999
cache_resume_threshold: 999999

media.cache_readahead_limit media.cache_readahead_limit.cellular

media.cache_resume_threshold media.cache_resume_threshold.cellular

You can set media.mediasource.enabled to false. If a site's video playback breaks, try to revert this option back to the default, before anything else. Set media.mediasource.enabled to false so it works on Youtube

media.preload.default

media.volume_scale

media.throttle-regardless-of-download-rate

media.throttle-factor

media.throttle-regardless-of-download-rate false

media.video-queue.default-size

media.wakelock_timeout

prevent video elements from preloading too much data pref("media.preload.default", 1); // default to preload none pref("media.preload.auto", 2); // preload metadata if preload=auto pref("media.cache_size", 32768); // 32MB media cache

creeper-0910 commented 1 year ago

Could you give us a brief summary of the results only? Longer "issue" take longer to read.

trimechee commented 1 year ago

Believe me @creeper-0910 , what i write is the summary of the summary, this is the best of months of hard search

K4sum1 commented 1 year ago

Can you just give some good settings to use by themselves?

K4sum1 commented 1 year ago

Actually nevermind setting media.cache_* to 9999 worked. I set cache size to 2147483647 though.

K4sum1 commented 1 year ago

How do I get high quality videos with mediasource disabled?

trimechee commented 1 year ago

with media source disabled, we can play 360p or 720p, but some streaming videos doesn't work if media source is disabled

surapunoyousei commented 1 year ago

https://github.com/Floorp-Projects/Floorp/issues/140#issuecomment-1547252868

trimechee commented 1 year ago

Hello @surapunoyousei , so as explained previously, I found clever way to full buffer streaming and have smooth playback even when internet connection becomes very weak when many members of our family connect to wifi : disable MSE media source extension by going to "about:config" and setting the value "false" to "media.mediasource.enabled", ir works on ok.ru/video, sibnet, uqload....like in this site :

https://french-anime.com/animes-vf/1214-mashle.html

but sometimes, some streaming platforms and video players don't work if MSE media source extensions is disabled, so our dream is that our beloved Floorp Browser increase the buffer network cache of streaming videos which is currently only 20 or 30 seconds no matter what our internet connection is weak and the video is in very high definition, so we could have smooth playback even with weak connection, thank you very much !

so, i see there is new version of Floorp Browser,so in the new version of Floorp Browser, is there an option to increase network cache to 1 minute for example in streaming videos for more smooth playback please ?

EDIT : i make some researches and i tested many values of these flags but sadly, nothing changes, the quantity of the network cache buffer does not change :(

media.cache_readahead_limit

media.cache_resume_threshold