Unity3d 将实时摄影机提要导入unity

Unity3d 将实时摄影机提要导入unity,unity3d,raspberry-pi,video-streaming,streaming,Unity3d,Raspberry Pi,Video Streaming,Streaming,我有一个问题,我无法通过互联网解决。我有一个raspberry摄像头,可以在web ip上进行流式处理,流式处理的脚本是python脚本,在我的例子中,我想将流导入unity应用程序。以前有人这样做过吗?应该怎么做?比如,当我在unity中按play时,我希望能够看到相机在应用程序的gamaobject中记录的图像!谢谢你抽出时间 using UnityEngine; using System.Collections; using System; using System.Net; using

我有一个问题,我无法通过互联网解决。我有一个raspberry摄像头,可以在web ip上进行流式处理,流式处理的脚本是python脚本,在我的例子中,我想将流导入unity应用程序。以前有人这样做过吗?应该怎么做?比如,当我在unity中按play时,我希望能够看到相机在应用程序的gamaobject中记录的图像!谢谢你抽出时间

using UnityEngine;
using System.Collections;
using System;
using System.Net;
using System.IO;

public class WebStreams : MonoBehaviour
{

    public MeshRenderer frame;    //Mesh for displaying video

    private string sourceURL = "http://192.168.0.94:8000/index.html";
    private Texture2D texture;
    private Stream stream;

    public void GetVideo()
    {
        texture = new Texture2D(2, 2);
        // create HTTP request
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourceURL);
        //Optional (if authorization is Digest)
        ///req.Credentials = new NetworkCredential("username", "password");
        // get response
        WebResponse resp = req.GetResponse();
        // get response stream
        stream = resp.GetResponseStream();
        StartCoroutine(GetFrame());
    }

    IEnumerator GetFrame()
    {
        Byte[] JpegData = new Byte[65536];

        while (true)
        {
            int bytesToRead = FindLength(stream);
            print(bytesToRead);
            if (bytesToRead == -1)
            {
                print("End of stream");
                yield break;
            }

            int leftToRead = bytesToRead;

            while (leftToRead > 0)
            {
                leftToRead -= stream.Read(JpegData, bytesToRead - leftToRead, leftToRead);
                yield return null;
            }

            MemoryStream ms = new MemoryStream(JpegData, 0, bytesToRead, false, true);

            texture.LoadImage(ms.GetBuffer());
            frame.material.mainTexture = texture;
            stream.ReadByte(); // CR after bytes
            stream.ReadByte(); // LF after bytes
        }
    }

    int FindLength(Stream stream)
    {
        int b;
        string line = "";
        int result = -1;
        bool atEOL = false;

        while ((b = stream.ReadByte()) != -1)
        {
            if (b == 10) continue; // ignore LF char
            if (b == 13)
            { // CR
                if (atEOL)
                {  // two blank lines means end of header
                    stream.ReadByte(); // eat last LF
                    return result;
                }
                if (line.StartsWith("Content-Length:"))
                {
                    result = Convert.ToInt32(line.Substring("Content-Length:".Length).Trim());
                }
                else
                {
                    line = "";
                }
                atEOL = true;
            }
            else
            {
                atEOL = false;
                line += (char)b;
            }
        }
        return -1;
    }
}

目前还不清楚您使用什么软件进行流媒体传输。我建议在你的问题中加入这些额外的信息(即编辑你的帖子)。我建议您找出您使用的流媒体标准,然后搜索标准的组合(可能是rtsp)+unity3dwell 192.168.x.x无法在internet上路由,因此您无法使用您需要的地址从本地网络将其发送到internet并使用internetIP@BugFinder我知道,我现在在我的本地网络上。这是我找到的一段代码,我尝试将其插入主摄像头并作为一个立方体帧,但不幸的是,什么也没有发生。可能索引返回的是html而不是视频流…您可以尝试使用Image.FromStream命令吗?目前还不清楚您使用什么软件进行流式处理。我建议在你的问题中加入这些额外的信息(即编辑你的帖子)。我建议您找出您使用的流媒体标准,然后搜索标准的组合(可能是rtsp)+unity3dwell 192.168.x.x无法在internet上路由,因此您无法使用您需要的地址从本地网络将其发送到internet并使用internetIP@BugFinder我知道,我现在在我的本地网络上。这是我找到的一段代码,我尝试将其插入主摄像头并作为立方体帧,但没有发生任何不幸的事情。可能索引返回的是html而不是视频流…您可以尝试使用Image.FromStream命令吗?