• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Takius · Mar 31, 2016 at 07:47 AM · videofoldermp4

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();
         }
     }    
     
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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?

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Takius · Apr 01, 2016 at 06:38 AM 0
Share

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.

avatar image Jayme65 Takius · Jan 07, 2017 at 03:12 PM 0
Share

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!

avatar image Takius Jayme65 · Jan 08, 2017 at 12:39 PM 1
Share

I had to convert all the videos to .ogg

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

What is causing Unity to crash when importing a mp4? 0 Answers

I want to convert a video(mp4) onto a mesh(panorama)(jpg pic) which moves according to gyro in Unity 3D. like amazon 360 product view or fyuse on android 0 Answers

MP4 converted from M4V crashes Unity 4 Answers

Reducing file size for mp4 to reduce build size? 1 Answer

Video: Not ready to play yet 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges