Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Issue with webm VP8 video transparency in Unity for Android

Discussion in 'Getting Started' started by neitdirect, May 10, 2024.

  1. neitdirect

    neitdirect

    Joined:
    Feb 8, 2020
    Posts:
    2
    I'm using Unity to create an application that displays video from a URL. The video is in webm format with the VP8 codec. In the Unity editor, everything works as expected - the video is displayed with a transparent background. However, when building the project for Android, the transparency is lost, and the video is displayed with an opaque background. I don't use shaders, but I tried it didn't help either
    Why is video not transparent on Android?

    Code (CSharp):
    1. [SerializeField] private RawImage _rawImage;
    2. [SerializeField] private UnityEngine.Video.VideoPlayer _videoPlayer;
    3.  
    4. private void Start()
    5. {
    6.     string pathToSaveVideo;
    7.  
    8.     if (Application.platform == RuntimePlatform.Android)
    9.     {
    10.         pathToSaveVideo = Path.Combine(Application.persistentDataPath, "12.webm");
    11.     }
    12.     else if (Application.platform == RuntimePlatform.IPhonePlayer)
    13.     {
    14.         pathToSaveVideo = Path.Combine(Application.persistentDataPath, "12.webm");
    15.     }
    16.     else
    17.     {
    18.         pathToSaveVideo = Path.Combine(Application.persistentDataPath, "12.webm");
    19.     }
    20.     _videoPlayer.url = pathToSaveVideo;
    21.     _videoPlayer.Prepare();
    22.     _videoPlayer.prepareCompleted += (videoPlayer) =>
    23.     {
    24.         _videoPlayer.Play();
    25.     };
    26. }
    Video Unity editor

    upload_2024-5-10_20-52-39.png

    Video on an android (the black spot is the display is cracked)

    upload_2024-5-10_20-51-41.png
     

    Attached Files:

  2. mccartywaters7484922

    mccartywaters7484922

    Joined:
    May 13, 2024
    Posts:
    1
    Unity offers a feature called "Transcoding." This allows you to transcode your video files within Unity during the build process. By enabling transcoding for the VP8 codec, Unity will convert your videos to a format that is compatible with Android's native decoder and supports transparency.
    Here's how to enable transcoding:
    • Go to Project Settings > Player > Video.
    • Under "Supported Video Codecs", check the box next to "VP8".
    • Make sure "Allow Transcoding" is enabled.
     
  3. neitdirect

    neitdirect

    Joined:
    Feb 8, 2020
    Posts:
    2
    What version of Unity are you using, I can’t find similar settings? I have version 2021.3.1f1