Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
ogv.js
2
======
3
 
4
Media decoder and player for Ogg Vorbis/Opus/Theora and WebM VP8/VP9/AV1 video.
5
 
6
Based around libogg, libvorbis, libtheora, libopus, libvpx, libnestegg and dav1d compiled to JavaScript and WebAssembly with Emscripten.
7
 
8
## Updates
9
 
10
1.8.9 - 2022-04-06
11
* Bump yuv-canvas to 1.2.11, further perf improvments for frame drawing
12
* Workaround gets audio working when ringer is disabled by iOS hardware switch
13
 
14
1.8.8 - 2022-04-04
15
* Bump yuv-canvas to 1.2.10, fixes WebGL scaling bug in Netscape/macOS; adjustment to prior performance tweaks.
16
 
17
1.8.7 - 2022-03-29
18
* Bump emscripten compatibility to 3.1.8
19
* Bump Opus to 1.3.1
20
* Bump yuv-canvas to 1.2.9, fixes WebGL performance regressions on some browsers
21
* experimental demo/threaded.php provides a COOP-COEP-CORP environment for testing threaded decoders (top-level frame and all worker JS must opt in to COOP-COEP; CORP or CORS required for most loaded resources)
22
 
23
1.8.6 - 2022-01-12
24
* Bump to yuv-canvas
25
* Fix demo for removal of video-canvas mode
26
 
27
1.8.5 - 2022-01-11
28
* Remove unnecessary user-agent checks
29
* Remove flaky, obsolete support for faking CSS `object-fit`
30
* Remove experimental support for streaming `<canvas>` into `<video>`
31
 
32
1.8.4 - 2021-07-02
33
* Fix for fix for OGVLoader.base fix
34
 
35
1.8.3 - 2021-07-02
36
* Fixes for build with emscripten 2.0.25
37
* Fix for nextTick/setImmediate-style polyfill in front-end
38
* Provisional fix for OGVLoader.base not working with CDNs
39
    * the fallback code for loading a non-local worker had been broken with WebAssembly for some time, sorry!
40
 
41
1.8.2 - errored out
42
 
43
1.8.1 - 2021-02-18
44
* Fixed OGVCompat APIs to correctly return false without WebAssembly and Web Audio
45
 
46
1.8.0 - 2021-02-09
47
* Dropping IE support and Flash audio backend
48
    * Updated to stream-file 0.3.0
49
    * Updated to audio-feeder 0.5.0
50
    * The old IE 10/11 support _no longer works_ due to the Flash plugin being disabled, and so is being removed
51
* Drop es6-promise shim
52
    * Now requires WebAssembly, which requires native Promise support
53
* Build & fixes
54
    * Demo fixed (removed test files that are now offline)
55
    * Builds with emscripten 2.0.13
56
    * Requires latest meson from git pending a fix hitting release
57
 
58
1.7.0 - 2020-09-28
59
* Builds with emscripten's LLVM upstream backend
60
    * Updated to build with emscripten 2.0.4
61
* Reduced amount of memory used between GC runs by reusing frame buffers
62
* Removed `memoryLimit` option
63
    * JS, Wasm, and threaded Wasm builds now all use dynamic memory growth
64
* Updated dav1d
65
* Updated libvpx to 1.8.1
66
* Experimental SIMD builds of AV1 decoder optional, with `make SIMD=1`
67
    * These work in Chrome with the "WebAssembly SIMD" flag enabled in chrome://flags/
68
    * Significant speed boost when available.
69
    * Available with and without multithreading.
70
    * Must enable explicitly with `simd: true` in `options`.
71
* Experimental SIMD work for VP9 as well, incomplete.
72
 
73
1.6.1 - 2019-06-18
74
* playbackSpeed attribute now supported
75
* updated audio-feeder to 0.4.21;
76
    * mono audio is now less loud, matching native playback better
77
    * audio resampling now uses linear interpolation for upscaling
78
    * fix for IE in bundling scenarios that use strict mode
79
    * tempo change support thanks to a great patch from velochy!
80
* updated yuv-canvas to 1.2.6;
81
    * fixes for capturing WebGL canvas as MediaStream
82
* fixes for seeks on low frame rate video
83
* updated emscripten toolchain to 1.38.36
84
    * drop OUTLINING_LIMIT from AV1 JS build; doesn't work in newer emscripten and not really needed
85
 
