playing MP4 video in unity pro

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:

using UnityEngine;
using System.Collections;

public class PlayMovie : MonoBehaviour 
{
    private MovieTexture mtex;

    // Use this for initialization
	void Start () 
    {
        mtex = gameObject.renderer.material.mainTexture as MovieTexture;
        mtex.Play();
	}
	
	// Update is called once per frame
	void Update () 
    {
        if (!mtex.isPlaying)
        {
            print("movie playing status: " + mtex.isPlaying + ".");
            mtex.Play();
        }
	}
}

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!

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?

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. :slight_smile:

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,

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?

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.

@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 :slight_smile:

Thanks guys.
Tim

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 >.>

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.

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?

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.