Mjpeg VLC and HTTP Streaming

user361526 picture user361526 · Apr 29, 2009 · Viewed 13.3k times · Source

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

Answer

Cindy picture Cindy · May 8, 2009

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