Question by
VyacheslavDmit · Oct 10, 2018 at 12:08 PM ·
camerawebrequestip
Displays streaming video from an IP camera
Hello everyone. I'm trying to display a video stream from an IP camera in an application on Unity3D. I took as a basis various examples from manuals and forums. Here is the code:
public class MainCameraController : MonoBehaviour {
private Texture2D IpCameraTexture;
UnityWebRequest VideoRequest;
private string sourceURL = "http://192.168.100.107/axis-cgi/mjpg/video.cgi";
void Start() {
IpCameraTexture = new Texture2D (50, 50, TextureFormat.RGB24, false);
StartCoroutine(GetFrame());
}
public IEnumerator GetFrame() {
string authorization = "Basic " + System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes("admin:admin"));
VideoRequest = new UnityWebRequest (sourceURL, UnityWebRequest.kHttpVerbGET);
VideoRequest.SetRequestHeader("AUTHORIZATION", authorization);
VideoRequest.downloadHandler = new DownloadHandlerBuffer();
VideoRequest.Send();
while (true) {
yield return null;
if (! string.IsNullOrEmpty(VideoRequest.error))
throw new UnityException(VideoRequest.error);
if (VideoRequest.downloadHandler.data != null) {
IpCameraTexture.LoadRawTextureData(VideoRequest.downloadHandler.data);
IpCameraTexture.Apply();
}
}
}
public void OnGUI() {
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), IpCameraTexture);
}
public void Update() {
}
}
Displays blurry squares on the screen instead of video and displays the error "No texture data provided to LoadRawTextureData".
Tell me, please, what is wrong.
videoerror.png
(194.8 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612180108im_/https://answers.unity.com/themes/thub/images/avi.jpg)