28

I have images being sent to my database from a remote video source at about 5 frames per second as JPEG images. I am trying to figure out how to get those images into a video format so I can stream a live video feed to Silverlight.

It seems to make sense to create a MJPEG stream but I'm having a few problems. Firstly I was trying to stream via an HTTP request so I didn't have a deal with sockets but maybe this is breaking my code.

If I try surf to my stream from QT I get a video error, Media player shows the first frame image and Silverlight crashes :)

Here is the code that streams - since I content type used this way can only be sent once I know that it isn't ideal and might be the root cause. All images are coming in via a LINQ2SQL object.

I did already try simply updating the image source of an image control in Silverlight but the flicker isn't acceptable. If Silverlight doesn't support MJPEG then no point even continuing but it looks like it does. I do have access to the h.264 frames coming in but that seemed more complicated via MP4.

    Response.Clear();
    Response.ContentType = "multipart/x-mixed-replace; boundary=--myboundary";
    ASCIIEncoding ae = new ASCIIEncoding();
    HCData data = new HCData();
    var videos = (from v in data.Videos
                 select v).Take(50); // sample the first 50 frames
    foreach (Video frame in videos)
    {
        byte[] boundary = ae.GetBytes("\r\n--myboundary\r\nContent-Type: image/jpeg\r\nContent-Length:" + frame.VideoData.ToArray().Length + "\r\n\r\n");
        var mem = new MemoryStream(boundary);
        mem.WriteTo(Response.OutputStream);
        mem = new MemoryStream(frame.VideoData.ToArray());
        mem.WriteTo(Response.OutputStream);
        Response.Flush();
        Thread.Sleep(200);
    }

Thanks!

EDIT: I have the stream working in firefox so if I surf to the page I see video! but nothing else accepts the format. Not IE, SL, Media player - nothing.

4

5 回答 5

2

我很久以前(3-4 年前)做过 MJPEG,我正在挠头试图记住细节,但我根本记不住。但是,如果可能的话,我建议找到某种网站,它可以流式传输 MJPEG 内容并启动wireshark/ethereal,然后看看你通过网络得到了什么。我的猜测是您缺少一些必需的 HTTP 标头,而 firefox 对此更宽容。

如果您在 Internet 上找不到示例 MJPEG 流,许多网络摄像头都有软件可以为您提供 MJPEG 流。我使用的应用程序是多个安全摄像头的控制台,所以我知道这是所有类型的摄像头的通用实现(如果它们支持 Web 界面)。

于 2008-11-05T21:59:32.803 回答
1

I'm far from being an expert in MJPEG streaming, but looking at the source of mjpg-streamer on sourcefourge I think you should send each frame separately, writing the boundary before and after each of them. You should of course not write the content-type in the closing boundary.

于 2008-11-05T10:22:51.870 回答
0

关于您的编辑:Firefox 和 Safari 支持 MJPEG。但是,其他应用程序不会,例如 Explorer 或 Silverlight,具体取决于您使用它执行的操作。

于 2008-12-17T19:48:57.993 回答
0

First, write your mjpeg frames out to separate files. You should then be able to open these in Phototshop (this will independently verify that you are parsing the stream correctly). If this fails, by bet is that you have HTTP headers embedded in your image data.

于 2008-10-19T17:11:18.663 回答
0

您是否查看过网络上存在的各种网络摄像头设置?他们中的许多人会进行某种低分辨率更新而不会闪烁。您应该能够对这些类型的站点进行逆向工程,以获得解决问题的更多线索。

一些网站创建了一个 GIF 动画,也许这是一个选项,以便用户可以看到过去一分钟左右。

于 2008-10-20T19:36:57.650 回答