Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
 
1441 ariadna 10
1.9.0 - 2024-04-23
11
* update repo URL
12
* update build to emscripten 3.1.57
13
* remove execute bits from wasm
14
 
1 efrain 15
1.8.9 - 2022-04-06
16
* Bump yuv-canvas to 1.2.11, further perf improvments for frame drawing
17
* Workaround gets audio working when ringer is disabled by iOS hardware switch
18
 
19
1.8.8 - 2022-04-04
20
* Bump yuv-canvas to 1.2.10, fixes WebGL scaling bug in Netscape/macOS; adjustment to prior performance tweaks.
21
 
22
1.8.7 - 2022-03-29
23
* Bump emscripten compatibility to 3.1.8
24
* Bump Opus to 1.3.1
25
* Bump yuv-canvas to 1.2.9, fixes WebGL performance regressions on some browsers
26
* 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)
27
 
28
1.8.6 - 2022-01-12
29
* Bump to yuv-canvas
30
* Fix demo for removal of video-canvas mode
31
 
32
1.8.5 - 2022-01-11
33
* Remove unnecessary user-agent checks
34
* Remove flaky, obsolete support for faking CSS `object-fit`
35
* Remove experimental support for streaming `<canvas>` into `<video>`
36
 
37
1.8.4 - 2021-07-02
38
* Fix for fix for OGVLoader.base fix
39
 
40
1.8.3 - 2021-07-02
41
* Fixes for build with emscripten 2.0.25
42
* Fix for nextTick/setImmediate-style polyfill in front-end
43
* Provisional fix for OGVLoader.base not working with CDNs
44
    * the fallback code for loading a non-local worker had been broken with WebAssembly for some time, sorry!
45
 
46
1.8.2 - errored out
47
 
48
1.8.1 - 2021-02-18
49
* Fixed OGVCompat APIs to correctly return false without WebAssembly and Web Audio
50
 
51
1.8.0 - 2021-02-09
52
* Dropping IE support and Flash audio backend
53
    * Updated to stream-file 0.3.0
54
    * Updated to audio-feeder 0.5.0
55
    * The old IE 10/11 support _no longer works_ due to the Flash plugin being disabled, and so is being removed
56
* Drop es6-promise shim
57
    * Now requires WebAssembly, which requires native Promise support
58
* Build & fixes
59
    * Demo fixed (removed test files that are now offline)
60
    * Builds with emscripten 2.0.13
61
    * Requires latest meson from git pending a fix hitting release
62
 
63
1.7.0 - 2020-09-28
64
* Builds with emscripten's LLVM upstream backend
65
    * Updated to build with emscripten 2.0.4
66
* Reduced amount of memory used between GC runs by reusing frame buffers
67
* Removed `memoryLimit` option
68
    * JS, Wasm, and threaded Wasm builds now all use dynamic memory growth
69
* Updated dav1d
70
* Updated libvpx to 1.8.1
71
* Experimental SIMD builds of AV1 decoder optional, with `make SIMD=1`
72
    * These work in Chrome with the "WebAssembly SIMD" flag enabled in chrome://flags/
73
    * Significant speed boost when available.
74
    * Available with and without multithreading.
75
    * Must enable explicitly with `simd: true` in `options`.
76
* Experimental SIMD work for VP9 as well, incomplete.
77
 
78
1.6.1 - 2019-06-18
79
* playbackSpeed attribute now supported
80
* updated audio-feeder to 0.4.21;
81
    * mono audio is now less loud, matching native playback better
82
    * audio resampling now uses linear interpolation for upscaling
83
    * fix for IE in bundling scenarios that use strict mode
84
    * tempo change support thanks to a great patch from velochy!
85
* updated yuv-canvas to 1.2.6;
86
    * fixes for capturing WebGL canvas as MediaStream
87
* fixes for seeks on low frame rate video
88
* updated emscripten toolchain to 1.38.36
89
    * drop OUTLINING_LIMIT from AV1 JS build; doesn't work in newer emscripten and not really needed
90
 
91
1.6.0 - 2019-02-26
92
* experimental support for AV1 video in WebM
93
* update buildchain to emscripten 1.38.28
94
* fix a stray global
95
* starting to move to ES6 classes and modules
96
* building with babel for ES5/IE11 compat
97
* updated eslint
98
* updated yuv-canvas to 1.2.4; fixes for software GL rendering
99
* updated audio-feeder to 0.4.15; fixes for resampling and Flash perf
100
* retooled buffer copies
101
* sync fix for audio packets with discard padding
102
* clients can pass a custom `StreamFile` instance as `{stream:foo}` in options. This can be useful for custom streaming until MSE interfaces are ready.
103
* refactored WebM keyframe detection
104
* prefill the frame pipeline as well as the audio pipeline before starting audio
105
* removed BINARYEN_IGNORE_IMPLICIT_TRAPS=1 option which can cause intermittent breakages
106
* changed download streaming method to avoid data corruption problem on certain files
107
* fix for seek on very short WebM files
108
* fix for replay-after-end-of-playback in WebM
109
 
