thenickdude / webm-writer-js

JavaScript-based WebM video encoder for Google Chrome
272 stars 43 forks source link

How to use WebMWriter with Node.js? I get "Couldn't decode WebP frame, does the browser support WebP?" #15

Closed ProgrammingLife closed 4 years ago

ProgrammingLife commented 4 years ago

I try to use WebmWriter like this:

const { createCanvas, loadImage } = require("canvas");
const CANVAS_WIDTH = 1920;
const CANVAS_HEIGHT = 1080;
const canvas = createCanvas(CANVAS_WIDTH, CANVAS_HEIGHT);
const context = canvas.getContext("2d");

const videoWriter = new webmWriter({
    quality: 0.9999,
    fileWriter: null,
    fd: null,
    frameRate: 30, 
});
for (let i = 0; i < 30 * 5; i++) {
    videoWriter.addFrame(canvas);
}
videoWriter.complete();

But unfortunately I have no luck because evertime I get "Couldn't decode WebP frame, does the browser support WebP?". How to use it with Node.js?

thenickdude commented 4 years ago

It's only supported under Electron, not vanilla Node, since Electron provides the required support for canvas.toDataURL('image/webp') by way of its Chrome engine.

https://github.com/Automattic/node-canvas doesn't have webp support built-in, although it may be available from other sources.