• Stars
    star
    271
  • Rank 151,717 (Top 3 %)
  • Language
    JavaScript
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JS class to draw YUV image frame buffers to an HTML5 canvas

YUVCanvas draws YUV video frames to an HTML 5 canvas element.

It is used in the ogv.js media player and is suitable for high-frequency frame updates using WebGL for drawing and colorspace conversion.

Copyright

Copyright 2014-2022 by Brion Vibber [email protected] MIT license, see the source files:

Updates

1.2.11 - 2022-03-04

  • perf: further improvements to speed in Safari / macOS using alpha instead of luminance textures
  • update shaders from low to medium precision, may fix pixel precision errors on some GPUs

1.2.10 - 2022-03-04

  • perf: fixed over-eager use of texImage2d on non-stripe frame updates
  • turning off stripe mode as default due to a compatibility problem with Netscape on macOS that is not resolved

1.2.9 - 2022-01-27

  • re-enabled "stripe" hack, but now by default everywhere. Turns out it makes a huge difference on macOS with some AMD GPUs too!

1.2.8 - 2022-01-11

  • disabled "stripe" texture hack for Windows by default; uses deprecated userAgent, and makes little difference in 2022 vs 2014

1.2.7 - 2021-05-26

  • applied contributed patch updating texture state when frame size changes
  • added dev dep for running demo on http-server

1.2.6 - 2019-05-27

  • added an extra WebGL option to preserve back buffer, fixes canvas video capture in Firefox

1.2.5 - 2019-05-27

  • remove some extra WebGL options that just slowed things down and could cause flicker in Safari during canvas video capture

1.2.4 - 2019-02-06

  • fix software rendering path for crop offsets (Theora)

1.2.3 - 2019-02-04

  • optimize software rendering path by a few percent

1.2.2 - 2019-02-04

  • don't use WebGL when software rendering is in use (failIfMajorPerformanceCaveat)
  • fix use of preferLowPowerToHighPerformance for preferring integrated GPU

1.2.1 - 2018-01-18

  • fix regression breaking iOS 9

1.2.0 - 2017-10-27

  • optimized Windows rendering (restored "stripe" more cleanly)
  • retooled rendering order to minimize CPU/GPU sync points

1.1.0 - 2017-10-27

  • improved scaling/filtering on Windows (dropped "stripe" optimization)

1.0.1 - 2017-02-17

  • fix flickering in Safari with software rendering

1.0.0 - 2016-09-11

  • Initial break-out release from ogv.js

Data format

Planar YUV frames are packed into objects per the yuv-buffer format. Frame buffer objects can be safely copied or transferred between worker threads, and can be either garbage collected or reused for another frame after output.

Each frame buffer includes the frame's size, a crop rectangle, a display aspect ratio, and chroma subsampling format as well as the raw bytes.

WebGL drawing acceleration

Accelerated YCbCr->RGB conversion and drawing is done using WebGL on supporting browsers (Firefox, Chrome, IE 11, Edge, and Safari for iOS 8 & OS X 10.9), and is enabled by default if available.

Caller can pass the 'webGL: false' key to options to force use of the software conversion and 2d canvas, or 'webGL: true' to force a failure if WebGL initialization fails.

Windows vs luminance textures

The Y, U and V planes are uploaded as luminance textures, then combined into RGB output by a shader.

Early versions of IE 11 do not support luminance or alpha textures at all, and in IE 11 update 1 and Edge uploading is unexpectedly slow. In fact, luminance and alpha textures seem consistently slow on Windows even in Chrome and Firefox, possibly due to a mismatch in interfaces between WebGL and Direct3D.

I've found as of 2022 this also affects some Mac systems with AMD GPUs, so a workaround is now enabled for all systems by default.

The textures are uploaded as packed RGBA textures, then unpacked to luminance textures on the GPU. This has a small runtime cost, but seems less than the cost of letting the ANGLE or other driver layer in the browser swizzle.

Usage

yuv-canvas is intended to be used via browserify, webpack, or similar npm-friendly bundling tool.

var YUVCanvas = require('yuv-canvas');

// Get your canvas
var canvas = document.querySelector('canvas#myvid');

// Attach it to a YUVCanvas.FrameSink instance!
//
// This will take over the canvas drawing context, which may include switching
// it into WebGL mode or resizing it to fit the output frames. From now on you
// can manipulate the canvas element itself such as attaching it in the DOM or
// changing its CSS styles, but should not attempt to touch its size or drawing
// context directly.
var yuv = YUVCanvas.attach(canvas);

// Now... given a YUV frame buffer object, draw it!
var buffer = decodeVideoFrame();
yuv.drawFrame(buffer);

// Or clear the canvas.
yuv.clear();

Demo

The included demo combines Y, U, and V planes from grayscale JPEGs into a color photograph on a canvas. Check it out!

Building

Run npm install (or grunt to rebuild if necessary) to build derived files in a local source checkout.

Derived files are the array of WebGL shaders (build/shaders.js) and the bundled JS for the demo (docs/demo-bundled.js).

More Repositories

1

ogv.js

JavaScript media player using Ogg/Vorbis/Theora/Opus/WebM libs compiled with Emscripten
JavaScript
1,197
star
2

OGVKit

Ogg and WebM media playback for iOS
Objective-C
216
star
3

mtpng

A parallelized PNG encoder in Rust
Rust
206
star
4

hdrfix

tool for converting HDR screenshots to SDR with suitable tone-mapping
Rust
114
star
5

audio-feeder

Small JS library to abstract Web Audio raw PCM output
JavaScript
53
star
6

yuv-buffer

YUV image frame buffer helper utilities for JavaScript
JavaScript
38
star
7

wasm2swf

Experimental WebAssembly to ActionScript bytecode translator
JavaScript
19
star
8

