[英]Capture and Show Video from IP camera source (Unity3d + c#)
Need your help. 需要你的帮助。 I am making simple application (and I'm a new to Unity3d also), which takes video from IP-camera and displays it onto Texture2D.
我正在做一个简单的应用程序(也是Unity3d的新手),它可以从IP摄像机获取视频并将其显示在Texture2D上。 Video format is MJPG.
视频格式为MJPG。 For simple jpg-images the code below works fine, but when I try to display MJPG I just get gray screen.
对于简单的jpg图片,下面的代码可以正常工作,但是当我尝试显示MJPG时,我只会得到灰屏。
Did I make a mistake in 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);
}
}
I used this plugin https://www.assetstore.unity3d.com/en/#!/content/15580 我使用了这个插件https://www.assetstore.unity3d.com/en/#!/content/15580
Hope it helps 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.