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

webm-writer

v1.0.0

Published

Render WebM videos from Canvas frames

Downloads

3,168

Readme

WebM Writer for Electron

This is a WebM video encoder based on the ideas from Whammy. It allows you to turn a series of Canvas frames into a WebM video.

This implementation allows you to create very large video files (exceeding the size of available memory), because it can stream chunks immediately to a file on disk while the video is being constructed, instead of needing to buffer the entire video in memory before saving can begin. Video sizes in excess of 4GB can be written. The implementation currently tops out at 32GB, but this could be extended.

When not streaming to disk, it can instead buffer the video in memory as a series of Blobs which are eventually returned to the calling code as one composite Blob. This Blob can be displayed in a <video> element, transmitted to a server, or used for some other purpose. Note that Chrome has a Blob size limit of 500MB.

Because this library relies on Chrome's WebP encoder to do the hard work for it, it can only run in a Chrome environment (e.g. Chrome, Chromium, Electron), it can't run on vanilla Node.

Usage

Add webm-writer to your project:

npm install --save webm-writer

Require and construct the writer, passing in any options you want to customize:

var 
    WebMWriter = require('webm-writer'),
    
    videoWriter = new WebMWriter({
        quality: 0.95,    // WebM image quality from 0.0 (worst) to 0.99999 (best), 1.00 (VP8L lossless) is not supported
        fileWriter: null, // FileWriter in order to stream to a file instead of buffering to memory (optional)
        fd: null,         // Node.js file handle to write to instead of buffering to memory (optional)
    
        // You must supply one of:
        frameDuration: null, // Duration of frames in milliseconds
        frameRate: null,     // Number of frames per second
    
        transparent: false,      // True if an alpha channel should be included in the video
        alphaQuality: undefined, // Allows you to set the quality level of the alpha channel separately.
                                 // If not specified this defaults to the same value as `quality`.
    });

Add as many Canvas frames as you like to build your video:

videoWriter.addFrame(canvas);

When you're done, you must call complete() to finish writing the video:

videoWriter.complete();

complete() returns a Promise which resolves when writing is completed.

If you didn't supply a fd in the options, the Promise will resolve to Blob which represents the video. You could display this blob in an HTML5 <video> tag:

videoWriter.complete().then(function(webMBlob) {
    $("video").attr("src", URL.createObjectURL(webMBlob));
});

There's an example which saves the video to an open file descriptor instead of to a Blob on this page:

https://github.com/thenickdude/webm-writer-js/tree/master/test/electron

Transparent WebM support

Transparent WebM files are supported, check out the example in https://github.com/thenickdude/webm-writer-js/tree/master/test/transparent. However, because I'm re-using Chrome's WebP encoder to create the alpha channel, and the alpha channel is taken from the Y channel of a YUV-encoded WebP frame, and Y values are clamped by Chrome to be in the range 22-240 instead of the full 0-255 range, the encoded video can neither be fully opaque or fully transparent :(.

Sorry, I wasn't able to find a workaround to get that to work.