gimp-icns

Gimp image editor plugin to load and save Mac OS X .icns icon resource files
C
18
star
9

stream-file

Small JS library to abstract streaming of large files via XHR w/ Range-based chunking
JavaScript
18
star
10

jsdec-openh264

Experimental OpenH264 emscripten build for Gecko experimental JavaScript video decoding API
C++
15
star
11

StatusNet

alternate copy of StatusNet repo from our Gitorious master
PHP
14
star
12

librsvg

Test fork of librsvg from git.gnome.org
C
12
star
13

aotjs

Experimental ahead-of-time JavaScript compiler targetting WebAssembly and native
C++
12
star
14

min-wasm-fail

Minimal test case for iOS 11.2.2/11.2.5 wasm failure
JavaScript
10
star
15

BugTender

mobile web app to manage Bugzilla from your phone
JavaScript
10
star
16

av1-demo

av1 encoding demo using svt-av1
JavaScript
9
star
17

chromium-win-arm64

Experimental dev builds of Chromium for Windows 10 ARM64
8
star
18

raw-to-mse

Experimental library for producing MSE-compatible buffers with uncompressed audio/video data
JavaScript
7
star
19

wasmosis

capability-passing "microkernel" for safely isolating WebAssembly modules
C
6
star
20

MediaWiki

PHP
6
star
21

svg-edit-test

SVG-Edit test tool comparing round-tripping of data files
JavaScript
6
star
22

emsdk-npm

emscripten SDK helper module for npm projects
JavaScript
5
star
23

statusnet-client

StatusNet Desktop and Mobile clients (mirror from Gitorious)
JavaScript
5
star
24

jpegxr

Rust wrapper for Microsoft's C JPEG XR codec library
C
4
star
25

mw-js-plugin

Experimental repo for MediaWiki JavaScript iframe-based plugin system
JavaScript
4
star
26

aomedia

work fork of aomedia - see http://aomedia.org/contributor-guide/
C
3
star
27

brot

Mandelbrot WebWorkers test
JavaScript
3
star
28

MediaWiki-MobileSidebar

mobile sidebar gadget
JavaScript
3
star
29

OEmbedConsumer

PHP
3
star
30

mediawiki-svn

A mirror of MediaWiki's Subversion repository produced with git-svn(1)
PHP
3
star
31

WLMTest

Development moved to https://github.com/wikimedia/WLMMobile
JavaScript
2
star
32

MediaWiki-ExtensionFetcher

Extension for MediaWiki to manage fetching extensions from git
PHP
2
star
33

WebM-iOS

iOS builds of libwebm
Ruby
2
star
34

density-bookmarklet

Experimental bookmarklet to swap PNG and SVG images to high-res on wikipedia
JavaScript
2
star
35

FlatRoller

HTML canvas game demo/tutorial/exploration
JavaScript
2
star
36

WebViewTest

quick Android webview test to see if text selection works
Java
2
star
37

ohgeevee

VR experiments with ogv.js and A-Frame
HTML
2
star
38

VPX-iOS

Local builds of libvpx for iOS
Makefile
2
star
39

CommonsMetro

Wikimedia Commons app for Windows 8/Windows RT
JavaScript
2
star
40

OEmbedProvider

PHP
2
star
41

cortado

mirror of old xiph cortado, for fun
Java
2
star
42

OgvRT

Experimental Ogg Theora/Vorbis player for WinRT (Windows 8.1 including RT and Phone)
C++
2
star
43

OGVKit-Specs

temp location of dependent CocoaPods specs for OGVKit
Ruby
2
star
44

EmbedScript

MediaWiki extension for safe embedding of locally-hosted scripts
PHP
2
star
45

WikipediaMetroTest

testbed for windows 8 metro integration features
JavaScript
1
star
46

orwel

OpenRaster Web Editing Library
JavaScript
1
star
47

EmbedTurtle

turtle graphics embedding test demo
JavaScript
1
star
48

turtle-world

Logo interpreter and turtle graphics environment for the web
JavaScript
1
star
49

MobileFrontend

MobileFrontend extension copy
PHP
1
star
50

gnome-system-monitor

Forked from master repo at http://git.gnome.org/browse/gnome-system-monitor/
C++
1
star
51

svg-test

SVG rendering test framework
JavaScript
1
star
52

EmbedPiechart

Experimental EmbedSandbox provider for drawing & editing pie charts
JavaScript
1
star
53

EmbedScriptSandbox

Sandbox page for MediaWiki EmbedScript extension
1
star
54

OLD-apps-win8-wikipedia

Wikipedia reader app for Windows 8/RT
JavaScript
1
star
55

CentralAuthAPI

MediaWiki API proxy for CentralAuth-connected wikis
PHP
1
star
56

test-emscripten-lib

C
1
star
57

WikipediaFrameTest

test of phonegap iframe issue on iOS
JavaScript
1
star
58

gnome-emscripten

Experiments at building GNOME low-level libraries for emscripten
C
1
star
59

EmbedSandbox

experimental MediaWiki extension for embedding remote scriptable objects safely
PHP
1
star
60

mozilla-SN---Plugin

Plugin for mozilla SN
PHP
1
star
61

operations-debs-ffmpeg2theorawmf

C
1
star
62

mandelbrot-shootout

Fractal programming language test demos
C
1
star
63

ffmpeg2theora

work fork of ffmpeg2theora
C
1
star
64

iframe-android-test

JavaScript
1
star
65

drive256

Drive256 - a VGA loadable driver experiment from 1992
Pascal
1
star
66

Vaders

HTML5 version of old DOS game
JavaScript
1
star
67

browser-transcode-test

Notes and experiments for browser-based transcoding of audio and video
HTML
1
star