- Home /
How to load .mp4 or .avi from local folder in unity 5?
How can I watch or reproduce .mp4 or .avi videos on unity 5 from a local address? On the following script I get the video in .ogg and .ogv format, but I need it in .mp4. How can I do??
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.IO;
public class PruebaAsignarVideo : MonoBehaviour {
string path = "C:/Users/Taku/Desktop/";
string url = "file:///C:/Users/Taku/Desktop/";
string fileName = "vide.mp4";
string[] files;
RawImage player;
AudioSource sound;
MovieTexture movie;
void Start () {
player = GetComponent<RawImage> ();
sound = GetComponent<AudioSource> ();
files = Directory.GetFiles (path);
StartCoroutine (loadMovie ());
}
IEnumerator loadMovie(){
WWW www = new WWW (url + fileName);
yield return www;
if (www.error != null) {
yield break;
} else {
MovieTexture video = www.movie as MovieTexture;
movie = video;
player.texture = movie;
sound.clip = movie.audioClip;
movie.Play ();
sound.Play ();
MovieTexture movieToPlay = www.movie;
MeshRenderer ren = this.GetComponent<MeshRenderer>();
ren.material.mainTexture = movieToPlay ;
movieToPlay.Play();
}
}
}
Answer by Paul-Jan · Mar 31, 2016 at 07:54 AM
You can't. Unity's MovieTexture only supports OGG Theora.
The Unity Editor supports converting .mp4 to .ogg using QuickTime, but the engine itself doesn't.
You might be able to find a plugin on the Asset Store that properly wraps ffmpeg (a famous library that supports MP4->OGV conversion), but the real question is: are you sure you need this at runtime, and can't simply convert the files beforehand?
Paul, im on a project (very old by the way), and it's running right now on vb.net, so i need to be able to load that resorces from local disk, because i got 500$$anonymous$$B in videos on that project. So this current project(new) im gonna deploy with OGG movies, but with the old ones i cant.
Takius, how did you sorted this out? I do have the same problem with an app that must be able to download about 1200 mp4 video on demand!! Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220612073903im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Cross Platform Video Streaming? 0 Answers
Windows standalone build fails to load VideoPlayer 0 Answers
Add a video to Unity 1 Answer
What is causing Unity to crash when importing a mp4? 0 Answers