Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Video Stopping a VideoPlayer takes a very long time (on Android)

Discussion in 'Audio & Video' started by Midiphony-panda, Feb 22, 2021.

  1. Midiphony-panda

    Midiphony-panda

    Joined:
    Feb 10, 2020
    Posts:
    234
    Hello,

    I am currently working on a project where we would like to play multiple videos (three max at the same time).

    Inside a scrollable list, each item includes two or three videos playing.
    We can go from an item to another by swiping, and the currently focused item plays its videos. Items are recycled while the user is scrolling.
    In total, around 10 VideoPlayers are created, ready-to-go and preparing videos as needed.

    However, when stopping a VideoPlayer or switching clips, we are encountering big framerate hitches. When looking at the profiler, stopping a VideoPlayer seems pretty expensive (VideoPlayer.DestroyPlayback takes more than 40 ms on the main thread to execute - for each VideoPlayer).

    upload_2021-2-22_9-41-31.png

    Test device : Samsung Galaxy S7 SM-G930F - Android 8

    Is it normal ? Am I missing something ?
    If it is normal, what would be the recommended way to reuse/recycle VideoPlayers for this use case ?


    Thanks
     
  2. benbarefield-lighthaus

    benbarefield-lighthaus

    Joined:
    Sep 16, 2019
    Posts:
    7
    We're seeing a similar issue. Did you find anything?
     
  3. Midiphony-panda

    Midiphony-panda

    Joined:
    Feb 10, 2020
    Posts:
    234
    I have stopped working on video features but at the time I was still at it, we began switching to AVPro Video.
     
  4. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    256
    Hi!

    Generally speaking, you're better off doing with the minimum number of concurrent VideoPlayers on Android; each device/OS version has different limits above which it may either fail or fallback to a slower implementation.

    It'd be interesting to hear if you're having the same behaviour when sticking to 2-3 VideoPlayers.

    This being said, we're delegating a lot of tear-down work to background threads exactly to avoid what you are reporting here, so it appears we may have some more backgrounding to do on Android.

    If you still have a version of your project that uses the VideoPlayer and submit this (or a simplified version of it) as a bug report, we'd be happy to take a look to see what exactly is consuming main thread time in this context.

    Thanks in advance,

    Dominique Leroux
    A/V developer at Unity
     
    Midiphony-panda likes this.
  5. benbarefield-lighthaus

    benbarefield-lighthaus

    Joined:
    Sep 16, 2019
    Posts:
    7
    Thanks for the reply Dominique.

    One thing I tried to avoid calls to DestroyPlayback, is to use a VideoPlayer per VideoClip we want to play, and call Pause() instead of Stop() on the running player. Changing .clip on the VideoPlayer seemed to result in calls to DestroyPlayback, so this approach also avoids that. (This also has a potential added benefit of being able to do some clip pre-preparation - though I have no idea if this is helping at all) We generally only have up to two Players playing at any given time. I'm still seeing a call to DestroyPlayback here and there, and am not really sure what's causing it. Based on what you said, it sounds like that could be forced by Android and there may be no way around it?

    I'd also like some clarification on "2-3 video players" - does this mean 2-3 total VideoPlayer components in the scene, or 2-3 VideoPlayer components playing (while there may be more in the scene not playing)?

    In the past I've also seen a few spikes due to DecodeNextFrame.
     
    Last edited: Nov 3, 2021
  6. benbarefield-lighthaus

    benbarefield-lighthaus

    Joined:
    Sep 16, 2019
    Posts:
    7
    @DominiqueLrx just a small update - we created a build with only a single video player, and cycled the .clip value. In the profiler, I'm seeing a pretty big cpu spike every time the clip changes, with DestroyPlayback being the culprit. We're working on the Oculus Quest 2. We may be able to work on a repro build in the near future, but I suspect it wouldn't be hard to reproduce on your end.