damus icon indicating copy to clipboard operation
damus copied to clipboard

Cache videos

Open danieldaquino opened this issue 2 years ago • 10 comments

At some point we investigated whether or not videos are cached, and unfortunately it seems like they are not (See this comment).

This is a concern in terms of mobile data/bandwidth usage. If we cache videos, we might be able to reduce data usage.

danieldaquino avatar Nov 15 '23 17:11 danieldaquino

How will cached videos affects storage, as we know cached images can stack up storage space quickly.

alltheseas avatar Nov 15 '23 17:11 alltheseas

On Wed, Nov 15, 2023 at 09:41:49AM -0800, alltheseas wrote:

How will cached videos affects storage, as we know cached images can stack up storage space quickly.

They would be handled just like our current cache eviction logic, after one day they get deleted.

We might have to do something custom here though, since we are not using kingfisher for videos.

jb55 avatar Nov 15 '23 17:11 jb55

On Wed, Nov 15, 2023 at 09:28:58AM -0800, Daniel D’Aquino wrote:

This is a concern in terms of mobile data/bandwidth usage. If we cache videos, we might be able to reduce data usage.

yeah this is pretty bad and should be high priority to fix

jb55 avatar Nov 15 '23 17:11 jb55

Related to low data/cellular mode https://github.com/damus-io/damus/issues/919

alltheseas avatar Nov 15 '23 17:11 alltheseas

If this is a large ticket, maybe we can break it down into smaller parts and convert this one into a tracking issue?

jb55 avatar Apr 08 '24 20:04 jb55

If this is a large ticket, maybe we can break it down into smaller parts and convert this one into a tracking issue?

The only meaningful way I currently see to split this ticket is by splitting it into progressively better cache versions. As of now, I know 3 ways of implementing this cache:

  1. The simplest method: Simple cache with whole file downloads and some initial download bandwidth overhead
    • This is the current patch
  2. The AVExportSession method: simple-ish cache that saves videos to the cache using AVExportSession which uses data downloaded by the AVPlayer
    • I have a draft for this one but I am hitting an issue with it that I could not solve after a good amount of research and experimentation
  3. The AVAssetResourceLoadingRequest method: We tap into the AVPlayer loader and manually load the bytes for them and direct those bytes to the cache as well. This might be the most efficient as it would enable us to do partial cache downloads
    • I am currently studying and experimenting with this in hopes that it will be easier than troubleshooting whatever obscure issue is on (2), and has the highest payoff

danieldaquino avatar Apr 09 '24 00:04 danieldaquino

  1. The AVAssetResourceLoadingRequest method: We tap into the AVPlayer loader and manually load the bytes for them and direct those bytes to the cache as well. This might be the most efficient as it would enable us to do partial cache downloads

    • I am currently studying and experimenting with this in hopes that it will be easier than troubleshooting whatever obscure issue is on (2), and has the highest payoff

@jb55, I have a draft and a closer understand of this technique now. Not fully functional yet, but I think this is doable in the short term

danieldaquino avatar Apr 09 '24 06:04 danieldaquino

On Mon, Apr 08, 2024 at 11:07:10PM GMT, Daniel D’Aquino wrote:

  1. The AVAssetResourceLoadingRequest method: We tap into the AVPlayer loader and manually load the bytes for them and direct those bytes to the cache as well. This might be the most efficient as it would enable us to do partial cache downloads

    • I am currently studying and experimenting with this in hopes that it will be easier than troubleshooting whatever obscure issue is on (2), and has the highest payoff

@jb55, I have a draft and a closer understand of this technique now. Not fully functional yet, but I think this is doable in the short term

ok great, this sounds like the right way to do it

jb55 avatar Apr 09 '24 15:04 jb55

Created a ticket to address any remaining video loading issues: https://github.com/damus-io/damus/issues/2181

danieldaquino avatar Apr 22 '24 23:04 danieldaquino

Opened this again due to video cache revert

  • #2191

jb55 avatar May 06 '24 20:05 jb55