How to show video of an IP camera
Hello there! I've spent last week tryin to show my ip camera's video in my unity 3d application , and i did , but the video displayed is TOOO slow ( around 2-3 fps ).
This is my actual code :
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class CameraManager : MonoBehaviour {
public string url;
public string username;
public string password;
public RawImage img1;
public RawImage img2;
public Text consolle;
public InputField ip;
public Texture2D cam;
public void Start() {
UnityEngine.Time.timeScale = 1;
cam=new Texture2D(1, 1, TextureFormat.RGB24, true);
}
public void StartFetching(){
if (ip.text != "") {
url = "http://" + ip.text + "/snapshot.cgi";
StartCoroutine (Fetch ());
} else {
consolle.text += "\r\n 'Ip' field cannot be empty";
}
}
public void StopFetching(){
StopAllCoroutines ();
}
public IEnumerator Fetch() {
while(true) {
WWW www = new WWW(url, null, new System.Collections.Generic.Dictionary<string,string>() {
{"Authorization", "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(username+":"+password))}
});
yield return www;
Debug.Log ("doing");
if(!string.IsNullOrEmpty(www.error))
consolle.text += "\r\nConnection with ip cam failed! : "+www.error;
try{
www.LoadImageIntoTexture(cam);
}catch(UnityException e){
consolle.text += e;
}
img1.texture = cam;
img2.texture = cam;
}
}
}
Now i want to know if exists some other method to make the video more faster and less choppy, the problem it's not the connection as i know that the video in my android application ( "FRCAM" , my ip-cam is an FREDI HD L17 ) is displayed at 20 fps ( which is good for what i'm using ) , the URL i could use for get the video is :
http://xxx.xxx.x.xxx/video/livesp.asp
Any ideas ? I'm really frustrated.
Comment