私はmjpegストリーミングの初心者です。FirefoxまたはGoogleChromeを実行しているクライアントにmjpegビデオをストリーミングするmjpegストリーミングサーバーアプリケーションを構築しようとしています。現時点では、ストリーミングはFirefoxで正常に機能しますが、GoogleChromeでの実行を拒否します。なぜこれが起こるのか誰かが知っていますか?(Windows用の最新バージョンのgoogle chromeとfirefoxをダウンロードしました)以下は、httpヘッダーと画像ストリーム(メモリストリーム)をネットワークストリームに書き込むC#クラスのコードスニペットです。
/* 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);
}
}
同じ問題があります(Chrome 29のバグ)。モーションjpegストリームをhtmlファイルに埋め込んだ場合、例:
<html><body>
<img src="http://192.168.1.77:8081">
</body></html>
Chrome29でストリームを表示できるようになりました。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加