Search Unity

Video Playing video on Android == lag & stuttering

Discussion in 'Audio & Video' started by jocyf, Mar 30, 2018.

  1. jocyf

    jocyf

    Joined:
    Jan 30, 2007
    Posts:
    288
    I have a project that use several videoclips. It works perfectly fine on windows & IOS, but it's imposible to use it on Android, the videos always plays with lags and sttutering.

    The video clips have several resolutions (956x720, 960x960, 512x512, 256x256) all of them are H264, BaseLine 3.0. I tested them with and without transcoding. Multithreaded Rendering enabled and disabled, force to use OpenGL 2, 3 & Vulkan. Nothing seems to work at all, it's imposible to make them play as they should on Android (I repeat, it works fine on Windows & IOS; no weird things happening there).

    VideoPlayer is rendering usign MaterialOverride Render Mode (an Unlit/Texture Material).

    The app only plays one video each time (there is not several videos playing at once) and even fails playing at 256p resolutions. I just can't believe that Unity's videoplayer is still giving this kind of problems!!!

    Any idea?
     
    Last edited: Mar 30, 2018
    adamstone711 likes this.
  2. rjonaitis

    rjonaitis

    Unity Technologies

    Joined:
    Jan 5, 2017
    Posts:
    115
    Hi, it would be best to make a bug report for such case. Need to know which Unity version and android device model you are using to reproduce this problem, also need the video files to check for malformed meta data.

    Given huge variety of android devices with different capabilities it's hard to tell what could be possible be wrong.
     
  3. marcusestes

    marcusestes

    Joined:
    Feb 2, 2017
    Posts:
    17
    Try disabling multi-threaded rendering in player settings.
     
    Eater_Games likes this.
  4. jocyf

    jocyf

    Joined:
    Jan 30, 2007
    Posts:
    288
    I tried that but didn't worked.
     
    turelmert_unity likes this.
  5. paulksi

    paulksi

    Joined:
    Nov 9, 2015
    Posts:
    27
    Hi, Did you found a solution?
     
    turelmert_unity likes this.
  6. Moshebeeri

    Moshebeeri

    Joined:
    Jun 18, 2021
    Posts:
    1
    Same issue with Oculus Quest 2, same video play smooth on my laptop, yet on VR it completely lag
     
    Saravana_Vins likes this.
  7. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    We have different implementations depending on the platform. It is probably why the video could play smoothly on your laptop and laggy on your VR. If you are not on the latest version of Unity, you could try and see if the problem was fixed. If you still have a problem, I would recommend making a bug report and we will try to help you.
     
    Last edited: Aug 31, 2021
  8. GandhiOfTheFoG

    GandhiOfTheFoG

    Joined:
    Oct 17, 2018
    Posts:
    6
    Having the same problem with 2020.3.9
     
  9. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    Can you share your project or recreate a small project that reproduces the issue?
     
  10. 3DNewsman

    3DNewsman

    Joined:
    Nov 3, 2012
    Posts:
    14
    We’re having the same problem and have been working for at least a week with different approaches but still get big lags on Quest 2, with short little 5 second clips. It seems related to stopping the videos and disposing of them in memory. But we have no idea why or how to work around this.
    Did you find a solution?
     
  11. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    Can you share a project that reproduces the bug? Can you check with the profiler what the issue is? Maybe it is unrelated, but someone else is having performance issues on the Quest 2 https://forum.unity.com/threads/sto...ry-long-time-on-android.1062467/#post-7630558
     
  12. jocyf

    jocyf

    Joined:
    Jan 30, 2007
    Posts:
    288
    I'm having no problems on my Quest & Quest 2 devices.
    Here is what I'm using:

    - Handbrake to "convert" the 'master' video clip:
    Format: h264 (.mp4),
    Coder profile: Baseline 3,
    Coder preset: "fast" or "very Fast",
    Quality: 22 to 24,
    Audio: NO audio in the video (erase any audio channel), no subtitles, no chapters.
    Video size in my case is 2048x2048.... I'm using chroma videos with a home made shader. If posible use cheap Unlit/Texture shader as main material.

    Import the video into Unity with NO transcoding (I never transcode my video clips thats the hole point of using HandBrake).

    - Extract de audio using VLC, save it in wav format an import in Unity.

    Play the video and the audio clip usin an script to do it (play /stop both clips at once). I'm my case is workng fine. The onky issue is when preparing a video clip, it takes some time (it's a expesive task so I assume isn't any workaround there).

    In my experience using audio channels in videoclips always cause troubles so I ended up using a home made player to play video & audio as independent sources. You can try it first withpout any audio at all just to check if video player is working fine in the Quest.

    Tested using Unity 2018.4.x, 2019.4.x, 2020.3.x
     
  13. 3DNewsman

    3DNewsman

    Joined:
    Nov 3, 2012
    Posts:
    14
    Hi there. We submitted a bug with project for reproduction. The other post you were referring to was also from our project. Please let us know if you're able to take a look -- and thanks for your time.

    https://fogbugz.unity3d.com/default.asp?1384846_fit2h1nprud5pji8
     
  14. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    Thank you! We will try to look and come back to you before Christmas.
     
    3DNewsman likes this.
  15. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    Hi! I was finally able to work on this bug. We found out that some blocking system call was done on the main thread. We are going to fix this and backport it. On that note, the issue seems to be more prevalent in your case because you loop multiple small clips. I would recommend combining all the clips into one. Not only will it be more performant even after the fix, but it will also be smoother and more seamless.
     
  16. merrythieves

    merrythieves

    Joined:
    Apr 28, 2021
    Posts:
    14
    Hello I am running into the same issue trying to play several small clips in a loop. I tried using handbrake to optimize them all without luck. I like your suggestion of combining video clips all into one, but how can you tell the video player to loop only a specific section of the master video?

    Also, which version will have the fix?
     
  17. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    The idea would be to have one clip with all combined clips and have the individual clips in the build. So you can switch the clip to the one you need to loop. If for some reason you really need to switch clips often, I would recommend having multiple VideoPlayer ready with your clips so you can stop and play the one you need. There is a memory overhead of doing this but it could be fine for you. I would not recommend, you try to implement looping with the VideoPlayer.time as this kind of jump can behave differently on platforms.

    It is currently in review to land in 2022 but, we are going to backport this fix to all currently supported Editor versions so 2021, 2020, and 2019.
     
  18. LB_Chris

    LB_Chris

    Joined:
    Jan 29, 2020
    Posts:
    33
    Hey, I was searching for information regarding one of our problems and it feels somewhat connected to what I read here. We are using the Oculus Quest 1. We also want to loop seamlessly and utilize two unity video players with one video player playing the video actively and the other one acting as the preparing video player that starts playing once the first one is done. They then swap roles.

    While the preparing video player prepares, the frames drop to about 30, which is fine, and everything worked okay-ish so far, yet we recently started encountering problems with the buffering video player failing at loading the video every now and then. The VideoPlayer.errorReceived message just states "cannot read file" after it tried to prepare the video for about 7 seconds.

    We figured that reducing the resolution and/or bit rate of the videos reduces the frequency of the error and reducing it to a certain point resolves the error completely, but we are displaying 5760x2880 resolution, 35mbits/s, 360 degree videos which suffer a lot from reduced resolution or a reduced bit rate. We optimally would find a solution to keep high video stats while also not encountering the error at all.

    Our question to you @The_Island is if you know some reasons to where the "cannot read file" error originates from? Could memory/video memory be a bottle neck? Maybe the read rate of the videos?
    Also, do you know if there is a way for the video players to keep the videos loaded somehow (I just assume they don't)?
     
  19. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    @LB_Chris Would you mind opening another thread? It is easier to manage different issues :). And would you mind adding the full error or is it just "cannot read file"?
     
    Last edited: May 18, 2022
  20. LB_Chris

    LB_Chris

    Joined:
    Jan 29, 2020
    Posts:
    33
  21. dormouse

    dormouse

    Joined:
    Mar 1, 2011
    Posts:
    82
    Hello I am having the same issue with Quest 2 and Unity 2021.3.4f1, with videoplayer i can play a 3840*3840px 3D format video without lag on Quest 2. But when i play another video (2160*1080px, mono 360 video), the Quest has a significant lag/sttutering...do we have a solution now ?
     
  22. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    Can you check the profiler for any clue @dormouse?
     
  23. dormouse

    dormouse

    Joined:
    Mar 1, 2011
    Posts:
    82
    profiler on MacOS ? Playing issued video has no significant lag on MacOS with Unity Play Button. Only having lag issue with APK installed on Quest 2...Profiler information still useful ?
    thanks
     
  24. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
  25. dormouse

    dormouse

    Joined:
    Mar 1, 2011
    Posts:
    82
    Ok, thanks for the info. i will make a profile and share with you here later.
    Finally, i found something interesting, sharing with you:

    Same clip same unity Project, with of 360 mono video, with Graphics APIs-> OpenGLES3 works pretty good in Unity Game Preview and Quest 2.
    When i switch Graphics APIs -> Vulkan, only Unity Game Preview looks good without lag. On Quest 2, lag lag and lag.....this problem is related to Vulkan i think...
     
    andreiagmu and carlos-molnao like this.
  26. adamstone711

    adamstone711

    Joined:
    Sep 8, 2018
    Posts:
    9
    ugh.. me too. My app works fine in the editor, and iOS, but android builds are still choppy.
    My app downloads short videos (approx 1 second) and plays them when a button is clicked.

    https://apps.apple.com/jp/app/vocabviddys/id1507752099

    https://play.google.com/store/apps/details?id=com.AdamStone.TangoViddys&hl=ja&gl=US

    I have tried the multithreading & vulkan settings, have set the version to a very early version too, this app needs to run on as many devices as poss,,
    i think it is a very simple app... have not been able to find anything helpful on the googles so far...
    any help appreciated !!!
     
  27. LuigiNicastro

    LuigiNicastro

    Joined:
    Feb 7, 2018
    Posts:
    34
    Any update on how to fix this running Vulkan?
     
  28. unity_65D8B279F4E596666C05

    unity_65D8B279F4E596666C05

    Joined:
    Dec 3, 2021
    Posts:
    1
    This works for me in quest 2
    Thanks
     
  29. Rincewind1979

    Rincewind1979

    Joined:
    Jan 31, 2023
    Posts:
    1
    Many, many thanks for your post! I have spent many days and tried many things. Nothing helped.
    Your method / description works perfectly.
     
    jocyf likes this.
  30. JuGiGo

    JuGiGo

    Joined:
    Aug 7, 2019
    Posts:
    1
    I was running into an issue getting videos to play smoothly in an android app. I originally exported them from After Effects but after seeing @jocyf's comment used handbrake to encode the videos and working perfectly now
     
    jocyf likes this.
  31. RSH1

    RSH1

    Joined:
    Jul 9, 2012
    Posts:
    256
    I'm now getting this with 2022.3.7f1, I didn't with previous versions. The only thing that worked was dropping the FPS down to 15, previous versions happily played 30/60FPS videos smoothly.
     
  32. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    It is really hard to know if you have the same issue or not. I am working on a regression on Android for video with variable framerate.
    https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-14136

    It look like it "works," but if you turned off the skipOnDrop, does it freeze mid-way? You can also quickly check with this site the video settings. If it is variable framerate, you can reencode to constant framerate as workaround https://mediaarea.net/MediaInfoOnline
     
    Last edited: Sep 5, 2023
  33. halinc

    halinc

    Joined:
    Feb 24, 2019
    Posts:
    32
    Hi, I am experiencing exactly this: stuttering videos on Android if the framerate is variable (mp4 not webm). I hope it will be fixed in 2022 LTS soon? Thanks for working on it!
     
  34. Rave-TZ

    Rave-TZ

    Joined:
    Jul 21, 2013
    Posts:
    77
    I'm experiencing the exact same problem when building to Quest 2 / Pro. T
    I'm experiencing this on Quest 2 / Pro builds. The video just freezes if I turn off SkipOnDrop. I also found out that videos WITHOUT audio play fine.

    Tested H.264 and H.265 at 1920x1080
    Vulcan API
    Android SDK target 32
    Unity 2022.3.5f1
     
  35. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    Your video probably has a variable framerate. The easiest way to fix it right now would be to make sure the video is a constant framerate. If I am not wrong, you are experiencing this issue. While it is a "workaround," I would still recommend using constant framerate even after we fix it. So, you might as well do it now.
     
  36. roboticacesmac

    roboticacesmac

    Joined:
    Jan 26, 2022
    Posts:
    1
    Thanks, it worked for me. Here, when I had Vulkan defined and the game installed on meta quest 2, when I tried to record the screen it started to freeze. When I enabled OpenGLES3, it worked normally.

    I use 2 low resolution videos (804x806, 30fps) rendered in a raw image, with unity in version 2021.3.16f1