Search Unity

Video Problem videoPlayer and Windows 7

Discussion in 'Audio & Video' started by LabMatti, May 10, 2018.

  1. LabMatti

    LabMatti

    Joined:
    Jan 19, 2018
    Posts:
    58
    Hi all!

    I've a plane with a videoPlayer component and I load the video from streamingAssets with a script that I found here in this forum.
    All works well but if I try to run this with windows 7, some video doesn't play.

    This is the script:


    Code (CSharp):
    1. IEnumerator playVideo()
    2.     {
    3.         try{
    4.             Destroy(videoPlayer);
    5.             Destroy(audioSource);
    6.         }catch{
    7.  
    8.         }
    9.           //Add VideoPlayer to the GameObject
    10.         videoPlayer = gameObject.AddComponent<VideoPlayer>();
    11.         //Add AudioSource
    12.         audioSource = gameObject.AddComponent<AudioSource>();
    13.  
    14.         /*videoPlayer = GetComponent<VideoPlayer> ();
    15.         audioSource = GetComponent<AudioSource> ();*/
    16.         //Disable Play on Awake for both Video and Audio
    17.         videoPlayer.playOnAwake = false;
    18.         audioSource.playOnAwake = false;
    19.         audioSource.Pause();
    20.         //We want to play from video clip not from url
    21.        
    22.         videoPlayer.source = VideoSource.VideoClip;
    23.         // Vide clip from Url
    24.         videoPlayer.source = VideoSource.Url;
    25.         videoPlayer.url = Application.streamingAssetsPath +"/"+ System.IO.File.ReadAllText (Application.dataPath + "/Resources/videoSelected.txt");
    26.         //Set Audio Output to AudioSource
    27.         videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
    28.         //Assign the Audio from Video to AudioSource to be played
    29.         videoPlayer.EnableAudioTrack(0, true);
    30.         videoPlayer.SetTargetAudioSource(0, audioSource);
    31.         //Set video To Play then prepare Audio to prevent Buffering
    32.         videoPlayer.clip = videoToPlay;
    33.         videoPlayer.Prepare();
    34.         //Wait until video is prepared
    35.         WaitForSeconds waitTime = new WaitForSeconds(1);
    36.         while (!videoPlayer.isPrepared)
    37.         {
    38.             Debug.Log("Preparing Video");
    39.             //Prepare/Wait for 5 sceonds only
    40.             yield return waitTime;
    41.             //Break out of the while loop after 5 seconds wait
    42.             break;
    43.         }
    44.         Debug.Log("Done Preparing Video");
    45.         //Assign the Texture from Video to RawImage to be displayed
    46.         image.texture = videoPlayer.texture;
    47.         //Play Video
    48.         videoPlayer.Play();
    49.         //Play Sound
    50.         audioSource.Play();
    51.         Debug.Log("Playing Video");
    52.         while (videoPlayer.isPlaying)
    53.         {
    54.             Debug.LogWarning("Video Time: " + Mathf.FloorToInt((float)videoPlayer.time));
    55.             yield return null;
    56.         }
    57.         Debug.Log("Done Playing Video");
    58.  
    59.     }
    The video that I need now is 500Mb+, has a width of 3000px and it's an mp4 (H264). It works in windows 10 and doesn't in windows 7. Any Idea?

    I tried other videos. With lighter(50-100Mb) videos works well but with a 4K video I've the same problem as before.
     
    ibyte likes this.
  2. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,048
    I have a similar issue on Win7 and trying to force Codec to VP8 hangs Unity.
     
  3. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    260
    Hi!

    The H.264 decoder on Windows 7 is limited to 1920 x 1088, as pointed out in the "Format Constraits" section of https://msdn.microsoft.com/en-us/library/windows/desktop/dd797815(v=vs.85).aspx. Above Windows 7, the limit is 4096 × 2304.

    Of course, it's quite hard for you to realize that under the hood, Unity on Microsoft platforms is decoding H.264 using Media Foundation... So I've recently added - in 2018.3 ... - a warning that explains, upon playback error, what the resolution is and what the limit is in order to help users identify that this is a hard limit on the platform.

    Using vp8 for larger resolutions (the limit is 16384x16384) is indeed the right approach, but since transcoding from H.264 to vp8 will still need the Windows implementation to decode the source, you cannot use Unity to transcode to vp8. Instead, you should use an external tool such as ffmpeg. ffmpeg is quite a flexible tool with lots of options for converting to/from about anything.

    Here's an article on one way to use ffmpeg to convert from mp4 to webm:

    https://thethemefoundry.com/blog/convert-mp4-to-webm/

    You can probably find many other examples by looking around. Once you're done with the conversion, importing the resulting clip in Unity will let you use this clip on Windows 7. Note that on most Unity platforms (all except Android and WebGL) the vp8 decoder is a software implementation so it will be CPU-intensive.

    Hope this helps!

    Dominique Leroux
    A/V developer at Unity