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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

playing MP4 video in unity pro

Discussion in 'Editor & General Support' started by Arcanor, Apr 29, 2013.

  1. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    283
    I'm having trouble getting a video to play in unity pro. I imported an MP4 video, created a plane, dragged the video to the plane, then attached a C# script that contains the following code:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayMovie : MonoBehaviour
    5. {
    6.     private MovieTexture mtex;
    7.  
    8.     // Use this for initialization
    9.     void Start ()
    10.     {
    11.         mtex = gameObject.renderer.material.mainTexture as MovieTexture;
    12.         mtex.Play();
    13.     }
    14.    
    15.     // Update is called once per frame
    16.     void Update ()
    17.     {
    18.         if (!mtex.isPlaying)
    19.         {
    20.             print("movie playing status: " + mtex.isPlaying + ".");
    21.             mtex.Play();
    22.         }
    23.     }
    24. }
    25.  
    However the video does not start playing. I definitely am running unity pro, 4.1.2f1.

    In addition, I've verified that this particular video is able to be played using QuickTime on my system, which is running Windows 7 Pro.

    I created the MP4 video using Premiere Pro CS6, and exported using the H.264 format and YouTube HD preset.

    Any clues?

    Thanks in advance!
     
    Last edited: Apr 29, 2013
  2. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    283
    I was able to get this to work using a different video, which is an MPG. The documentation doesn't seem to explain why one would work and not the other.


    http://docs.unity3d.com/Documentation/Manual/VideoFiles.html


    According to the documentation: "Supported file types are what your QuickTime installation can play "

    The documentation also specifically lists MP4 as one of the valid formats. I verified that the MP4 file worked just fine in QuickTime. Why won't it work in Unity Pro?

    Are there additional unlisted restrictions regarding CODEC?
     
  3. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    283
    I submitted a bug report to UT and got a response confirming they were able to reproduce the problem. So my code and usage was fine after all. :)
     
  4. Desktopdaydreams

    Desktopdaydreams

    Joined:
    Nov 20, 2010
    Posts:
    154
    Thanks for this @Arcanor! We've been banging our collective heads against the wall! Looks like its just mp4 though on our end as we can use .mov's but they are incredibly large!

    Did you ever receive an update?

    Cheers,
     
  5. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    283
    I never got an update, but I didn't expect one. UT said they would apply the fix in some future release, and to be honest I'd already worked around the problem, so I haven't checked to see if it's been delivered yet. Since you're asking about it I'm guessing it's still broken. Which version are you using?
     
  6. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Unity actually uses Ogg Theora for video. The movies that your QuickTime can play need to be converted into Ogg Theora for inclusion in your game. (This is similar to how Unity can import maya mb or ma files, fbx files, and so on. These import formats are not used in the shipping game.) You can try converting your MP4 into Ogg Theora directly, and not rely on Unity doing this conversion for you.
     
  7. Desktopdaydreams

    Desktopdaydreams

    Joined:
    Nov 20, 2010
    Posts:
    154
    @Arcanor we're using 4.3.2f1 but we also found a work around. We optimized the video and exported out to a .mov, the video is quite short so it isn't too large.

    @Graham thanks for the reply! Yeh we tried using Micro video convertor and a couple of online .ogg converters but the resulting quality is quite poor. Its a shame After effects or Adobe premier don't export directly to .ogg. Maybe some more research is needed when I get time :)

    Thanks guys.
    Tim
     
  8. Aldo

    Aldo

    Joined:
    Aug 10, 2012
    Posts:
    173
    I know this is old but still
    it is not about the mp4 it is about the codec used to export, apparently there are plenty of mp4 formats >.>
     
  9. mikamikem

    mikamikem

    Joined:
    Mar 3, 2013
    Posts:
    10
    For anyone still trying to figure this out. I was having problems at first, but got it to work in Premiere CS5.5 with these settings (not sure which change made it work since I just changed a bunch all at once):

    Format: H.264
    TV Standard: NTSC
    Resolution: 1920x1080
    FPS: 30
    Pixel Aspect Ratio: Widescreen 16:9
    Profile: Basic (I think this might have been the trick)
    Level: 4.2
    Bitrate Encoding: CBR (This was also a possibility since I was using VBR before and that wasn't working)

    I hope it helps someone else if they get stuck.
     
  10. Priyanka-Rajwanshi

    Priyanka-Rajwanshi

    Joined:
    Nov 22, 2013
    Posts:
    8
    Hello

    I tried converting the file format to ogg thera (.ogv) but the video does not play now and mp4 has low quality.
    What exactly do I need to do?
    Also , i am confused with the fact that it is written that Unity only supports formats that are supported by Quick Time Player and ogg is not included, how can it work?
     
  11. Lahmeck

    Lahmeck

    Joined:
    May 14, 2015
    Posts:
    5
    Hi all!!

    I am using Unity 5.3.4f1, non PRO Edition, and I was trying to import a video and use as a Texture. After many attempts, you can imagine, looking for a proper video converter (my video is a MP4 file), following many instructions from internet forums and so on, I couldn´t import the video so Unity is able to use it as a Texture.

    Finally, and it sounds crazy, I drag the video, converted to OGG and even the original MP4 one, to "Materials" folder in Assets. I was doing that in other folder before. And it worked. Amazing, stupid, unexpected and useful.

    I hope it works for you all too.

    PS: Installed QuickTime is needed, I didn´t mention that.