简体   繁体   中英

How to extract images from Motion Jpeg Stream of IP Camera?

I use GET nphMotionJpeg to get Motion Jpeg stream from IP Camera Panasonic. The response content is described in document bellow.

(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. 

The problem I encounter when trying to extract jpeg images data from above response content is it don't let I know the size of each image.

This is very difficult to process when don't have image size.

I have to try to write a algorithm to do it, but I so sophisticated. It may effect to system performance and maybe it exists more bugs.

Can you suggest me a simple way to do it?

Some [better] IP cameras provide Content-Length sub-header along with every JPEG video frame, however this header is not mandatory and this becomes a problem in your case: you don't have JPEG data length in advance.

There is nothing you can do but to keep reading into a buffer along with checking for receiving a new boundary line, at which you would cut off a video frame. You might also want to check for buffer overflow.

Also FYI some older Panasonic (such as BL-C140) and Axis (such as 213 PTZ) cameras format the multipart MIME response incorrectly, confusing the -- part of the boundary.

Use Gstreamer. See my full post linked by Martin Beckett above.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM