DASH Adaptive Streaming for HTML 5 Video
Dynamic Adaptive Streaming over HTTP (DASH) is an adaptive streaming protocol. This means that it allows for a video stream to switch between bit rates on the basis of network performance, in order to keep a video playing.
Browser Support
Firefox 21 includes an implementation of DASH for HTML5 WebM video which is turned off by default. It can be enabled via "about:config" and the "media.dash.enabled" preference.
Firefox 23 removed support for DASH for HTML5 WebM video. It will be replaced by an implementation of the Media Source Extensions API which will allow support for DASH via Javascript libraries such as dash.js. See bug 778617 for details.
Using DASH - Server Side
First you'll need to convert your WebM video to a DASH manifest with the accompanying video files in various bit rates. To start with you'll need:
- ffpmeg - with libvpx and libvoribis support for WebM video and audio (ffmpeg.org).
- libwebm - specifically for the samplemuxer tool (git clone https://gerrit.chromium.org/gerrit/p/webm/libwebm.git).
- webm-tools - specifically for the manifest creation tool, webm_dash_manifest (git clone https://gerrit.chromium.org/gerrit/p/webm/webm-tools.git).
1. Use your existing WebM file to create one audio file and multiple video files.
For example:
The file in.video can be any container with at least one audio and one video stream that can be decoded by ffmpeg,
Create the audio using:
ffmpeg -i in.video -vn -acodec libvorbis -ab 128k my_audio.webm
Create each video variant.
<code>ffmpeg -i in.video -c:v </code>libvpx-vp9 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 -f webm -dash 1 \ -an -vf scale=160:190 -b:v 250k video_160x90_250k.webm ffmpeg -i in.video -c:v libvpx-vp9 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 -f webm -dash 1 \ -an -vf scale=320:180 -b:v 500k video_320x180_500k.webm <code>ffmpeg -i in.video -c:v </code>libvpx-vp9 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 -f webm -dash 1 \ -an -vf scale=640:360 -b:v 750k video_640x360_750k.webm <code>ffmpeg -i in.video -c:v </code>libvpx-vp9 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 -f webm -dash 1 \ -an -vf scale=640:360 -b:v 1000k video_640x360_1000k.webm <code>ffmpeg -i in.video -c:v </code>libvpx-vp9 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 -f webm -dash 1 \ -an -vf scale=1280:720 -b:v 1500k video_1280x720_1500k.webm
Or do it in all in one command.
ffmpeg -i in.video -c:v libvpx-vp9 -keyint_min 150 \ -g 150 -tile-columns 4 -frame-parallel 1 -f webm -dash 1 \ -an -vf scale=160:190 -b:v 250k video_160x90_250k.webm \ -an -vf scale=320:180 -b:v 500k video_320x180_500k.webm \ -an -vf scale=640:360 -b:v 750k video_640x360_750k.webm \ -an -vf scale=640:360 -b:v 1000k video_640x360_1000k.webm \ -an -vf scale=1280:720 -b:v 1500k video_1280x720_1500k.webm
2. Align the clusters to enable switching at cluster boundaries.
For video:
samplemuxer -i my_video-250kbps.webm -o my_video-250kbps-final.webm</code> <code>etc.
Although we don't switch audio streams, it's still necessary to run it through samplemuxer to ensure a cues element is added. Note: to be compatible with playing on Chrome, it is suggested to change the track number to something other than the one in the video files, most likely 0.
samplemuxer -i my_audio.webm -o my_audio-final.webm -output_cues 1 -cues_on_audio_track 1 -max_cluster_duration 2 -audio_track_number
3. Create the manifest file:
webm_dash_manifest -o my_video_manifest.mpd \ -as id=0,lang=eng \ -r id=0,file=my_video-250kbps-final.webm \ -r id=1,file=my_video-100kbps-final.webm \ -r id=2,file=my_video-50kbps-final.webm \ -as id=1,lang=eng \ -r id=4,file=my_audio-final.webm
Put the manifest and the associated video files on your web server or CDN. DASH works via HTTP, so as long as your HTTP server supports byte range requests, and it's set up to serve .mpd files with mimetype="application/dash+xml", then you're all set.
Using DASH - Client Side
You'll want to modify your web page to point to the DASH manifest first, instead of directly to a particular video file:
<video> <source src="movie.mpd"> <source src="movie.webm"> Your browser does not support the video tag. </video>
That's it! If DASH is supported by the browser, your video will now stream adaptively.
Links
WebM DASH Specification at The WebM Project
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/html/dash_adaptive_streaming_for_html_5_video