谷歌浏览器无法播放Mjpeg视频流。

3

我是一个对mjpeg流媒体新手。我正在尝试构建一个mjpeg流媒体服务器应用程序,向运行firefox或google chrome的客户端流式传输mjpeg视频。目前,在firefox上流媒体工作正常,但在google chrome上却无法运行。有人知道这可能是为什么吗?(我已经下载了最新版本的Windows版google chrome和firefox)以下是来自我的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个回答

3

我有同样的问题(Chrome 29中的错误)。 我发现,如果您将运动JPEG流嵌入到HTML文件中,例如:

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

现在您可以在Chrome 29中查看流媒体。


谢谢!非常顺利。你知道有没有适用于Firefox的好解决方案吗?尽管Firefox只需输入URL(IP地址和端口号)即可流式传输mjpeg,但它并不高效地回收内存,并且在开始占用过多内存时被操作系统强制关闭。 - vsx06

0
我认为这是最新版Chrome的一个错误。 我能够在Chrome v28中很好地使用mjpg_streamer,但v29会停在空白屏幕上。 运行program files\google\chrome\application下有时会留下的oldchrome.exe,运动JPEG又开始工作了。 我向Google发送了一个错误通知,但不确定会走多远。

谢谢!我尝试使用v28,但不幸的是,v28对我没有用。我已经创建了一个小的HTML网页(如上所述),现在在v29中MJPEG流媒体工作得非常好。它在Opera上也完美运行。 - vsx06

-1

我在Chromium博客上发现,Chrome 29不支持x-mixed-replace:

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

真奇怪!


https://bugs.chromium.org/p/chromium/issues/detail?id=249132与图像无关... - Wolfgang Fahl

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接