2013年11月15日 星期五

高速公路路況即時影像的作法

有點好奇高速公路路況即時影像的作法,因此捉了封包進行分析,結論如下:

1. 測試網址為
http://www.1968.com.tw/modules/CCTVeasy.aspx?cctv_id=nfbCCTV-N2-W-10.650-M

2. 即時影像的實作是透過 HTTP 協定,封包分析如後:
Client:
發出 HTTP Get
Server:
使用 Content-Type: multipart/x-mixed-replace; boundary=--multipartBoundary 回覆資料,並持續的傳送多個 MJPEG 給 Client, HTTP Header 摘錄如下:
HTTP/1.1 200 OK
Server: nginx/1.2.7
Date: Fri, 15 Nov 2013 08:14:13 GMT
Content-Type: multipart/x-mixed-replace; boundary=--multipartBoundary
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: no-cache
Pragma: no-cache
Expires: 0
Client:
收到這些資料後,按照 multipart/x-mixed-replace 定義的方式,
持續使用包含在 --multipartBoundary 內的 MJPEG 來更新畫面

3. 使用此方式播放, 大約 30 秒左右就會停止,
    可以自行起一個 timer, 每30秒或每分鐘重新 reload 此 URI

4. Client 端分別使用PC上的瀏覽器 chrome, safari, Internet Explorer 測試都可以正常運作。
     使用 iPad 上的 safari 也可以正常運作


摘錄 Wiki 上的 Mixed-Replace 說明如下
The content type multipart/x-mixed-replace was developed as part of a technology to emulate server push and streaming over HTTP. 
All parts of a mixed-replace message have the same semantic meaning. However, each part invalidates - "replaces" - the previous parts as soon as it is received completely. Clients should process the individual parts as soon as they arrive and should not wait for the whole message to finish. 
Originally developed by Netscape,[5] it is still supported by Mozilla, Firefox, Chrome,[6] Safari, and Opera, but traditionally ignored by Microsoft. It is commonly used in IP cameras as the MIME type for MJPEG streams.[7]