npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yuv-canvas

v1.3.0

Published

Utility for drawing YUV image data to HTML5 canvas

Downloads

7,949

Readme

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-2024 by Brooke Vibber [email protected] MIT license, see the source files:

  • Source: https://github.com/bvibber/yuv-canvas
  • Issues: https://github.com/bvibber/yuv-canvas/issues

Updates

1.3.0 - 2024-10-03

  • build cleanup
  • doc/name/links cleanup

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).

License

MIT-style license:

Copyright (c) 2014-2024 Brooke Vibber [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.