- Home /
MovieTexture - Black Video with Audio
Hey guys,
I ran into an issue today where i was trying to play back a MovieTexture with audio. The video wouldn't play back showing only a black screen but the audio would play back. The video would play back in VLC fine and Windows Media Player.
My quick fix was to create the videos and audio files separately and everything works fine. Although, i was curious as to why it wouldn't work?
EDIT: I just realized it may be how Unity converts the file. The file size is 2.8kb when I import it with audio instead of 5mb without audio.
The video file was .mp4 and the quality settings in Unity were default.
Here is my script i was using:
using UnityEngine;
using System.Collections;
public class AutoPlayVideo : MonoBehaviour
{
public MovieTexture objectVideo;
public bool videoHasAudio = false;
public AudioClip audioClip;
AudioSource audiodata;
void Awake()
{
transform.renderer.material.mainTexture = objectVideo;
objectVideo.loop = true;
if(videoHasAudio)
{
audiodata = GetComponent<AudioSource>();
audiodata.clip = audioClip;
audiodata.playOnAwake = false;
audiodata.loop = true;
}
}
void OnEnable()
{
objectVideo.Play ();
if(videoHasAudio)audiodata.Play ();
}
void Update()
{
//Debug.Log (""+objectVideo.isPlaying);
}
void OnDisable()
{
objectVideo.Stop ();
if(videoHasAudio)audiodata.Stop();
}
}
"It breaks with big files and gives you inconsistent results."
http://answers.unity3d.com/questions/17409/best-video-preparation-for-unity.html
I have a feeling it has to do with the compression rate of the video and audio.
I have this same issue trying to stream .ogvs. The bug only occurs on $$anonymous$$acs: the first time you play the video, it works fine. Then if you refresh the browser and play the movie again it is black with audio. If you quit the browser and come back, the video works again. Happens with perfect consistency; always on a $$anonymous$$ac (any generation, any browser), always after refresh, always goes away after quitting.
I exported my .ogvs with ffmpeg using the following command:
ffmpeg -i C:$$anonymous$$y$$anonymous$$ovie.mov -r 30 -acodec libvorbis -ac 2 -vcodec libtheora -b:v 2000k -s 1280x720 $$anonymous$$y$$anonymous$$ovie.ogv
I tried turning off the audio and it had no effect.