86
1.6.0 - 2019-02-26
87
* experimental support for AV1 video in WebM
88
* update buildchain to emscripten 1.38.28
89
* fix a stray global
90
* starting to move to ES6 classes and modules
91
* building with babel for ES5/IE11 compat
92
* updated eslint
93
* updated yuv-canvas to 1.2.4; fixes for software GL rendering
94
* updated audio-feeder to 0.4.15; fixes for resampling and Flash perf
95
* retooled buffer copies
96
* sync fix for audio packets with discard padding
97
* clients can pass a custom `StreamFile` instance as `{stream:foo}` in options. This can be useful for custom streaming until MSE interfaces are ready.
98
* refactored WebM keyframe detection
99
* prefill the frame pipeline as well as the audio pipeline before starting audio
100
* removed BINARYEN_IGNORE_IMPLICIT_TRAPS=1 option which can cause intermittent breakages
101
* changed download streaming method to avoid data corruption problem on certain files
102
* fix for seek on very short WebM files
103
* fix for replay-after-end-of-playback in WebM
104
 
105
See more details and history in [CHANGES.md](https://github.com/brion/ogv.js/blob/master/CHANGES.md)
106
 
107
## Current status
108
 
109
Note that as of 2021 ogv.js works pretty nicely but may still have some packagine oddities with tools like webpack. It should work via CDNs again as of 1.8.2 if you can't or don't want to package locally, but this is not documented well yet. Improved documentation will come with the next major update & code cleanup!
110
 
111
Since August 2015, ogv.js can be seen in action [on Wikipedia and Wikimedia Commons](https://commons.wikimedia.org/wiki/Commons:Video) in Safari and IE/Edge where native Ogg and WebM playback is not available. (See [technical details on MediaWiki integration](https://www.mediawiki.org/wiki/Extension:TimedMediaHandler/ogv.js).)
112
 
113
See also a standalone demo with performance metrics at https://brionv.com/misc/ogv.js/demo/
114
 
115
* streaming: yes (with Range header)
116
* seeking: yes for Ogg and WebM (with Range header)
117
* color: yes
118
* audio: yes, with a/v sync (requires Web Audio or Flash)
119
* background threading: yes (video, audio decoders in Workers)
120
* [GPU accelerated drawing: yes (WebGL)](https://github.com/brion/ogv.js/wiki/GPU-acceleration)
121
* GPU accelerated decoding: no
122
* SIMD acceleration: no
123
* Web Assembly: yes (with asm.js fallback)
124
* multithreaded VP8, VP9, AV1: in development (set `options.threading` to `true`; requires flags to be enabled in Firefox 65 and Chrome 72, no support yet in Safari)
125
* controls: no (currently provided by demo or other UI harness)
126
 
127
Ogg and WebM files are fairly well supported.
128
 
129
 
130
## Goals
131
 
132
Long-form goal is to create a drop-in replacement for the HTML5 video and audio tags which can be used for basic playback of Ogg Theora and Vorbis or WebM media on browsers that don't support Ogg or WebM natively.
133
 
134
The API isn't quite complete, but works pretty well.
135
 
136
 
137
## Compatibility
138
 
139
ogv.js requires a fast JS engine with typed arrays, and Web Audio for audio playback.
140
 
141
The primary target browsers are (testing 360p/30fps and up):
142
* Safari 6.1-12 on Mac OS X 10.7-10.14
143
* Safari on iOS 10-11 64-bit
144
 
145
Older versions of Safari have flaky JIT compilers. IE 9 and below lack typed arrays, and IE 10/11 no longer support an audio channel since the Flash plugin was sunset.
146
 
147
(Note that Windows and Mac OS X can support Ogg and WebM by installing codecs or alternate browsers with built-in support, but this is not possible on iOS where all browsers are really Safari.)
148
 
149
Testing browsers (these support .ogv and .webm natively):
150
* Firefox 65
151
* Chrome 73
152
 
153
 
154
## Package installation
155
 
156
Pre-built releases of ogv.js are available as [.zip downloads from the GitHub releases page](https://github.com/brion/ogv.js/releases) and through the npm package manager.
157
 
158
You can load the `ogv.js` main entry point directly in a script tag, or bundle it through whatever build process you like. The other .js files must be made available for runtime loading, together in the same directory.
159
 
160
ogv.js will try to auto-detect the path to its resources based on the script element that loads ogv.js or ogv-support.js. If you load ogv.js through another bundler (such as browserify or MediaWiki's ResourceLoader) you may need to override this manually before instantiating players:
161
 
162
```
163
  // Path to ogv-demuxer-ogg.js, ogv-worker-audio.js, etc
164
  OGVLoader.base = '/path/to/resources';
165
```
166
 
167
To fetch from npm:
168
 
169
```
170
npm install ogv
171
```
172
 
173
The distribution-ready files will appear in 'node_modules/ogv/dist'.
174
 
175
To load the player library into your browserify or webpack project:
176
 
177
```
178
var ogv = require('ogv');
179
 
180
// Access public classes either as ogv.OGVPlayer or just OGVPlayer.
181
// Your build/lint tools may be happier with ogv.OGVPlayer!
182
ogv.OGVLoader.base = '/path/to/resources';
183
var player = new ogv.OGVPlayer();
184
```
185
 
186
## Usage
187
 
188
The `OGVPlayer` class implements a player, and supports a subset of the events, properties and methods from [HTMLMediaElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement) and [HTMLVideoElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement).
189
 
190
```
191
  // Create a new player with the constructor
192
  var player = new OGVPlayer();
193
 
194
  // Or with options
195
  var player = new OGVPlayer({
196
	debug: true,
197
	debugFilter: /demuxer/
198
  });
199
 
200
  // Now treat it just like a video or audio element
201
  containerElement.appendChild(player);
202
  player.src = 'path/to/media.ogv';
203
  player.play();
204
  player.addEventListener('ended', function() {
205
    // ta-da!
206
  });
207
```
208
 
209
To check for compatibility before creating a player, include `ogv-support.js` and use the `OGVCompat` API:
210
 
211
```
212
  if (OGVCompat.supported('OGVPlayer')) {
213
    // go load the full player from ogv.js and instantiate stuff
214
  }
215
```
216
 
217
This will check for typed arrays, web audio, blacklisted iOS versions, and super-slow/broken JIT compilers.
218
 
219
If you need a URL versioning/cache-buster parameter for dynamic loading of `ogv.js`, you can use the `OGVVersion` symbol provided by `ogv-support.js` or the even tinier `ogv-version.js`:
220
 
221
```
222
  var script = document.createElement('script');
223
  script.src = 'ogv.js?version=' + encodeURIComponent(OGVVersion);
224
  document.querySelector('head').appendChild(script);
225
```
226
 
227
## Distribution notes
228
 
229
Entry points:
230
* `ogv.js` contains the main runtime classes, including OGVPlayer, OGVLoader, and OGVCompat.
231
* `ogv-support.js` contains the OGVCompat class and OGVVersion symbol, useful for checking for runtime support before loading the main `ogv.js`.
232
* `ogv-version.js` contains only the OGVVersion symbol.
233
 
234
These entry points may be loaded directly from a script element, or concatenated into a larger project, or otherwise loaded as you like.
235
 
236
Further code modules are loaded at runtime, which must be available with their defined names together in a directory. If the files are not hosted same-origin to the web page that includes them, you will need to set up appropriate CORS headers to allow loading of the worker JS modules.
237
 
238
Dynamically loaded assets:
239
* `ogv-worker-audio.js`, `ogv-worker-video.js`, and `*.worker.js` are Worker entry points, used to run video and audio decoders in the background.
240
* `ogv-demuxer-ogg-wasm.js/.wasm` are used in playing .ogg, .oga, and .ogv files.
241
* `ogv-demuxer-webm-wasm.js/.wasm` are used in playing .webm files.
242
* `ogv-decoder-audio-vorbis-wasm.js/.wasm` and `ogv-decoder-audio-opus-wasm.js/.wasm` are used in playing both Ogg and WebM files containing audio.
243
* `ogv-decoder-video-theora-wasm.js/.wasm` are used in playing .ogg and .ogv video files.
244
* `ogv-decoder-video-vp8-wasm.js/.wasm` and `ogv-decoder-video-vp9-wasm.js/.wasm` are used in playing .webm video files.
245
* `*-mt.js/.wasm` are the multithreaded versions of some of the above modules. They have additional support files.
246
 
247
If you know you will never use particular formats or codecs you can skip bundling them; for instance if you only need to play Ogg files you don't need `ogv-demuxer-webm-wasm.js` or `ogv-decoder-video-vp8-wasm.js` which are only used for WebM.
248
 
249
 
250
## Performance
251
 
252
(This section is somewhat out of date.)
253
 
254
As of 2015, for SD-or-less resolution basic Ogg Theora decoding speed is reliable on desktop and newer high-end mobile devices; current high-end desktops and laptops can even reach HD resolutions. Older and low-end mobile devices may have difficulty on any but audio and the lowest-resolution video files.
255
 
256
WebM VP8/VP9 is slower, but works pretty well at a resolution step below Theora.
257
 
258
AV1 is slower still, and tops out around 360p for single-threaded decoding on a fast desktop or iOS device.
259
 
260
*Low-res targets*
261
 
262
I've gotten acceptable performance for Vorbis audio and 160p/15fps Theora files on 32-bit iOS devices: iPhone 4s, iPod Touch 5th-gen and iPad 3. These have difficulty at 240p and above, and just won't keep up with higher resolutions.
263
 
264
Meanwhile, newer 64-bit iPhones and iPads are comparable to low-end laptops, and videos at 360p and often 480p play acceptably. Since 32-bit and 64-bit iOS devices have the same user-agent, a benchmark must be used to approximately test minimum CPU speed.
265
 
266
(On iOS, Safari performs significantly better than some alternative browsers that are unable to enable the JIT due to use of the old UIWebView API. Chrome 49 and Firefox for iOS are known to work using the newer WKWebView API internally. Again, a benchmark must be used to detect slow performance, as the browser remains otherwise compatible.)
267
 
268
 
269
Windows on 32-bit ARM platforms is similar... IE 11 on Windows RT 8.1 on a Surface tablet (NVidia Tegra 3) does not work (crashes IE), while Edge on Windows 10 Mobile works ok at low resolutions, having trouble starting around 240p.
270
 
271
 
272
In both cases, a native application looms as a possibly better alternative. See [OGVKit](https://github.com/brion/OGVKit) and [OgvRt](https://github.com/brion/OgvRT) projects for experiments in those directions.
273
 
274
 
275
Note that at these lower resolutions, Vorbis audio and Theora video decoding are about equally expensive operations -- dual-core phones and tablets should be able to eke out a little parallelism here thanks to audio and video being in separate Worker threads.
276
 
277
 
278
*WebGL drawing acceleration*
279
 
280
Accelerated YCbCr->RGB conversion and drawing is done using WebGL on supporting browsers, or through software CPU conversion if not. This is abstracted in the [yuv-canvas](https://github.com/brion/yuv-canvas) package, now separately installable.
281
 
282
It may be possible to do further acceleration of actual decoding operations using WebGL shaders, but this could be ... tricky. WebGL is also only available on the main thread, and there are no compute shaders yet so would have to use fragment shaders.
283
 
284
 
285
## Difficulties
286
 
287
*Threading*
288
 
289
Currently the video and audio codecs run in worker threads by default, while the demuxer and player logic run on the UI thread. This seems to work pretty well.
290
 
291
There is some overhead in extracting data out of each emscripten module's heap and in the thread-to-thread communications, but the parallelism and smoother main thread makes up for it.
292
 
293
*Streaming download*
294
 
295
Streaming buffering is done by chunking the requests at up to a megabyte each, using the HTTP Range header. For cross-site playback, this requires CORS setup to whitelist the Range header! Chunks are downloaded as ArrayBuffers, so a chunk must be loaded in full before demuxing or playback can start.
296
 
297
Old versions of [Safari have a bug with Range headers](https://bugs.webkit.org/show_bug.cgi?id=82672) which is worked around as necessary with a 'cache-busting' URL string parameter.
298
 
299
 
300
*Seeking*
301
 
302
Seeking is implemented via the HTTP Range: header.
303
 
304
For Ogg files with keyframe indices in a skeleton index, seeking is very fast. Otherwise,  a bisection search is used to locate the target frame or audio position, which is very slow over the internet as it creates a lot of short-lived HTTP requests.
305
 
306
For WebM files with cues, efficient seeking is supported as well as of 1.1.2. WebM files without cues can be seeked in 1.5.5, but inefficiently via linear seek from the beginning. This is fine for small audio-only files, but might be improved for large files with a bisection in future.
307
 
308
As with chunked streaming, cross-site playback requires CORS support for the Range header.
309
 
310
 
311
*Audio output*
312
 
313
Audio output is handled through the [AudioFeeder](https://github.com/brion/audio-feeder) library, which encapsulates use of Web Audio API:
314
 
315
Firefox, Safari, Chrome, and Edge support the W3C Web Audio API.
316
 
317
IE is no longer supported; the workaround using Flash no longer works due to sunsetting of the Flash plugin.
318
 
319
A/V synchronization is performed on files with both audio and video, and seems to actually work. Yay!
320
 
321
Note that autoplay with audio doesn't work on iOS Safari due to limitations with starting audio playback from event handlers; if playback is started outside an event handler, the player will hang due to broken audio.
322
 
323
As of 1.1.1, muting before script-triggered playback allows things to work:
324
 
325
```
326
  player = new OGVPlayer();
327
  player.muted = true;
328
  player.src = 'path/to/file-with-audio.ogv';
329
  player.play();
330
```
331
 
332
You can then unmute the video in response to a touch or click handler. Alternately if audio is not required, do not include an audio track in the file.
333
 
334
 
335
*WebM*
336
 
337
WebM support was added in June 2015, with some major issues finally worked out in May 2016. Initial VP9 support was added in February 2017. It's pretty stable in production use at Wikipedia and is enabled by default as of October 2015.
338
 
339
Beware that performance of WebM VP8 is much slower than Ogg Theora, and VP9 is slightly slower still.
340
 
341
For best WebM decode speed, consider encoding VP8 with "profile 1" (simple deblocking filter) which will sacrifice quality modestly, mainly in high-motion scenes. When encoding with ffmpeg, this is the `-profile:v 1` option to the `libvpx` codec.
342
 
343
It is also recommended to use the `-slices` option for VP8, or `-tile-columns` for VP9, to maximize ability to use multithreaded decoding when available in the future.
344
 
345
*AV1*
346
 
347
WebM files containing the AV1 codec are supported as of 1.6.0 (February 2019) using the [dav1d](https://code.videolan.org/videolan/dav1d) decoder.
348
 
349
Currently this is experimental, and does not advertise support via `canPlayType`.
350
 
351
Performance is about 2-3x slower than VP8 or VP9, and may require bumping down a resolution step or two to maintain frame rate. There may be further optimizations that can be done to improve this a bit, but the best improvements will come from future improvements to WebAssembly multithreading and SIMD.
352
 
353
Currently AV1 in MP4 container is not supported.
354
 
355
## Upstream library notes
356
 
357
We've experimented with tremor (libivorbis), an integer-only variant of libvorbis. This actually does *not* decode faster, but does save about 200kb off our generated JavaScript, presumably thanks to not including an encoder in the library. However on slow devices like iPod Touch 5th-generation, it makes a significant negative impact on the decode time so we've gone back to libvorbis.
358
 
359
The Ogg Skeleton library (libskeleton) is a bit ... unfinished and is slightly modified here.
360
 
361
libvpx is slightly modified to work around emscripten threading limitations in the VP8 decoder.
362
 
363
 
364
## WebAssembly
365
 
366
WebAssembly (Wasm) builds are used exclusively as of 1.8.0, as Safari's Wasm support is pretty well established now and IE no longer works due to the Flash plugin deprecation.
367
 
368
 
369
## Multithreading
370
 
371
Experimental multithreaded VP8, VP9, and AV1 decoding up to 4 cores is in development, requiring emscripten 1.38.27 to build.
372
 
373
Multithreading is used only if `options.threading` is true. This requires browser support for the new `SharedArrayBuffer` and `Atomics` APIs, currently available in Firefox and Chrome with experimental flags enabled.
374
 
375
Threading currently requires WebAssembly; JavaScript builds are possible but perform poorly.
376
 
377
Speedups will only be noticeable when using the "slices" or "token partitions" option for VP8 encoding, or the "tile columns" option for VP9 encoding.
378
 
379
If you are making a slim build and will not use the `threading` option, you can leave out the `*-mt.*` files.
380
 
381
 
382
## Building JS components
383
 
384
Building ogv.js is known to work on Mac OS X and Linux (tested Fedora 29 and Ubuntu 18.10 with Meson manually updated).
385
 
386
1. You will need autoconf, automake, libtool, pkg-config, meson, ninja, and node (nodejs). These can be installed through Homebrew on Mac OS X, or through distribution-specific methods on Linux. For meson, you may need a newer version than your distro packages -- install it manually with `pip3` or from source.
387
2. Install [Emscripten](http://kripken.github.io/emscripten-site/docs/getting_started/Tutorial.html); currently building with 2.0.13.
388
3. `git submodule update --init`
389
4. Run `npm install` to install build utilities
390
5. Run `make js` to configure and build the libraries and the C wrapper
391
 
392
 
393
## Building the demo
394
 
395
If you did all the setup above, just run `make demo` or `make`. Look in build/demo/ and enjoy!
396
 
397
 
398
## License
399
 
400
libogg, libvorbis, libtheora, libopus, nestegg, libvpx, and dav1d are available under their respective licenses, and the JavaScript and C wrapper code in this repo is licensed under MIT.
401
 
402
Based on build scripts from https://github.com/devongovett/ogg.js
403
 
404
See [AUTHORS.md](https://github.com/brion/ogv.js/blob/master/AUTHORS.md) and/or the git history for a list of contributors.