INTRODUCTION
Here we will decode an Ogg Theora file streaming from the internet onto a plane surface scripted in Unity 3d.
DISCUSSION
The fastest method to do this as of writing is to look here and then attach this to the camera in a new unity 3d scene.
FINDINGS
The Unity docs do not seem to show a C# source example, so in full Blue Peter (UK) style: Here is one I made earlier.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
//============================================================================ // Name : WWWVideoTexture (Unity 3d) // Author : Divide To Infinity // Version : V1.0 // Copyright : GNU GPL v2 // Description : C# Monobehaviour Script for Decoding Video Streams to Texture //============================================================================ using UnityEngine; using System.Collections; [RequireComponent(typeof(GUITexture))] [RequireComponent(typeof(AudioSource))] public class WWWVideoTexture : MonoBehaviour { public string url = "http://playground.html5rocks.com/samples/html5_misc/chrome_japan.ogv"; IEnumerator Start() { WWW www = new WWW(url); MovieTexture movieTexture = www.movie; while (!movieTexture.isReadyToPlay) { yield return null; } GUITexture gt = GetComponent(); gt.texture = movieTexture; transform.localScale = new Vector3(0, 0, 0); transform.position = new Vector3(0.1f, 0.25f, 0); gt.pixelInset = new Rect(0, 0, movieTexture.width / 2, movieTexture.height / 2); AudioSource aud = GetComponent(); aud.clip = movieTexture.audioClip; movieTexture.Play(); aud.Play(); } } |
And the screenshot:
LINKS
WWW.movie in Unity 3d Scripting API
Video Streaming solutions for Unity3d on Stack Overflow
C# pixelInset problem on UnityAnswers
Streaming Textures in Unity3d
Video Playback Speed Discussion on Unity 3d Forums