1441 ariadna 110
See more details and history in [CHANGES.md](https://github.com/bvibber/ogv.js/blob/master/CHANGES.md)
1 efrain 111
 
112
## Current status
113
 
114
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!
115
 
116
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).)
117
 
118
See also a standalone demo with performance metrics at https://brionv.com/misc/ogv.js/demo/
119
 
120
* streaming: yes (with Range header)
121
* seeking: yes for Ogg and WebM (with Range header)
122
* color: yes
123
* audio: yes, with a/v sync (requires Web Audio or Flash)
124
* background threading: yes (video, audio decoders in Workers)
1441 ariadna 125
* [GPU accelerated drawing: yes (WebGL)](https://github.com/bvibber/ogv.js/wiki/GPU-acceleration)
1 efrain 126
* GPU accelerated decoding: no
127
* SIMD acceleration: no
128
* Web Assembly: yes (with asm.js fallback)
129
* 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)
130
* controls: no (currently provided by demo or other UI harness)
131
 
132
Ogg and WebM files are fairly well supported.
133
 
134
 
135
## Goals
136
 
137
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.
138
 
139
The API isn't quite complete, but works pretty well.
140
 
141
 
142
## Compatibility
143
 
144
ogv.js requires a fast JS engine with typed arrays, and Web Audio for audio playback.
145
 
146
The primary target browsers are (testing 360p/30fps and up):
147
* Safari 6.1-12 on Mac OS X 10.7-10.14
148
* Safari on iOS 10-11 64-bit
149
 
150
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.
151
 
152
(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.)
153
 
154
Testing browsers (these support .ogv and .webm natively):
155
* Firefox 65
156
* Chrome 73
157
 
158
 
159
## Package installation
160
 
1441 ariadna 161
Pre-built releases of ogv.js are available as [.zip downloads from the GitHub releases page](https://github.com/bvibber/ogv.js/releases) and through the npm package manager.
1 efrain 162
 
163
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.
164
 
165
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:
166
 
167
```
168
  // Path to ogv-demuxer-ogg.js, ogv-worker-audio.js, etc
169
  OGVLoader.base = '/path/to/resources';
170
```
171
 
172
To fetch from npm:
173
 
174
```
175
npm install ogv
176
```
177
 
178
The distribution-ready files will appear in 'node_modules/ogv/dist'.
179
 
180
To load the player library into your browserify or webpack project:
181
 
182
```
183
var ogv = require('ogv');
184
 
185
// Access public classes either as ogv.OGVPlayer or just OGVPlayer.
186
// Your build/lint tools may be happier with ogv.OGVPlayer!
187
ogv.OGVLoader.base = '/path/to/resources';
188
var player = new ogv.OGVPlayer();
189
```
190
 
191
## Usage
192
 
193
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).
194
 
195
```
196
  // Create a new player with the constructor
197
  var player = new OGVPlayer();
198
 
199
  // Or with options
200
  var player = new OGVPlayer({
201
	debug: true,
202
	debugFilter: /demuxer/
203
  });
204
 
205
  // Now treat it just like a video or audio element
206
  containerElement.appendChild(player);
207
  player.src = 'path/to/media.ogv';
208
  player.play();
209
  player.addEventListener('ended', function() {
210
    // ta-da!
211
  });
212
```
213
 
214
To check for compatibility before creating a player, include `ogv-support.js` and use the `OGVCompat` API:
215
 
216
```
217
  if (OGVCompat.supported('OGVPlayer')) {
218
    // go load the full player from ogv.js and instantiate stuff
219
  }
220
```
221
 
222
This will check for typed arrays, web audio, blacklisted iOS versions, and super-slow/broken JIT compilers.
223
 
224
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`:
225
 
226
```
227
  var script = document.createElement('script');
228
  script.src = 'ogv.js?version=' + encodeURIComponent(OGVVersion);
229
  document.querySelector('head').appendChild(script);
