Search Unity

Question Playing video from Streaming Assets folder is choppy

Discussion in 'Audio & Video' started by EthanHooper1023, Aug 31, 2022.

  1. EthanHooper1023

    EthanHooper1023

    Joined:
    Jan 19, 2017
    Posts:
    24
    I am trying to play a video from the streaming assets folder on android. I can get it to play but it is very choppy.
    The reason I need to pull from the streaming assets folder is that I am using the library ffmpeg to bake stickers the user can place over the video. I am treating the stickers as watermarks and ffmpeg can only pull from the streaming assets folder

    Lastly, I am getting the video and audio separate so I can swap them out(for multilanguage support) It works well right now but the video is choppy and the audio becomes desynced from the video.

    Is there a method for preloading the video besides checking if it's prepared?
    I have tried to wait for upwards of 30sec after it's prepared to let it "Load" but still pretty choppy

    Code (CSharp):
    1. public void StartVid()
    2.      {
    3.          string url = "file://" + Application.streamingAssetsPath + "/" + "video.mp4";
    4. #if !UNITY_EDITOR && UNITY_ANDROID
    5.              url = Application.streamingAssetsPath + "/" + "video.mp4";
    6. #endif
    7.          //We want to play from url
    8.          videoPlayer.source = VideoSource.Url;
    9.          videoPlayer.url = url;
    10.          StartCoroutine(prepareVid(Path.Combine(Application.streamingAssetsPath, "audio.wav")));
    11.      }
    12.          private IEnumerator prepareVid(string file)
    13.          {
    14.              videoPlayer.Prepare();
    15.              while (!videoPlayer.isPrepared)
    16.              {
    17.                  Debug.Log("Preparing");
    18.                  yield return null;
    19.              }
    20.  
    21.              UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(file, AudioType.WAV);
    22.              yield return request.SendWebRequest();
    23.  
    24.              audioSource.clip = DownloadHandlerAudioClip.GetContent(request);
    25.  
    26.              Debug.Log("Prepared");
    27.              //yield return new WaitForSeconds(30);
    28.              videoPlayer.Play();
    29.              videoPlayer.started += (trash) => { audioSource.Play(); };
    30.  
    31.              request.Dispose();
    32.          }
    Thank you
     
  2. dezzell

    dezzell

    Joined:
    Feb 7, 2015
    Posts:
    32
    Any Luck on this? It seems if the video size is around 100 mb, all works good, if over 300 mb, the video is choppy. I used your code to prepare my video, and it still choppy and sound cuts in and out. I would really like to utilize videos from the StreamingAssets folder to play course videos.

    Video resolution is 640x480 and plays perfectly fine on Windows and Mac. Very choppy in Unity3D using Video Player.

    Strange, I have a YouTube plugin for Unity3D, and the videos seem to play fine from YouTube. Playing locally is very choppy.

    Well I will keep investigating, checking if you found a solution.
     
  3. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    Hi @dezzell. Can you explain what you mean by "choppy" (a video would be appreciated)? Is it that they are some frames dropped? Are you on Android like the original post? On Windows, I can play a 4k video without issue. Maybe if you have "skip on drop" enabled, I would try disabling it. It sometimes causes problems when the codec is struggling to decode frames. Also, can you transcode your file to webm to see if it is mp4 specific? I never used any YouTube plugin for Unity3D, so I can't tell if it is the issue.
     
    geoinnovacion likes this.
  4. dezzell

    dezzell

    Joined:
    Feb 7, 2015
    Posts:
    32
    Just seen your message, had moved on to other things and never came back. It is unwatchable. I tested with 10 different videos and it seems at or around 100 MB 640 resolution plays fine. If I load 200+ mb videos, the sound and video continuously goes in and out. I was looking at AV Pro, thou 800 dollars is a little much. I've done the script to download the video and play, and changed the settings for first frame and so on. I am looking to see if some other processes are going on and causing the issue. I will create an empty scene and load the same videos and see what happens. I have other Unity3D Apps, mobile Android, PC, and Apple that plays videos around 100 MB fine. I've not done over 100 MB on those apps. This project is to load personal videos in a VR space, currently on PC utilizing Quest 2 / Rift. Walk up to a TV and browse through years of videos for family. So far, I've not had luck with over 100 MB videos and it cuts in and out, not smooth at all. I just upgraded to 2022.2.1f, and will do another test and let you know what happens.

    I tried with 4K and 2K and 640 and just all do the same thing, Will keep you posted.
     
  5. dezzell

    dezzell

    Joined:
    Feb 7, 2015
    Posts:
    32
    I created an empty scene and all videos over 100 MB seem to play perfectly fine without anything else in the scene. So must be something causing the videos to run slow in my other scene. Will need to do a process of elimination to see what it could be.
     
  6. dezzell

    dezzell

    Joined:
    Feb 7, 2015
    Posts:
    32
    This is interesting, the problem was with the Bathroom Mirror which was causing the video player to hose up. The Bathroom Mirror is in the other room, not even in the current scene, using a Render Texture with Camera Target Texture. After disabling the Mirror, the video plays fine. Very strange that this would cause issues with Video Player. Has anyone else had an issue with a Mirror and Video Player? Will need to play around with the Mirror and Camera settings to see what happens. All this time I was thinking the videos were too large to play, and it was just a mirror, lol. And it seems the performance is better without the Mirror as well. Very strange.

    Well that solves another fun issue, I had issues with SkyManager and lighting UpdateScene messages, and after disabling SkyManager, the UpdateScene messages went away and Everything works better. Fun Fun Fun!!! Been at this since 2007 and always something, lol... Be nice to just develop without issues or limitations.