Hi,
I’m trying to get the actual resolution (in pixels) of a video I’m loading (MovieTexture).
However, when I’m reading the MovieTexture.width and MovieTexture.height, I’m always getting 16 (both width and height). Weird…
Any suggestions?
Thanks.
Hi,
I’m trying to get the actual resolution (in pixels) of a video I’m loading (MovieTexture).
However, when I’m reading the MovieTexture.width and MovieTexture.height, I’m always getting 16 (both width and height). Weird…
Any suggestions?
Thanks.
worked for me without a problem on my movies.
sure you wait until the movie is at least ready to be played with checking its size?
yes, I am… Thanks for the answer though…
Did you convert the movie in unity or export it as ogg theora?
I’m using ogg theora movies I import, as well as ogg theora movies that I stream from web
I would highly recommend the later for quality reasons. Miro Converter is free and available on win and osx and generates much better looking videos at the same or smaller size.
I’m using a sample ogg file provided by Unity and I’m streaming it from web. The url is http://www.unity3d.com/webplayers/Movie/sample.ogg
I’m not having any problems with playing the video. Everything’s fine. I can assign it as a texture or play its sound. The only problem is getting its resolution, which is definitely not 16 x 16.
All the same for me, aside of the fact that I get the right movie sizes.
Do you try to get the size before calling play or after?
The code I’m using is below, the 3 variables it expects have self explaining types (ie MovieTexture, GUITexture and AudioClip :))
/// <summary>
/// Functionality to play back a movie
/// </summary>
/// <param name="movie">The movietexture we want to play back</param>
public bool PlayMovie(MovieTexture movie, bool upscale)
{
if (movie != null)
{
if (movieCamera == null)
{
if (Camera.main != null)
movieCamera = Camera.main;
if (movieCamera == null)
return false;
}
if (moviePlane == null)
{
moviePlane = new GameObject().transform;
moviePlane.position = new Vector3(0.5f, 0.5f, 1);
moviePlane.localScale = Vector3.zero;
moviePlane.name = "Movie Plane";
if (movieGUITexture == null) movieGUITexture = moviePlane.gameObject.AddComponent<GUITexture>();
if (movieAudio == null)
{
movieAudio = moviePlane.gameObject.AddComponent<AudioSource>();
movieAudio.rolloffMode = AudioRolloffMode.Linear;
movieAudio.minDistance = 2000;
movieAudio.playOnAwake = false;
}
if (!upscale)
{
Transform backdropGO = new GameObject().transform;
backdropGO.parent = moviePlane;
Texture2D black = new Texture2D(2, 2);
black.SetPixels(new Color[4] { new Color(0, 0, 0, 0.5f), new Color(0, 0, 0, 0.5f), new Color(0, 0, 0, 0.5f), new Color(0, 0, 0, 0.5f) });
black.Apply();
GUITexture backdrop = backdropGO.gameObject.AddComponent<GUITexture>();
Rect inset = new Rect(-Screen.width / 2, -Screen.height / 2, Screen.width, Screen.height);
backdrop.pixelInset = inset;
backdropGO.localPosition = new Vector3(0.5f, 0.5f, 0);
backdropGO.name = "Movie Backdrop";
backdropGO.localScale = Vector3.one;
backdrop.texture = black;
}
}
else if( !moviePlane.gameObject.active )
{
moviePlane.gameObject.SetActiveRecursively(true);
}
if (!upscale)
{
// native movie resolution, centered on screen, with semi black surounding
movieGUITexture.pixelInset = new Rect(-movie.width / 2, -movie.height / 2, movie.width, movie.height);
moviePlane.localScale = new Vector3(movie.width / Screen.width, movie.height / Screen.height, 1);
}
else
{
// this would be fullscreen
movieGUITexture.pixelInset = new Rect(-Screen.width / 2, -Screen.height / 2, Screen.width, Screen.height);
}
StartCoroutine(DoPlayMovie(movie));
movie.Play();
return true;
}
return false;
}
/// <summary>
/// Internal function used to wait until the movie is prepared prior assigning it
/// </summary>
/// <param name="movie">movie it is meant to wait to assign</param>
IEnumerator DoPlayMovie(MovieTexture movie)
{
while (!movie.isPlaying)
yield return null;
movieCurrent = movie;
movieGUITexture.texture = movieCurrent;
movieAudio.clip = movie.audioClip;
if (movieAudio.clip != null) movieAudio.Play();
}
Hah, that was the problem. I was reading the width and height vars before calling Play().
Now I tried doing it after Play() is called and it works perfectly fine.
This is quite strange though. Width and height are usually stored in video’s metadata so there shouldn’t be a need to play it first in order to get the info. Also, we might want to create let’s say a scrollable list of available videos with their resolutions shown on the screen. To do this, we would have to call Play() for each video first. Really annoying.
If there’s nothing I’m oblivious to, I would suggest it as another wish in Unity’s wish list.
Thank you for your help!
I’m getting width and height too before playing it, so its double strange. I would guess the movie UT provides is jsut buggy with incorrect metas or something cause my Miro Conversions work without any problem (as you can see in my code)
Anyway, it’s great you helped me solve it. Even if it requires to play the movie first. I’ll try with some other file later.
Thanks again.