Media Source API

草案
此页面不完整。

Media Source API , formally known as 媒体源扩展 ( MSE ), provides functionality enabling plugin-free web-based streaming media. Using MSE, media streams can be created via JavaScript, and played using <audio> and <video> elements.

Media Source Extensions concepts and usage

Playing video and audio has been available in web applications without plugins for a few years now, but the basic features offered have really only been useful for playing single whole tracks. We can't, for example, combine/split arraybuffers. Streaming media has up until recently been the domain of Flash, with technologies like Flash Media Server serving video streams using the RTMP protocol.

The MSE standard

With Media Source Extensions (MSE), this is changing. MSE allows us to replace the usual single track src value fed to media elements with a reference to a MediaSource object, which is a container for information like the ready state of the media for being played, and references to multiple SourceBuffer objects that represent the different chunks of media that make up the entire stream. MSE gives us finer grained control over how much and how often content is fetched, and some control over memory usage details, such as when buffers are evicted. It lays the groundwork for adaptive bitrate streaming clients (such as those using DASH or HLS) to be built on its extensible API.

Creating assets that work with MSE in modern browsers is a laborious process, taking significant time, computing power, and energy. The usage of external utilities to massage the content into a suitable format is required. While browser support for the various media containers with MSE is spotty, usage of the H.264 video codec, AAC audio codec, and MP4 container format is a common baseline. MSE also provides an API for runtime detection of container and codec support.

If you do not require explicit control of video quality over time, the rate at which content is fetched, or the rate at which memory is evicted, then the <video> and <source> tags may well be a simple and adequate solution.

DASH

Dynamic Adaptive Streaming over HTTP (DASH) is a protocol for specifying how adaptive content should be fetched. It is effectively a layer built on top of MSE for building adaptive bitrate streaming clients. While there are other protocols available (such as HTTP Live Streaming (HLS)), DASH has the most platform support.

DASH moves lots of logic out of the network protocol and into the client side application logic, using the simpler HTTP protocol to fetch files.  Indeed, one can support DASH with a simple static file server, which is also great for CDNs.  This is in direct contrast with previous streaming solutions that required expensive licenses for proprietary non-standard client/server protocol implementations.

The two most common use cases for DASH involve watching content “on demand” or “live.”  On demand allows a developer to take their time transcoding the assets into multiple resolutions of various quality.

Live profile content can introduce latency due to its transcoding and broadcasting, so DASH is not suitable for real time communication like WebRTC is. It can however support significantly more client connections than WebRTC.

There are numerous available free and open source tools for transcoding content and preparing it for use with DASH, DASH file servers, and DASH client libraries written in JavaScript.

接口

MediaSource
Represents a media source to be played via an HTMLMediaElement 对象。
SourceBuffer
Represents a chunk of media to be passed into an HTMLMediaElement via a MediaSource 对象。
SourceBufferList
A simple container list for multiple SourceBuffer 对象。
VideoPlaybackQuality
Contains information about the quality of video being played by a <video> element, such as number of dropped or corrupted frames. Returned by the HTMLVideoElement.getVideoPlaybackQuality() 方法。
TrackDefault
提供 SourceBuffer with kind, label, and language information for tracks that do not contain this information in the initialization segments of a media chunk.
TrackDefaultList
A simple container list for multiple TrackDefault 对象。

Extensions to other interfaces

URL.createObjectURL()
Creates an object URL pointing to a MediaSource object that can then be specified as the src value of an HTML media element to play a media stream.
HTMLMediaElement.seekable
MediaSource object is played by an HTML media element, this property will return a TimeRanges object that contains the time ranges that the user is able to seek to.
HTMLVideoElement.getVideoPlaybackQuality()
返回 VideoPlaybackQuality object for the currently played video.
AudioTrack.sourceBuffer , VideoTrack.sourceBuffer , TextTrack.sourceBuffer
返回 SourceBuffer that created the track in question.

规范

规范 状态 Comment
媒体源扩展 Recommendation 初始定义。

浏览器兼容性

MediaSource interface

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
MediaSource
Chrome 31
31
不支持 23 — 31
Prefixed
Prefixed Implemented with the vendor prefix: WebKit
Edge 12 Firefox 42
42
不支持 25 — 42
注意事项 Disabled
注意事项 Limited support to an allowed list of sites, for example YouTube, Netflix, and other popular streaming sites. The limitation was removed when Media Source Extensions was enabled by default in Firefox 42.
Disabled From version 25 until version 42 (exclusive): this feature is behind the media.mediasource.enabled preference. To change preferences in Firefox, visit about:config.
IE 11 Opera 18
18
不支持 15 — 18
Prefixed
Prefixed Implemented with the vendor prefix: WebKit
Safari 8 WebView Android 4.4.3 Chrome Android 31
31
不支持 25 — 31
Prefixed
Prefixed Implemented with the vendor prefix: WebKit
Firefox Android 41 Opera Android 18
18
不支持 14 — 18
Prefixed
Prefixed Implemented with the vendor prefix: WebKit
Safari iOS 8 Samsung Internet Android 2.0
2.0
不支持 1.5 — 2.0
Prefixed
Prefixed Implemented with the vendor prefix: WebKit

图例

完整支持
完整支持
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。
见实现注意事项。
见实现注意事项。
用户必须明确启用此特征。
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。
要求使用供应商前缀或不同名称。

另请参阅