首页 文章

Mjpeg流不支持谷歌浏览器

提问于
浏览
1

我是mjpeg流媒体的新手 . 我正在尝试构建一个mjpeg流媒体服务器应用程序,将mjpeg视频流式传输到运行firefox或google chrome的客户端 . 目前,流媒体在Firefox上工作正常,但拒绝在谷歌浏览器上运行 . 有谁知道为什么会这样? (我已经下载了最新版本的google chrome和firefox for windows)以下是我的C#类的代码片段,它将http标头和图像流(内存流)写入网络流:

/* 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);
        }

以下是代码片段,它使相应的方法调用将头和图像数据写入网络流:

/* 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);
            }
    }

3 回答

  • 0

    我有同样的问题(Chrome 29中的错误) . 我发现如果你将动作jpeg流嵌入到html文件中,例如:

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

    您现在可以在Chrome 29中查看流 .

  • 2

    我认为这是最新版Chrome的错误 . 我能够在Chrome v28上使用mjpg_streamer,但v29在空白屏幕时停止 . 运行oldchrome.exe,有时会留在程序文件\ google \ chrome \ application下,运动jpeg再次开始工作 . 我向Goog发送了一个错误通知,但不确定会走多远 .

  • 0

    我发现Chromium Blog的Chrome 29不支持x-mixed-replace:

    我们已经删除了对multipart / x-mixed-replace主要资源的支持 . 我们将继续支持多部分图像和动画图像 .

    奇怪!

相关问题