Besoin de votre aide. Je fais une application simple (et je suis un nouveau à Unity3d également), qui prend la vidéo de la caméra IP et l'affiche sur Texture2D. Le format vidéo est MJPG. Pour les images jpg simples, le code ci-dessous fonctionne bien, mais quand j'essaie d'afficher MJPG, je reçois simplement un écran gris.Capturez et affichez une vidéo à partir d'une source de caméra IP (Unity3d + C#)
Ai-je commis une erreur de code?
public class testVid : MonoBehaviour {
//public string uri = "http://24.172.4.142/mjpg/video.mjpg"; //url for example
public Texture2D cam;
public void Start() {
cam = new Texture2D(1, 1, TextureFormat.RGB24, false);
StartCoroutine(Fetch());
}
public IEnumerator Fetch() {
while(true) {
Debug.Log("loading... " + Time.realtimeSinceStartup);
WWWForm form = new WWWForm();
WWW www = new WWW("http://24.172.4.142/mjpg/video.mjpg");
yield return www;
if(!string.IsNullOrEmpty(www.error))
throw new UnityException(www.error);
www.LoadImageIntoTexture(cam);
}
}
public void OnGUI() {
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), cam);
}
}