开发者

How to parse MJPEG HTTP Stream within C++?

开发者 https://www.devze.com 2023-02-06 14:46 出处:网络
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 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 da开发者_开发技巧ta 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
...


In this page:

http://thistleshrub.net/www/index.php?controller=posts&action=show&id=2012-05-13DisplayingStreamedMJPEGinJava.txt

Parse a MJPEG Stream with Java, I implemented this with flawlessly results in Java.

If you try to use with C++ you find some things missed: socket conection and render canvas, libcurl seems to be a good option to http request, but still missing the canvas, you can use something like GLUT or Qt.

I read in some forums that OpenCV can read input stream of type MJPEG Streamer, but seems they need to be the recent version of OpenCV (compile OpenCV from scratch it's hard).

I hope this help.

0

精彩评论

暂无评论...
验证码 换一张
取 消