This repository was archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
(Not ready for publication) Web Fundamentals Update post: Unified Media Pipeline #2906
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3f03076
Merge branch 'master' of github.com:google/WebFundamentals
samdutton ca9d011
Removed nbu files
samdutton 4ee158a
Added back files
samdutton f8d6dd8
Fixed date
samdutton be889d6
Fixed bullet list wording
samdutton 61f1cb3
Added code, etc., following review from Paul and Pangu
samdutton c2a76cc
Minor tweak
samdutton 631d532
Updated browser support
samdutton 7c69d7a
Added back images
samdutton 7e35f0e
Changed Blob to blob
samdutton 9ecde27
...and one more
samdutton eb6e599
Tweaks to wording requested by jmedley
samdutton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
--- | ||
layout: updates/post | ||
title: "Service worker caching, playbackRate and blob URLs for audio and video on Chrome for Android" | ||
description: "From version 51, Android Chrome uses the same media stack as desktop Chrome, rather than relying on the underlying platform implementation. This enables service worker media caching, variable playback rates, blob URLs on Android, MediaStream passing between APIs, and easier cross-platform debugging." | ||
published_on: 2016-05-19 | ||
updated_on: 2016-05-19 | ||
authors: | ||
- samdutton | ||
tags: | ||
- audio | ||
- chrome51 | ||
- media | ||
- recording | ||
- video | ||
- webrtc | ||
featured_image: /web/updates/images/2016/04/ump/featured.jpg | ||
--- | ||
|
||
<style> | ||
.screenshot-landscape { | ||
max-width: 60%; | ||
} | ||
.screenshot-portrait { | ||
max-width: 35%; | ||
} | ||
@media screen and (max-width: 500px) { | ||
img.screenshot { | ||
max-width: 100%; | ||
} | ||
} | ||
</style> | ||
|
||
<p class="intro">Sometimes good things have boring names.</p> | ||
|
||
Case in point: the Unified Media Pipeline, **UMP** for short. | ||
|
||
This may sound like a sinister Soviet era directive, but in fact it's an important step towards consistent cross-platform audio and video delivery. Chrome on Android will now use the same media stack as desktop Chrome, rather than relying on the underlying platform implementation. | ||
|
||
UMP enables you to do a lot: | ||
|
||
* Cache audio and video with service workers, since media delivery is now implemented directly within Chrome rather than being passed off to the Android media stack. | ||
* Use blob URLs for audio and video elements. | ||
* Set `playbackRate` for audio and video. | ||
* Pass MediaStreams between Web Audio and MediaRecorder. | ||
* Develop and maintain media apps more easily across devices — media works the same on desktop and Android. | ||
|
||
UMP took some hard engineering work to implement: | ||
|
||
* A new caching layer for improved power performance. | ||
* Updating a new MediaCodec based video decoder hosted in Chrome's GPU process. | ||
* Lots of testing and iteration on different devices. | ||
|
||
Here's a <a href="https://googlechrome.github.io/samples/service-worker/prefetch-video/index.html">demo of video caching with a service worker</a>: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated sample is now live (but with questions about video hosting). |
||
|
||
<a href="https://googlechrome.github.io/samples/service-worker/prefetch-video/index.html"><img class="screenshot-landscape" src="/web/updates/images/2016/04/ump/screenshot-sw.jpg" alt="Screenshot of video playback"></a> | ||
|
||
Caching the video file and the video poster image is as simple as adding their paths to the list of URLs to prefetch: | ||
|
||
{% highlight html %} | ||
<video controls poster="static/poster.jpg"> | ||
<source src="static/video.webm" type="video/webm" /> | ||
<p>This browser does not support the video element.</p> | ||
</video> | ||
{% endhighlight %} | ||
|
||
{% highlight javascript %} | ||
var urlsToPrefetch = [ | ||
'static/video.webm', 'static/poster.jpg', | ||
]; | ||
{% endhighlight %} | ||
|
||
The inability to change `playbackRate` on Android has been a [long-standing bug](https://bugs.chromium.org/p/chromium/issues/detail?id=263654). UMP fixes this. For the demo at <a href="https://simpl.info/video/playbackrate">simpl.info/video/playbackrate</a>, `playbackRate` is set to 2. Try it out! | ||
|
||
<a href="https://simpl.info/video/playbackrate"><img class="screenshot-landscape" src="/web/updates/images/2016/04/ump/screenshot-rate.jpg" alt="Screenshot of video playback with playbackRate set to 2"></a> | ||
|
||
UMP enables blob URLs for media elements — which means that, for example, you can now <a href="https://webrtc.github.io/samples/src/content/getusermedia/record/" title="MediRecorder demo">play back a video recorded using the MediaRecorder API</a> in a video element on Android: | ||
|
||
<a href="https://webrtc.github.io/samples/src/content/getusermedia/record/"><img class="screenshot-landscape" src="/web/updates/images/2016/04/ump/screenshot-mr.jpg" alt="Screenshot of playback in Chrome on Android of a video recorded using the MediaRecorder API"></a> | ||
|
||
Here's the relevant code: | ||
|
||
{% highlight javascript %} | ||
var recordedBlobs = []; | ||
|
||
mediaRecorder.ondataavailable = function(event) { | ||
if (event.data && event.data.size > 0) { | ||
recordedBlobs.push(event.data); | ||
} | ||
}; | ||
|
||
function play() { | ||
var superBuffer = new Blob(recordedBlobs, {type: 'video/webm'}); | ||
recordedVideo.src = window.URL.createObjectURL(superBuffer); | ||
} | ||
{% endhighlight %} | ||
|
||
For the demo at <a href="https://simpl.info/video/offline" title="Offline video using the File APIs">simpl.info/video/offline</a>, video is stored using the File APIs, then played back using a Blob URL: | ||
|
||
<a href="https://simpl.info/video/offline"><img class="screenshot-portrait" src="/web/updates/images/2016/04/ump/screenshot-file.jpg" alt="Screenshot of playback in Chrome on Android of video stored using the File APIs"></a> | ||
|
||
{% highlight javascript %} | ||
function writeToFile(fileEntry, blob) { | ||
fileEntry.createWriter(function(fileWriter) { | ||
fileWriter.onwriteend = function() { | ||
readFromFile(fileEntry.fullPath); | ||
}; | ||
fileWriter.onerror = function(e) { | ||
log('Write failed: ' + e.toString()); | ||
}; | ||
fileWriter.write(blob); | ||
}, handleError); | ||
} | ||
|
||
function readFromFile(fullPath) { | ||
window.fileSystem.root.getFile(fullPath, {}, function(fileEntry) { | ||
fileEntry.file(function(file) { | ||
var reader = new FileReader(); | ||
reader.onloadend = function() { | ||
video.src = URL.createObjectURL(new Blob([this.result])); | ||
}; | ||
reader.readAsArrayBuffer(file); | ||
}, handleError); | ||
}, handleError); | ||
} | ||
{% endhighlight %} | ||
|
||
The Unified Media Pipeline has also been [enabled for Media Source Extensions (MSE) and Encrypted Media Extensions (EME)](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-reviews/Qi4dLcKjcCM). | ||
|
||
This is another step towards unifying mobile and desktop Chrome. You don't need to change your code, but building a consistent media experience across desktop and mobile should now be easier, since the media stack is the same across platforms. Debugging with Chrome DevTools? Mobile emulation now uses the 'real' audio and video stack. | ||
|
||
If you experience problems as a result of the Unified Media Pipeline, please file issues on the [implementation bug](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-reviews/Qi4dLcKjcCM) or via [new.crbug.com](https://new.crbug.com). | ||
|
||
## Demos | ||
|
||
* <a href="https://googlechrome.github.io/samples/service-worker/prefetch-video/index.html">Cache video with a service worker</a> | ||
* <a href="https://simpl.info/video/playbackrate">Media `playbackRate`</a> | ||
* <a href="https://simpl.info/mediarecorder">MediaRecorder: playback using a blob URL</a> | ||
* <a href="https://simpl.info/video/offline">Offline video implemented with the File APIs</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't capitalize file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the name of a set of APIs: the File APIs. (See simpl.info/mse for an example.) |
||
|
||
## Relevant bugs | ||
|
||
* [Tracking issues for the Unified Media Pipeline](https://bugs.chromium.org/p/chromium/issues/detail?id=507834) | ||
* [UMP Field Trial](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-reviews/okUkrNc0z6w) | ||
* [MSE, EME and the Unified Media Pipeline](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-reviews/Qi4dLcKjcCM) | ||
|
||
There are a couple of bugs affecting <video>, service workers and the Cache Storage API: | ||
|
||
* [<video> triggers a mode: cors request and won't accept an opaque service worker response](https://bugs.chromium.org/p/chromium/issues/detail?id=546076) | ||
* [Seeking doesn't work in videos served by service worker cache](https://bugs.chromium.org/p/chromium/issues/detail?id=575357) | ||
|
||
|
||
## Browser support | ||
|
||
* Enabled by default in Chrome 52 and above. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't capitalize Web Audio.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Web Audio (capitalized) refers to the Web Audio API (not just 'web audio').