230
```
231
 
232
## Distribution notes
233
 
234
Entry points:
235
* `ogv.js` contains the main runtime classes, including OGVPlayer, OGVLoader, and OGVCompat.
236
* `ogv-support.js` contains the OGVCompat class and OGVVersion symbol, useful for checking for runtime support before loading the main `ogv.js`.
237
* `ogv-version.js` contains only the OGVVersion symbol.
238
 
239
These entry points may be loaded directly from a script element, or concatenated into a larger project, or otherwise loaded as you like.
240
 
241
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.
242
 
243
Dynamically loaded assets:
244
* `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.
245
* `ogv-demuxer-ogg-wasm.js/.wasm` are used in playing .ogg, .oga, and .ogv files.
246
* `ogv-demuxer-webm-wasm.js/.wasm` are used in playing .webm files.
247
* `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.
248
* `ogv-decoder-video-theora-wasm.js/.wasm` are used in playing .ogg and .ogv video files.
249
* `ogv-decoder-video-vp8-wasm.js/.wasm` and `ogv-decoder-video-vp9-wasm.js/.wasm` are used in playing .webm video files.
250
* `*-mt.js/.wasm` are the multithreaded versions of some of the above modules. They have additional support files.
251
 
252
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.
253
 
254
 
255
## Performance
256
 
257
(This section is somewhat out of date.)
258
 
259
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.
260
 
261
WebM VP8/VP9 is slower, but works pretty well at a resolution step below Theora.
262
 
263
AV1 is slower still, and tops out around 360p for single-threaded decoding on a fast desktop or iOS device.
264
 
265
*Low-res targets*
266
 
267
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.
268
 
269
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.
270
 
271
(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.)
272
 
273
 
274
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.
275
 
276
 
1441 ariadna 277
In both cases, a native application looms as a possibly better alternative. See [OGVKit](https://github.com/bvibber/OGVKit) and [OgvRt](https://github.com/bvibber/OgvRT) projects for experiments in those directions.
1 efrain 278
 
279
 
280
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.
281
 
282
 
283
*WebGL drawing acceleration*
284
 
1441 ariadna 285
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/bvibber/yuv-canvas) package, now separately installable.
1 efrain 286
 
287
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.
288
 
289
 
290
## Difficulties
291
 
292
*Threading*
293
 
294
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.
295
 
296
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.
297
 
298
*Streaming download*
299
 
300
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.
301
 
302
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.
303
 
304
 
305
*Seeking*
306
 
307
Seeking is implemented via the HTTP Range: header.
308
 
309
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.
310
 
311
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.
312
 
313
As with chunked streaming, cross-site playback requires CORS support for the Range header.
314
 
315
 
316
*Audio output*
317
 
1441 ariadna 318
Audio output is handled through the [AudioFeeder](https://github.com/bvibber/audio-feeder) library, which encapsulates use of Web Audio API:
1 efrain 319
 
320
Firefox, Safari, Chrome, and Edge support the W3C Web Audio API.
321
 
322
IE is no longer supported; the workaround using Flash no longer works due to sunsetting of the Flash plugin.
323
 
324
A/V synchronization is performed on files with both audio and video, and seems to actually work. Yay!
325
 
326
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.
327
 
328
As of 1.1.1, muting before script-triggered playback allows things to work:
329
 
330
```
331
  player = new OGVPlayer();
332
  player.muted = true;
333
  player.src = 'path/to/file-with-audio.ogv';
334
  player.play();
335
```
336
 
337
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.
338
 
339
 
340
*WebM*
341
 
342
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.
343
 
344
Beware that performance of WebM VP8 is much slower than Ogg Theora, and VP9 is slightly slower still.
345
 
346
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.
347
 
348
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.
349
 
350
*AV1*
351
 
352
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.
353
 
354
Currently this is experimental, and does not advertise support via `canPlayType`.
355
 
356
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.
357
 
358
Currently AV1 in MP4 container is not supported.
359
 
360
## Upstream library notes
361
 
362
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.
363
 
364
The Ogg Skeleton library (libskeleton) is a bit ... unfinished and is slightly modified here.
365
 
366
libvpx is slightly modified to work around emscripten threading limitations in the VP8 decoder.
367
 
368
 
369
## WebAssembly
370
 
371
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.
372
 
373
 
374
## Multithreading
375
 
376
Experimental multithreaded VP8, VP9, and AV1 decoding up to 4 cores is in development, requiring emscripten 1.38.27 to build.
377
 
378
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.
379
 
380
Threading currently requires WebAssembly; JavaScript builds are possible but perform poorly.
381
 
382
Speedups will only be noticeable when using the "slices" or "token partitions" option for VP8 encoding, or the "tile columns" option for VP9 encoding.
383
 
384
If you are making a slim build and will not use the `threading` option, you can leave out the `*-mt.*` files.
385
 
386
 
387
## Building JS components
388
 
389
Building ogv.js is known to work on Mac OS X and Linux (tested Fedora 29 and Ubuntu 18.10 with Meson manually updated).
390
 
391
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.
392
2. Install [Emscripten](http://kripken.github.io/emscripten-site/docs/getting_started/Tutorial.html); currently building with 2.0.13.
393
3. `git submodule update --init`
394
4. Run `npm install` to install build utilities
395
5. Run `make js` to configure and build the libraries and the C wrapper
396
 
397
 
398
## Building the demo
399
 
400
If you did all the setup above, just run `make demo` or `make`. Look in build/demo/ and enjoy!
401
 
402
 
403
## License
404
 
405
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.
406
 
407
Based on build scripts from https://github.com/devongovett/ogg.js
408
 
1441 ariadna 409
See [AUTHORS.md](https://github.com/bvibber/ogv.js/blob/master/AUTHORS.md) and/or the git history for a list of contributors.