Mjpeg VLC 和 HTTP 流媒体

发布于 2024-07-17 12:31:02 字数 1150 浏览 12 评论 0原文

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

代码:

        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();
    }

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

我一直在嗅探 VLC 到 VLC 流他们似乎使用 HTTP 标头“application/octet-stream”而不是 multipart/x-mixed-replace

有什么想法吗?

提前谢谢, 何塞

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

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)

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

Any ideas ?

Tks in advance,
Jose

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

万劫不复 2024-07-24 12:31:02

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

辛迪

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/xyz
Then, I thought I should try http://server:port/livevideo/xyz.mjpeg
And 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.

Cindy

忆悲凉 2024-07-24 12:31:02

您是否尝试过这个:

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

或者这些的一些变体?

Have you tried this:

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

Or some variation of those?

紫轩蝶泪 2024-07-24 12:31:02

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文