2012-02-10 123 views
1

我使用GET nphMotionJpeg从IP Camera Panasonic获取Motion Jpeg流。 响应内容在下面的文档中描述。如何从IP摄像机的Motion Jpeg Stream中提取图像?

(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

http://stackoverflow.com/questions/6022423/mjpeg-streaming-and-decoding – 2012-02-10 18:55:05

回答

0

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

除了在检查接收新的边界线以及切断视频帧的同时,还可以继续阅读缓冲区,因此没有什么可以做的。您可能还想检查缓冲区溢出。

也FYI一些老的松下(如BL - C140)和轴(如213 PTZ)摄像头格式化多部分MIME响应不正确,混淆--部分的边界。

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 
相关问题