2013-09-01 78 views
1

我是mjpeg流媒體的新手。我正嘗試構建一個mjpeg流媒體服務器應用程序,將mjpeg視頻流傳輸到運行firefox或谷歌瀏覽器的客戶端。目前,流媒體在Firefox上運行良好,但拒絕在谷歌瀏覽器上運行。有誰知道這可能是爲什麼? (我已經下載了谷歌Chrome和Firefox的Windows的最新版本)以下是從我的C#類的代碼片斷寫入HTTP標頭和圖像流(內存流)到網絡流:Mjpeg流媒體不工作谷歌Chrome

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

回答

2

我有同樣的問題(Chrome 29中的錯誤)。我發現,如果你在一個HTML文件中嵌入您的Motion JPEG流,例如:

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

現在,您可以在Chrome 29

+0

謝謝!像魅力一樣工作。你知道一個好的Firefox解決方案嗎?儘管firefox通過簡單地輸入URL(IP地址和端口號)來傳輸mjpeg,但它並不能有效地回收內存,並且當操作系統開始佔用太多內存時,會被操作系統強行關閉。 – vsx06

0

我認爲這是與Chrome瀏覽器的最新版本的錯誤。我可以在Chrome v28上使用mjpg_streamer,但是v29以空白屏幕停止。運行有時留在程序文件\ google \ chrome \ application下的oldchrome.exe,運動jpeg再次開始工作。我向Goog發送了一個錯誤通知,但不確定這將會走多遠。

+0

謝謝!我嘗試使用v28,但不幸的是,v28沒有爲我工作。我已經創建了一個小的html網頁(如上所述),而mjpeg streaming現在在v29中出色地運行。它也可以在Opera上完美運行。 – vsx06

0

查看信息流,我發現X - 混合取代不Chrome 29支持Chromium博客:

我們已經移除了對multipart/x-mixed-replace主資源的支持。我們 將繼續支持多部分圖像和動畫圖像。

奇怪!