Video Player Memory Usage
I'm working on a VR app for all Oculus platforms where a primary component is downloading and/or streaming 360 videos for playback. I've been having some problems with the built-in Unity VideoPlayer, specifically in the Android builds due to memory constraints.
I've done all of the legwork to profile the app extensively, and reduce repeat memory allocations as much as possible (all of our code generates 0B after scene setup, for reference). When profiling the video playback scene for a 6K video, memory usage actually goes down because we're unloading some skybox and UI-related textures among other things.
The first thing I notice is that VideoPlayer memory usage isn't profiled properly. Monitoring available memory on any device (Desktop or Android) will show that the app memory usage balloons as playback starts and the Unity profiler doesn't catch it. The obvious culprit is the videos. Rather than load clips, I'm simply providing a URL to stream the video from the server or the downloaded file's location. Still, memory is allocated for the size of the file (and, oddly, 2x that momentarily just before playback starts on 6K videos). Obviously, with a reasonable length of 6K video, this has a high likelihood of getting the app killed by the Go's OS as I skirt memory limitations, particularly on devices without enough free storage to cache some of the required memory.
Now, for my actual question since the VideoPlayer is likely working as intended: does anyone know a pre-packaged way to stream videos from disk (and an online source, preferably) while keeping memory utilization low? For reference, these videos have been extensively tested in a variety of standalone 360 video player apps on all pertinent hardware and have no problems there, so there's definitely SOME way to do it, though perhaps not from within the Unity engine.
Answer by yoiang · Mar 04, 2021 at 03:55 PM
@scottishrob13 did you ever find a method for streaming video from disk? I will be running up to this issue soon as well!
Also was the profiler issue ever resolved?
After some back and forth with Unity support, it looks like the VideoPlayer will stream files from disk properly but, at certain resolutions with certain types of encoding, the operating system falls back to a software implementation that requires additional memory overhead. The reason the Unity profiler doesn't catch this is because it's not actually occurring within Unity, it's the Microsoft Media Foundation (in my case) that's the problem. The good news is that it shouldn't be a problem for most people unless you're doing some crazy high-resolution video work for VR or something like that. If you do run into that problem, they suggested "using webm files with the vp8 video codec and vorbis audio codec" with the following disclaimer:
The vp8 codec supports up to 16384 x 16384. Our implementation on Windows - as on all platforms except Android and Switch - is a software codec so it will have predictable behaviour. Because it is purely software, however, higher resolutions will require more horsepower.
Your answer
Follow this Question
Related Questions
Making VR-screenshot on Android 0 Answers
Playing a VR video on Android - Google Cardboard 0 Answers
Playing a VR video on Android - Google Cardboard 0 Answers
Best way to store video content for later playback in Unity? 0 Answers
How to play a video inside a canvas with world space in unity3d 0 Answers