![](/img/trans.png)
[英]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.