Здравствуйте. Пытаюсь отобразить видеопоток с IP-камеры в приложении на Unity3D. Брал за основу различные примеры из мануалов и форумов. Такой код:
| Код | private Texture2D IpCameraTexture; private string sourceURL = "http://login:[email protected]/axis-cgi/mjpg/video.cgi";
public void Start() { IpCameraTexture = new Texture2D (1, 1, TextureFormat.RGB24, true); StartCoroutine(GetFrame()); }
public void OnGUI() { GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), IpCameraTexture); }
public IEnumerator GetFrame() { while (true) { WWW www = new WWW (sourceURL); while (!www.isDone) yield return null; if (!string.IsNullOrEmpty(www.error)) yield break; www.LoadImageIntoTexture(IpCameraTexture); } }
public void Update() { }
|
И такой
| Код | private string sourceURL = "http://192.168.100.108/axis-cgi/mjpg/video.cgi";
public IEnumerator GetFrame() { string authorization = "Basic " + System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes("login:password")); VideoRequest = UnityWebRequest.Get(sourceURL); VideoRequest.SetRequestHeader ("AUTHORIZATION", authorization); while (true) { yield return VideoRequest.Send (); if (!string.IsNullOrEmpty (VideoRequest.error)) throw new UnityException (VideoRequest.error); else if (VideoRequest.downloadHandler.data != null) { IpCameraTexture.LoadRawTextureData (VideoRequest.downloadHandler.data); IpCameraTexture.Apply (); } } }
|
Не работают. Программа не доходит до LoadRawTextureData
Пробовал использовать компонент VideoPlayer
| Код | public RawImage image; private VideoPlayer videoPlayer; private VideoSource videoSource; private AudioSource audioSource;
private string sourceURL = "http://login:[email protected]/axis-cgi/mjpg/video.cgi";
void Start () { Application.runInBackground = true; StartCoroutine (playVideo ()); }
IEnumerator playVideo () { videoPlayer = gameObject.AddComponent<VideoPlayer> (); audioSource = gameObject.AddComponent<AudioSource> (); videoPlayer.playOnAwake = false; audioSource.playOnAwake = false; audioSource.Pause (); videoPlayer.source = VideoSource.Url; videoPlayer.url = sourceURL; videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource; videoPlayer.EnableAudioTrack (0, true); videoPlayer.SetTargetAudioSource (0, audioSource); videoPlayer.Prepare (); WaitForSeconds waitTime = new WaitForSeconds (1); while (!videoPlayer.isPrepared) { yield return waitTime; break; } image.texture = videoPlayer.texture; videoPlayer.Play (); audioSource.Play (); while (videoPlayer.isPlaying) yield return null; }
|
Выдает ошибку: WindowsVideoMedia error 0x80070005 while reading http://...
Подскажите, пожалуйста, как правильно решить эту задачу.
|