Mjpeg VLC and HTTP Streaming

醉酒当歌 提交于 2019-12-09 07:18:20

问题


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


回答1:


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




回答2:


Have you tried this:

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

Or some variation of those?




回答3:


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.



来源:https://stackoverflow.com/questions/801944/mjpeg-vlc-and-http-streaming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!