[英]How to convert motion jpeg frames from ip camera(rtp stream) to valid jpg image
[英]How to extract images from Motion Jpeg Stream of IP Camera?
我使用GET nphMotionJpeg从IP摄像机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图像数据时遇到的问题是,它不让我知道每个图像的大小。
没有图像大小时,这很难处理。
我必须尝试编写一种算法来做到这一点,但是我是如此复杂。 它可能会影响系统性能,并且可能存在更多错误。
您能建议我一个简单的方法吗?
一些[更好]的IP摄像机在每个JPEG视频帧中都提供了Content-Length
子标题,但是此标题不是必需的,这在您的情况下会成为问题:您没有JPEG数据长度提前。
您别无选择,只能继续读入缓冲区,并检查是否有新的边界线,在该边界线处您将切断视频帧。 您可能还需要检查缓冲区溢出。
另外,仅供参考,一些较旧的Panasonic(例如BL-C140)和Axis(例如213 PTZ)相机会错误地格式化多部分MIME响应,从而混淆了边界的--
部分。
使用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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.