带有 MJPEG 和 multipart/x-mixed-replace 的 HttpWebResponse;边界=--来自安全摄像头的 myboundary 响应内容类型不起作用
我有一个 ASP.NET 应用程序,需要显示来自安全摄像头的视频源。视频源的内容类型为“multipart/x-mixed-replace”; border=--myboundary' 边界之间的图像数据。我需要帮助将该数据流传递到我的页面,以便我拥有的客户端插件可以使用该流,就像我直接浏览相机的网络界面一样。 以下代码不起作用:
//Get response data
byte[] data = HtmlParser.GetByteArrayFromStream(response.GetResponseStream());
if (data != null)
{
HttpContext.Current.Response.OutputStream.Write(data, 0, data.Length);
}
return;
I have an ASP.NET application that I need to show a video feed from a security camera. The video feed has a content type of 'multipart/x-mixed-replace; boundary=--myboundary' with the image data between the boundaries. I need assistance with passing that stream of data through to my page so that the client side plugin I have can consume the stream just as it would if I browsed to the camera's web interface directly.
The following code does not work:
//Get response data
byte[] data = HtmlParser.GetByteArrayFromStream(response.GetResponseStream());
if (data != null)
{
HttpContext.Current.Response.OutputStream.Write(data, 0, data.Length);
}
return;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,如果您希望客户端看到 mjpeg 流,您需要发送整个 http 响应。 HTTP 客户端(例如浏览器)或媒体播放器(例如 VLC)需要一个 mjpeg 流,如下所示:
注意:正如 Ergousha 在答案中所说,内容长度字段后面必须有一个空行。
顺便说一句,为什么不将您的客户端直接重定向到 mjpeg 流?
例如,您可以使用 http://ipcam/mjpg/video.mjpg AXIS IP 摄像机。
如果您只需要通过 HTTP 获取图像,则必须设置正确的标头和 MIME 内容类型
图像/jpeg。要解码图像,您必须获取字节数据,然后您将获得 jpeg 编码。然后你必须解码 jpeg 以获得特定格式的图像(我认为类似于 yuv420p)。我检查了我的网络摄像机,我认为它的流不是 Base64 编码的。
准确你的需求,我会尽力帮助更多。
my2c
编辑:
嗯,我想你会做类似的事情:
这就是说你必须将正确的标头发送给你的客户端。为了确保使用像wireshark这样的工具来监视数据包,并确保在您的客户端发出HTTP GET之后,您向他发送正确的MJPEG流(就像我在帖子开头描述的那样......)
m2c
Well, if you want your client to see the mjpeg stream, you need to send the whole http response. HTTP client like browser or media player like VLC need a mjpeg stream that looks like :
NOTE: As Ergousha said in an answer, you must have an empty line after the Content-length field.
By the way, why not redirect your client directly to the mjpeg stream ?
You can use http://ipcam/mjpg/video.mjpg AXIS IP cameras for example.
If you just need the image through HTTP, you have to set the correct header and the MIME content-type
image/jpeg. To decode the image, you have to get the byte data and you will get jpeg encoding. Then you will have to decode jpeg to get an image in a specific format (something like yuv420p I think). I've check on my ip camera, and its stream is not base64 encoded I think.
Precise your needs, I will try to help more.
my2c
EDIT:
Well, I suppose you do something like :
That to say that you must send the correct header to your client. To be sure use a tool like wireshark to spy on the packet and be sure that after your client has issued a HTTP GET you send to him the correct MJPEG stream (like the one I describe at the beginning of my post ...)
m2c
关于 mjpeg 流的外观的很好的解释。我想补充一点:
实际数据之前总是有 2 个换行符。如果你把它写成一行,它就不起作用。
Good explaination about how mjpeg stream looks like. I would like to add a tip that;
there are always 2 new line character before the actual data. If you make it one line, it doesnt work.
图像数据的编码是什么?是Base64吗?
基本上,您必须从响应中解析出图像数据,将其 Base64 解码为字节,然后将图像发送到客户端。
What is the encoding of the image data? Is it Base64?
Basically you will have to parse out the image data from the response, Base64 decode it into bytes, and then send the image to the client.