如何在C ++中解析MJPEG HTTP流? [英] How to parse MJPEG HTTP Stream within C++?

查看:877
本文介绍了如何在C ++中解析MJPEG HTTP流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要访问和读取从网络摄像机发送实时MJPEG镜头的http流,以便对图像进行一些opencv图像处理。



我可以通过VLC访问摄像机的镜头,或者只需转到chrome或firefox中的网址。但是当服务器只是发送一个连续的feed时,如何以编程方式访问http服务器和分离每一帧呢?​​



数据似乎格式简单, HTTP头和JPEG数据。我可以想到的接近这种方式的唯一方法是以某种方式向服务器发送请求,解析数据,当它进来,并分离头与实际的jpeg数据,并反过来,传递给opencv。



但是,这听起来非常复杂,我不知道我从哪里开始。



谢谢alot

你知道我的图书馆有没有图书馆,或者只是一个简单的方法,我可以忽略,

解决方案

对于HTTP下载,您可以使用 Libcurl 库。



AFAIK MJPEG格式不是标准格式。它的实际字节格式因实现而异。但基本上只是jpeg文件与分隔符的连接。例如,ffmpeg的mjpeg输出结构如下:





$ b b

  0xff 0xd8 // jpeg的开头
{...} // jpeg body
0xff 0xd9 // jpeg结尾
...
0xff 0xd8 // jpeg开始
{...} // jpeg body
0xff 0xd9 // jpeg结束
...


I need to access and read an http stream which is sending live MJPEG footage from a network camera, in order to do some opencv image processing on the image.

I can access the camera's footage through VLC, or simply by going to the URL in chrome or firefox. But how can I programmatically access the http server and separate each frame, when the server is just sending a continuous feed?

The data seems to be simply formatted, looping between the HTTP Header and JPEG data. The only way I can think of approaching this is somehow sending a request to the server, parsing the data as it comes in, and separating the header from the actual jpeg data, and, in turn, passing that to opencv.

However, that sounds awfully convoluted and I'm not quite sure where I'd start. Do you guys know if there are any libraries out there, or just a simpler approach I'm overlooking, that could make all this easier?

Thanks alot

解决方案

For HTTP download, you can use Libcurl library.

AFAIK MJPEG format is not a standardized format. Its actual byte format vary by implementations. But basically just concatenation of jpeg file with delimiters. If you look at bytes with a hex editor you could easily distinguish each jpeg file.

For example, ffmpeg's mjpeg output is structured like below:

0xff 0xd8 // start of jpeg
{ ... }   // jpeg body
0xff 0xd9 // end of jpeg
...
0xff 0xd8 // start of jpeg
{ ... }   // jpeg body
0xff 0xd9 // end of jpeg
...

这篇关于如何在C ++中解析MJPEG HTTP流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