Skip to content

Commit

Permalink
Update readmes
Browse files Browse the repository at this point in the history
  • Loading branch information
thenickdude committed Jul 2, 2020
1 parent 06464ec commit 516891d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
18 changes: 16 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ browsers, check out the [Blob size limits][].
## Compatibility

Because this code relies on browser support for encoding a Canvas as a WebP image (using `toDataURL()`), it is presently
only supported in Google Chrome. It will throw an exception on other browsers.
only supported in Google Chrome, or a similar environment like Electron. It will throw an exception on other browsers or
on vanilla Node.

## Usage (Chrome)

Expand All @@ -33,7 +34,7 @@ project.
Include the script in your header:

```html
<script type="text/javascript" src="webm-writer-0.1.0.js"></script>
<script type="text/javascript" src="webm-writer-0.3.0.js"></script>
```

First construct the writer, passing in any options you want to customize:
Expand All @@ -47,6 +48,10 @@ var videoWriter = new WebMWriter({
// 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`.
});
```

Expand Down Expand Up @@ -87,6 +92,15 @@ videoWriter.complete().then(function(webMBlob) {
The video encoder can use Node.js file APIs to write the video to disk when running under Electron. There is an example
in `test/electron`. Run `npm install` in that directory to fetch required libraries, then `npm start` to launch Electron.

## Transparent WebM support

Transparent WebM files are supported, check out the example in 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.

## License

This project is licensed under the WTFPLv2 https://en.wikipedia.org/wiki/WTFPL
21 changes: 19 additions & 2 deletions src/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ When not streaming to disk, it can instead buffer the video in memory as a serie
returned to the calling code as one composite Blob. This Blob can be displayed in a &lt;video&gt; 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.

[Whammy]: https://github.com/antimatter15/whammy
[Blob size limit]: https://github.com/eligrey/FileSaver.js/

Expand All @@ -30,12 +33,17 @@ var
WebMWriter = require('webm-writer'),

videoWriter = new WebMWriter({
quality: 0.95, // WebM image quality from 0.0 (worst) to 1.0 (best)
fd: null, // Node.js file descriptor to write to instead of buffering to memory (optional)
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`.
});
```

Expand Down Expand Up @@ -65,3 +73,12 @@ videoWriter.complete().then(function(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.

0 comments on commit 516891d

Please sign in to comment.