Generate video files from
<canvas>
animations in Node.js
npm install --save pellicola
This package provides a lightweight framework for generating animations with node-canvas
and saving them as video files using ffmpeg
.
const pellicola = require('pellicola')
function myAnimation () {
// provide a function to draw video frames
return function ({ context, width, height, playhead }) {
context.fillStyle = '#0f0'
context.fillRect(0, 0, width * playhead, height)
}
}
const settings = {
dimensions: [640, 360], // video will be 640px wide by 360px tall
duration: 2, // video will last 2 seconds
filename: 'my-sketch.mp4' // set custom filename for output video
}
pellicola(myAnimation, settings)
.then(path => console.log('Done saving video file to:', path))
// => Done saving video file to: /path/to/current-dir/my-sketch.mp4
Conceptually, pellicola
uses the idea of the “sketch” that can be found in Processing and its Javascript cousin p5.js. The API tries to follow Matt DesLauriers’s canvas-sketch
framework, which provides excellent tools for working on generative art with <canvas>
in the web browser. The aim is to permit a sketch function developed using canvas-sketch
to be re-used with pellicola
with minimal adaptation.
For more details, see the Documentation →
pellicola
is distributed under the GNU General Public License v3.0.