Search Unity

Question VideoPlayer reserves a lot of memory on iOS

Discussion in 'iOS and tvOS' started by Ufid016, Mar 18, 2021.

  1. Ufid016

    Ufid016

    Joined:
    Oct 25, 2017
    Posts:
    2
    Hello.

    Playing a video with VideoPlayer on iOS uses more memory than necessary.
    The app consumes + 350MB more memory just by playing 35MB of 4K video.

    This memory does not appear in Unity Profiler, and if you check it in Memory of Debug Navigator of Xcode, it is supposed to be used by the application itself.

    We need to play multiple 4K-scale videos, and Jetsam may kill the app as it is.

    If you look at Xcode's GPU Frame Capture, you can see that 10 CoreVideos (Texture 2D) with the same resolution as the video resolution are allocated.

    I think this number of buffers is too large. (Isn't it okay to have 3-5 buffers?)

    Isn't this large number of buffers a problem on the Unity side?
    Or is there a way to control the number of buffers?

    Playback specs:
    Versions: Unity 2019.4.21f1, Xcode 12.4
    Model: iPhone XR / iPhone 6S / iPad Pro 12inch (3rd Gen)
    Video: 3840x2160 / H.264 / Main@L5.2 / 22.5Mbps (CBR) / 29.97fps / FileSize 34.6MB

    ios_videoplayer_memory.jpg
     
  2. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    File a bug report if this is an undesired behavior.

    I looked at the implementation code of Unity’s Video Player and did not see anything odd in memory management or specifically calling for caching 10 CoreVideo buffers. It could be that the buffers are managed by AVAssetReader.

    A similar behavior can be found across iOS whenever the camera is used. iOS would automatically allocate several buffers in the current camera resolution as backup to avoid frame drops.
     
  3. Ufid016

    Ufid016

    Joined:
    Oct 25, 2017
    Posts:
    2
    Hello, Thank you for the answer.

    I also saw the converted code in Xcode, but it seems that Unity does not seem to control the number of buffers.

    I don't know much about iOS, but is there an option to control the number of buffers in AVAssetReader?
    (I'm thinking about making a similar plug-in to solve it)
     
  4. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    I am not aware if the high-level API allows it. You'll probably handle the video decoding yourself using VideoToolbox
     
  5. fxlange

    fxlange

    Joined:
    Dec 20, 2016
    Posts:
    45
    Hi @Ufid016,

    did you by any chance find a solution for this? I'm also running into memory issues. 5mb of video is allocating ~400mb ram.
     
  6. jamesjxiao

    jamesjxiao

    Joined:
    Mar 1, 2018
    Posts:
    9