Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by unity_oEVKDotJO50MrQ · Mar 29, 2019 at 05:19 PM · videostreamingvideo streaming

C# - Stream from IP camera over 3D Plane object

Hello i made a program with Unity3D that "project" the image of an ip camera over a 3D object, a plane..

The script is working well with streams i got from the internet but i have problems with my Panasonic WV-SW458.

Do not know why because i get the right stream on the internet and in the VLC with both the internet camera and my Panasonic.

I'll attach my code , maybe i'm missing something that, at the moment, i cannot see...

 using UnityEngine;
  using UnityEngine.UI;
  using System.Collections;
  using System;
  using System.Net;
  using System.IO;
 
  public class WebStream : MonoBehaviour {
 
      [HideInInspector]
      public Byte [] JpegData;
      [HideInInspector]
      public string resolution = "480x360";
 
      private Texture2D texture; 
      private Stream stream;
      private WebResponse resp;
      public MeshRenderer frame;
 
      public void Start() {
        GetVideo();
      }
 
      public void StopStream(){
          stream.Close ();
          resp.Close ();
      }
 
      public void GetVideo(){
          texture = new Texture2D(2, 2); 
 
          //Working
          //string url = "http://24.172.4.142/mjpg/video.mjpg?COUNTER";
          //Working
          string url = "http://200.36.58.250/mjpg/video.mjpg?resolution=640x480";
          //NotWorking
          //rtsp://192.168.140.120/MediaInput/h264
          //NotWorking
          //string url = "http://192.168.140.120/cgi-bin/mjpeg";
 
          HttpWebRequest req = (HttpWebRequest) WebRequest.Create(url);
          //For testing
         // req.ProtocolVersion = HttpVersion.Version10;
 
          // get response
          resp = req.GetResponse();
          // get response stream
          stream = resp.GetResponseStream();
          frame.material.color = Color.white;
          StartCoroutine (GetFrame ());
      }
 
      public IEnumerator GetFrame (){
         // Byte [] JpegData = new Byte[105536];
        //   Byte [] JpegData = new Byte[205536];
          Byte [] JpegData = new Byte[505536];
          while(true) {
              int bytesToRead = FindLength(stream);
              if (bytesToRead == -1) {
                  yield break;
              }
 
              int leftToRead=bytesToRead;
 
              while (leftToRead > 0) {
                 Debug.Log("Left To Read" + leftToRead);
                  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;
              frame.material.color = Color.white;
              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;
      }
  }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

104 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Could a privacy error on a video streaming server cause videos not to play in an Android build? 1 Answer

Video Streaming for Web Player 1 Answer

Splash videos on android and iOS? 0 Answers

How to play videos in WebGL? 1 Answer

Video Player WebGl Transparency problem - previous frames doesn't clear 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges