RenderHeads / UnityPlugin-AVProVideo

AVPro Video is a multi-platform Unity plugin for advanced video playback
https://www.renderheads.com/products/avpro-video/
226 stars 28 forks source link

Stream mp4 over http + cache at the same time #1173

Open AshleyTuring opened 2 years ago

AshleyTuring commented 2 years ago

Given we are using unity and targeting Android and iPhone and have a list of URLs linking to mp4s (encoded with FASTSTART) that we wish to http stream, we present the user with the ability to scroll through the list of (1000s) of videos in batches (of 10) urls. We then get the next batch list of (10) urls when they reach the end of the list in the batch and again programmatically create the video players setting the media source urls and dynamically attaching the next set of video players to the scroll view, removing the previous batch players and so on...

Question: Ideally, please can you send the code required A) to start downloading and caching the 10 videos (perhaps only the first few frames for example first 7 seconds of each video) and download and play the full video at a given index in the list of urls ie: B) if the user stops at a particular video in the list the player should start playing the entire video (from cache ideally) without re-downloading it (given the user can go 1-10 through the list of urls or scroll back through the list 10-1 non-sequentially and stop and wish to view the video at index n in the list)? C) we wish to optimise so the videos play with the minimal amount of download bandwidth required and the user has seemingly 0 second buffer wait time experience while scrolling through, stopping and watching the videos.

We looked at the documentation here

https://www.renderheads.com/content/docs/AVProVideo/articles/feature-caching.html

It seems to suggest we need the ultra version and is not clear if it will work given it does not detail playing a video from a url that is still caching nor limiting the seconds/frames it caches or removing the URLs from the cache (eg upon loading the next 10 urls ideally it should delete the precached first (7 seconds) frames previews from the previous batch).

Alternatively a different approach might be just to show the first frame (issue #38) then start downloading and playing (not using the cache at all or caching and playing from the cache when they stop at a particular video (index in the list of urls), however, would the user potentially have a buffer wait time? And would we still need some code on how to play from cache if that is the recommended approach ie play from cache that is in the state of "caching"?

Some code example and guidance on how to best implement the avpro player would be much appreciated, thank you!

MorrisRH commented 2 years ago

I've uploaded our caching test scene here: Caching.zip This should allow you to see how it all works and how to go about adding support for it to your project.

I'm not sure it's a good fit for your use case though as it's really intended for offline playback of a video at a later date. If you start playback before the video has cached then it will play via the network and depending on bandwidth, stop the download to the cache.

On iOS caching of mp4 videos is not supported, only HLS streams will be cached.

The Ultra edition of the plugin is required to get the caching feature, however it is available in the Trial version of the plugin if you want to try it out.

AshleyTuring commented 2 years ago

Firstly thank you so much, very much appreciated. I agree with your comment that I do not think it is the correct solution for our use case as it, from what we gather, stops the download and in fact doesn't use what it has cached, furthermore, the HLS requirement rules out the majority of our users. Please can we ask if you have another suggestion on how best to implement it, effectively, if we were using a browser to stream the browser would handle saving and caching, perhaps, that can provide us some clues?

Ste-RH commented 2 years ago

Just a bit of additional info regarding functionality on Android...

Chris-RH commented 2 years ago

I'm closing this for now as I believe all questions have been answered.

AshleyTuring commented 2 years ago

Thank you for the help, the solution is not acceptable for us as we do not use HLS however have a majority of folks using iPhones

MorrisRH commented 1 year ago

Reopening as adding support for caching of mp4's on iOS is definitely desirable

AshleyTuring commented 1 year ago

Thanks @MorrisRH

Please see https://github.com/RenderHeads/UnityPlugin-AVProVideo/issues/1288

Not sure if we want to merge that over here or keep it separate...