C# Mjpeg VLC 和 HTTP 流

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/801944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 01:45:49  来源:igfitidea点击:

Mjpeg VLC and HTTP Streaming

c#httpstreamingvlcmjpeg

提问by user361526

I'm generating a MJpeg Stream and trying to stream it to VLC and play it there.

我正在生成一个 MJpeg 流并尝试将其流式传输到 VLC 并在那里播放。

The code:

编码:

        public void SendMultiPartData(String contentType, Func<byte[]> getData)
    {
        MemoryStream mem = null;
        response.StatusCode = 200;
        for ( byte[] buffer = getData(); buffer != null && buffer.Length > 0; buffer = getData())
        {
            response.ContentType = "multipart/x-mixed-replace; boundary=--testboundary";
            ASCIIEncoding ae = new ASCIIEncoding();
            byte[] boundary = ae.GetBytes("\r\n--testboundary\r\nContent-Type: " + contentType + "\r\nContent-Length:" + buffer.Length + "\r\n\r\n");
            mem = new MemoryStream(boundary);
            mem.WriteTo(response.OutputStream);
            mem = new MemoryStream(buffer);
            mem.WriteTo(response.OutputStream);
            response.OutputStream.Flush();
        }
        mem.Close();
        listener.Close();
    }

If I try to open the stream with firefox, there's no problem at all, although with VLC it doesn't work (VLC seems to keep reading but never shows the video)

如果我尝试使用 Firefox 打开流,则完全没有问题,尽管使用 VLC 它不起作用(VLC 似乎继续阅读但从未显示视频)

I've been sniffing VLC-to-VLC streaming and they seems to use as HTTP header "application/octet-stream" instead of multipart/x-mixed-replace

我一直在嗅探 VLC 到 VLC 的流媒体,它们似乎用作 HTTP 标头“application/octet-stream”而不是 multipart/x-mixed-replace

Any ideas ?

有任何想法吗 ?

Tks in advance, Jose

提前确认,何塞

采纳答案by Jason Williams

Jose, I had exactly same problem. Firefox plays my stream but VLC doesnt. I went thru so many ways to figure this out including debugging VLC source code, and got no where. btw My (REST) URL looks like http://server:port/livevideo/xyzThen, I thought I should try http://server:port/livevideo/xyz.mjpegAnd guess what, VLC started to play video! I think VLC might need a little hint more than content type to figure out it is a mjpeg stream. Hope this helps.

何塞,我遇到了完全相同的问题。Firefox 会播放我的流,但 VLC 不会。我尝试了很多方法来解决这个问题,包括调试 VLC 源代码,但一无所获。顺便说一句,我的 (REST) URL 看起来像http://server:port/livevideo/xyz然后,我想我应该尝试http://server:port/livevideo/xyz.mjpeg猜猜看,VLC 开始播放视频了!我认为 VLC 可能需要比内容类型更多的提示才能确定它是一个 mjpeg 流。希望这可以帮助。

Cindy

辛迪

回答by Jason Williams

Have you tried this:

你有没有试过这个:

Response.Buffer = false;
Response.BufferOutput = false;

Or some variation of those?

或者它们的一些变体?

回答by Dolphin

I can't get firefox to play my stream (though chrome plays it okay). For VLC I set the buffer to 0 ms (under advanced open options) and it seemed to work from there, though my data rate is killing it.

我无法让 Firefox 播放我的流(尽管 chrome 播放正常)。对于 VLC,我将缓冲区设置为 0 毫秒(在高级打开选项下),它似乎从那里开始工作,尽管我的数据速率正在扼杀它。