MJPEG over HTTP

multipart/x-mixed-replace (MIME型)

[29] multipart/x-mixed-replace は、 HTTP応答によりサーバーが任意のタイミングで複数の文書を返し、 紙芝居的にレンダリングを切り替えさせるものです。

[30] 90年代に Netscape 社により server push の手法として実装されました。 現在でも MJPEG の実現手法として用いられています。

仕様書

構文

[34] multipart/mixed と同じとされています。

処理

[36] 基本的には multipart/mixed と同じように処理します。

[35] サーバーは適当なタイミングで順次新しい本体部分を送出していきますから、 クライアントmultipart実体全体の到着を待たずに受信した本体部分からレンダリングしていく必要があります。

MJPEG over HTTP

[27] JPEGmultipart/x-mixed-replace により HTTP で返し、動画としてレンダリングさせるものを MJPEG over HTTP と呼ぶことがあります。単に MJPEGMotion JPEG と呼ぶこともあるようです。

MJPEG も参照。

[33] いわゆるWebカメラWebブラウザー向けUIの実装などに使われています。

[37] 現在画像としての multipart/x-mixed-replace の処理方法を明確に規定した仕様書は存在していません。

navigate における multipart/x-mixed-replace

[31] 元々の server pushMJPEG のような画像としての埋め込みだけでなく、 ページ全体にも適用されるものでした。すなわち multipart/x-mixed-replace への navigate も実装されていました。

[32] 現在では JavaScript によりページの一部分を書き換えることができるため、 ページ全体を送りなおす必要がある本手法は使われなくなっています。 それに伴い Webブラウザーからも navigate における multipart/x-mixed-replace 対応は削除されつつあります。

HTML Standard にはまだ multipart/x-mixed-replace への navigate の規定が残っています。

 Content-type: multipart/x-mixed-replace;boundary=ThisRandomString
 
 --ThisRandomString
 Content-type: text/plain
 
 Data for the first object.
 
 --ThisRandomString
 Content-type: text/plain
 
 Data for the second and last object.
 
 --ThisRandomString--

関連

[48] データを直接送信する代わりに URL にしたものが HLS といえなくもありません。 HLSdata: URL を使えば実質同じことができます (実装が対応しているのかどうかは謎)。

歴史

[8] Netscape 社の定義した、「Server Push」の一手法であり、 <http://www.netscape.com/assist/net_sites/pushpull.html> に説明があります。

Web browser は、新しい Multipart の part が送られてきたら、 閲覧中の part の代わりに新しい part を閲覧させます。

サーバー側は、 part を送り終わっても connection を張ったまま にして、次に必要になったら新しい part を送りつけます。

結局のところ、普及せず標準化もされず、失敗に終わったと見られます。

けど、業界(どこ)ではそれなりに知名度があるらしく、 multipart/x-mixed-replace が IE では正しく表示されません、 てな質問を CGI 系 ML で稀に見かけるなあ。

