如何从IP Camera的Motion Jpeg Stream中提取图像?

时间:2012-02-10 18:28:31

标签: c++ ip-camera

我使用GET nphMotionJpeg从IP Camera Panasonic获取Motion Jpeg流。 响应内容在下面的文档中描述。

(2) Data reception 
    "HTTP/1.0 200 OK\r\n" 
    "Content-Type: multipart/x-mixed-re place; bound ary=--myboundary..." 
    "...--myboundary.Content-type: image/jpeg..." 
    JPEG binary data No. 1 (Hexadecimal notation="FFD8...... ........................ ..FFD9") 
    "...--myboundary.Content-type: image/jpeg..." 
    JPEG binary data No. 2 (Hexadecimal notation="FFD8...... ........................ ..FFD9") 
    : 
    : 
    "...--myboundary.Content-type: image/jpeg..." 
    JPEG binary data No. N (Hexadecimal notation="FFD8...... ........................ ..FFD9") 

    * Above mentioned  Content-type: From FFD8(following image/jpeg) to "--my boundary" (just before FFD9) 
    is 1 JPEG data file. 

    (3) Image displaying/saving 
    From the data above, extract JPEG  data, and display the extracted consecutively or save it. 
    A viewer that supports the above data is required to view images. 

尝试从上面的响应内容中提取jpeg图像数据时遇到的问题是它不让我知道每个图像的大小。

当没有图像尺寸时,这很难处理。

我必须尝试编写一个算法来做到这一点,但我非常复杂。它可能会影响系统性能,也许存在更多错误。

你能建议我一个简单的方法吗?

2 个答案:

答案 0 :(得分:0)

一些[更好] IP摄像机提供Content-Length子标题以及每个JPEG视频帧,但是此标题不是强制性的,这在您的情况下会成为一个问题:您没有提前提供JPEG数据长度。

除了继续读取缓冲区以及检查接收新的边界线之外,您无法做任何事情,您可以在此处切断视频帧。您可能还想检查缓冲区溢出。

另外,一些较旧的松下(例如BL-C140)和Axis(例如213 PTZ)相机错误地格式化多部分MIME响应,使边界的--部分混淆。

答案 1 :(得分:0)

使用Gstreamer。请参阅Martin Beckett上面链接的完整帖子。

gst-launch souphttpsrc location="http://[ip]:[port]/[dir]/xxx.cgi" do-timestamp=true is_live=true ! multipartdemux ! jpegdec !  videoflip method=vertical-flip ! jpegenc !  multifilesink location=image-out-%05d.jpg
相关问题