Question

I am a newbie to mjpeg streaming. I am trying to build an mjpeg streaming server application that streams mjpeg video to clients running firefox or google chrome. At the moment, the streaming works fine on firefox, but refuses to run on google chrome. Does anyone know why this might be? (I have downloaded the latest versions of google chrome and firefox for windows) Following is the code snippet from my C# class that writes the http headers and image stream (memory stream) to the network stream:

 /* Write the HTTP header to the network stream */
        public void WriteHeader()
        {
            Write("HTTP/1.1 200 OK\r\n"                                 +
                  "Content-Type: multipart/x-mixed-replace; boundary="  +
                    this.Boundary                                       +
                    "\r\n"
                 );

            this.Stream.Flush();
        }

        /* To write text to the stream */
        private void Write(string text)
        {
            byte[] data = BytesOf(text);
            this.Stream.Write(data, 0, data.Length);
        }

        /* Write header followed by the provided memory stream*/
        public void Write(MemoryStream imageStream)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine();
            sb.AppendLine(this.Boundary);
            sb.AppendLine("Content-Type: image/jpeg");
            sb.AppendLine("Content-Length: " + imageStream.Length.ToString());
            sb.AppendLine();
            Write(sb.ToString());
            imageStream.WriteTo(this.Stream);
            Write("\r\n");
            this.Stream.Flush();
        }

        /* To get bytes from the from the specified string */
        private static byte[] BytesOf(string text)
        {
            return Encoding.ASCII.GetBytes(text);
        }   

And following is the code snippet that makes the appropriate method calls to write headers and image data to the network stream :

/* Sends data to the specified client */
    private void SendData(Socket client)
    {
            MjpegWriter jw = new MjpegWriter(new NetworkStream(client, true));
            jw.WriteHeader();
            foreach (var memstream in this.ProcessImages())
            {
                Thread.Sleep(50);
                jw.Write(memstream);
            }
    }
Was it helpful?

Solution

I have the same problem (bug in Chrome 29). I've found that if you embed your motion jpeg stream in an html file, example:

<html><body>
<img src="http://192.168.1.77:8081">
</body></html>

You can now view the stream in Chrome 29.

OTHER TIPS

I think it is a bug with the latest version of Chrome. I was able to use mjpg_streamer just fine with Chrome v28, but v29 stops with a blank screen. Running oldchrome.exe which is sometimes left under program files\google\chrome\application the motion jpeg began working again. I sent a bug notice to Goog, but unsure as to how far that will go.

I found that x-mixed-replace was not supported by Chrome 29 from Chromium Blog:

We’ve removed support for multipart/x-mixed-replace main resources. We will continue to support multipart images and animated images.

strange!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top