接続が時間切れになる可能性をどうするのか、 時間切れが無いとしたら resource 喰うんじゃ? (keep-alive よりたちが悪そう)、 boundary が part の entity body 中に現れないことを必ずしも 保証出来るのか (HTTP で multipart/* に CTE は使えるんだっけ?)、 必ず part ごとに全体を送りなおさないといけないから無駄が多いのでは、 なんていう疑問点が浮かびます。

→CTE は使えません。たぶん。 使えたとしても、対応してる実装はそう無いでしょう。そもそも、 multipart (byterange 以外) を理解する HTTP の実装って 稀稀なのでは?

[3] 多部分境界の先頭の -- を抜かしている解説書を見かけました。いくらなんでも動作確認くらいしているでしょうから (と考えるのは甘い?)、 Classic Mozilla は多部分境界の最初の -- がなくても動くのかもしれません (要確認)。 (名無しさん)

[4] Surfin’ Safari - Blog Archive &#187; WebKit Fixes in Safari 2.0.2 / Mac OS X 10.4.3 (2007-02-03 21:37:54 +09:00 版) <http://webkit.org/blog/?p=32> (名無しさん)

[5] Bug 76816 &#8211; View Source tries to DL Bugzilla buglist as multipart/x-mixed-replace ( 版) <https://bugzilla.mozilla.org/show_bug.cgi?id=76816>

[6] img src に指定することによって、画像アニメーションさせることができたようです。

まだアニメーションGIF が無かった頃に使われていたようです。

[7] Web Applications 1.0 r6596 Specify multipart/x-mixed-replace ( ( 版)) <http://html5.org/tools/web-apps-tracker?from=6595&to=6596>

[11] [ietf-types] Registration for multipart/x-mixed-replace ( ( 版)) <http://www.ietf.org/mail-archive/web/ietf-types/current/msg01710.html>

[12] Motion JPEG - Wikipedia, the free encyclopedia ( ( 版)) <http://en.wikipedia.org/wiki/Motion_JPEG>

[13] An Exploration of Dynamic Documents ( 版) <http://web.archive.org/web/19970614044340/http://home.netscape.com/assist/net_sites/pushpull.html>

[14] IRC logs: freenode / #whatwg / 20150317 ( 版) <http://krijnhoetmer.nl/irc-logs/whatwg/20150317#l-704>

[22:19] <seth_> in general support for multipart/x-mixed-replace images and documents seems to be shrinking everywhere, but i suspect we will end up being stuck with at least the subset necessary to display JPEG webcams

[15] Issue 249132 - chromium - Remove support for multipart/x-mixed-replace main resources - An open-source project to help move the web forward. - Google Project Hosting ( 版) <https://code.google.com/p/chromium/issues/detail?id=249132>

[16] flash - multipart/x-mixed-replace ActionScript3 and Google Chrome (and others as well) - Stack Overflow ( 版) <http://stackoverflow.com/questions/5129620/multipart-x-mixed-replace-actionscript3-and-google-chrome-and-others-as-well>

[17] http - chrome multipart/x-mixed-replace connection not closed - Stack Overflow ( 版) <http://stackoverflow.com/questions/25479248/chrome-multipart-x-mixed-replace-connection-not-closed>

[18] Issue 146972 - chromium - multipart/x-mixed-replace no longer working reliably - An open-source project to help move the web forward. - Google Project Hosting ( 版) <https://code.google.com/p/chromium/issues/detail?id=146972>

[19] 987135 – motion JPEG server push (multipart/x-mixed-replace image stream) flickers and sometimes stops ( 版) <https://bugzilla.mozilla.org/show_bug.cgi?id=987135>

[20] Streaming no longer works using Google Chrome under Ubuntu 12.04 · Issue #8 · RobotWebTools/mjpeg_server ( 版) <https://github.com/RobotWebTools/mjpeg_server/issues/8>

[21] Bug 82291 – Pages containing "multipart/x-mixed-replace" resources should not be cached. ( 版) <https://bugs.webkit.org/show_bug.cgi?id=82291>

[22] Bug 47222 – Ability to pause and resume mjpeg image streams ( 版) <https://bugs.webkit.org/show_bug.cgi?id=47222>

[23] [webkit-dev] [Proposal] Remove support for 'multipart/x-mixed-replace' main resources ( 版) <https://lists.webkit.org/pipermail/webkit-dev/2015-April/027379.html>

[24] Bug 143979 – Crash when showing Web Inspector on page with 'multipart/x-mixed-replace' main resource ( 版) <https://bugs.webkit.org/show_bug.cgi?id=143979>

[25] Site Compatibility for Firefox 22 - Mozilla | MDN ( 版) <https://developer.mozilla.org/en-US/Firefox/Releases/22/Site_compatibility#XHR_multipart_response_support_has_been_removed>

Support for the multipart property and multipart/x-mixed-replace responses has been removed from XMLHttpRequest. This was a Firefox-only feature that was never standardized.

[26] 843508 – Remove support for multipart XHR responses ( 版) <https://bugzilla.mozilla.org/show_bug.cgi?id=843508>

[28] 625012 – Flickering Motion JPEG (mjpg) ( 版) <https://bugzilla.mozilla.org/show_bug.cgi?id=625012>

[38] 動画配信 ( 版) <http://www2.wisnet.ne.jp/~daddy/LC3/Broadcast.html>

実際のクライアント側の作り方に関してですが、Multipart間のヘッダーの仕様も様々なので、ちゃんとpartを理解して受信するプログラムを記述するよりも、JPEG画像の開始コードと終了コードを目安に受信した方が接続性は上がると思います。

[39] Navigate: remove "gone async" and define redirect handling (annevk著, ) <https://github.com/whatwg/html/commit/8b630f5e4fa2ec8b0999470d09490bffe6e9a1e3>

[40] Remove navigation support for multipart/x-mixed-replace resources by annevk · Pull Request #1353 · whatwg/html () <https://github.com/whatwg/html/pull/1353>

[41] 249132 - Remove support for multipart/x-mixed-replace main resources - chromium - Monorail () <https://bugs.chromium.org/p/chromium/issues/detail?id=249132>

[42] Bug 14392 – Add support for multipart/x-mixed-replace to XMLHttpRequest () <https://bugs.webkit.org/show_bug.cgi?id=14392>

[43] 237319 – Add support for server push using multipart/x-mixed-replace with XMLHttpRequest. () <https://bugzilla.mozilla.org/show_bug.cgi?id=237319>

[44] 843508 – Remove support for multipart XHR responses () <https://bugzilla.mozilla.org/show_bug.cgi?id=843508>

[45] XMLHttpRequest.multipart - Web APIs | MDN () <https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/multipart>

[46] CSP not applied to pages sent with multipart/x-mixed-replace — Mozilla () <https://www.mozilla.org/en-US/security/advisories/mfsa2016-45/>

[47] Access Denied () <https://bugzilla.mozilla.org/show_bug.cgi?id=1223743>