Socket
Socket
Sign inDemoInstall

@pankod/canvas2video

Package Overview
Dependencies
173
Maintainers
8
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @pankod/canvas2video

canvas to video renderer


Version published
Weekly downloads
6
increased by200%
Maintainers
8
Created
Weekly downloads
 

Readme

Source
            

@pankod/canvas2video

Canvas to Video

Simplifies the way to create a video from canvas content

Maintainability Test Coverage npm version npm dependencies Status dev-dependencies Status

Created by Pankod


About

@pankod/canvas2video helps you to create videos with ease by using gsap and fabric libraries.

Getting started

To install the module, run the following in the command line:

npm install @pankod/canvas2video --save

or

yarn add @pankod/canvas2video

Usage

Library exports two different functions renderer and encoder.

Define canvas properties and create stream with makeScene function by using fabric and gsap animation library methods. You get a stream as a return which then you'll use in the encoder function which convert canvas to video output.

You can also define a background video in encoder function which will be applied to your canvas with a beautiful filter.

import { renderer, encoder } from "@pankod/canvas2video";

const helloWorld = async () => {
    const stream = await renderer({
        silent: false,
        width: 1920,
        height: 1080,
        fps: 30,
        makeScene: (fabric, canvas, anim, compose) => {
            var text = new fabric.Text("Hello world", {
                left: 400,
                top: 400,
                fontSize: 100,
                fill: "#f99339",
                angle: 0,
            });
            canvas.add(text);
            anim.to(text, {
                duration: 1,
                angle: 360,
                ease: Power3.easeOut,
            });
            compose();
        },
    });

    const output = await encoder({
        silent: false,
        frameStream: stream,
        output: "output/hello-world.mp4",
        fps: {
            input: 30,
            output: 30,
        },
    });
    console.log("process done,", output.path);
};

For more detailed usage, checkout our examples.

Examples


We've provided two examples to demonstrate how canvas2video works and what can be done. See examples

Installation
git clone https://github.com/pankod/canvas2video.git
cd examples
npm i
Hello World
npm run start:hello-world
Weather
npm run start:weather

Options

Renderer

PropertiesTypeDescription
width
*required
numberWidth of your canvas
height
*required
numberHeight of your canvas
fps
*required
numberFrames per second of your animations
makeScene
*required
functionSee below

makeScene

You can create contents by using fabric, gsap library methods which comes default with makeScene function.

This function takes 4 arguments(fabric, canvas, anim and compose) which is passed by the renderer function.

renderer({
    /* .. */
    makeScene: (fabric, canvas, anim, compose) => {
        /**
         * your code to create and manipulate your canvas
         */
    },
});
ParameterType
fabricfabric.js instanceRepo
canvasfabric.StaticCanvasRepo
animgsap.TimelineMaxRepo
compose() => void

Encoder

PropertiesTypeDescription
frameStream
*required
ReadableOutput of your renderer call
output
*required
stringYour output file path
fps
*required
Object{ input: number, output: number }
backgroundVideoObjectSee below

backgroundVideo
backgroundVideo: {
  videoPath: string, // your background video path
  inSeconds: number, // video start time in seconds
  outSeconds: number, // video end time in seconds
}

License

License

Keywords

FAQs

Last updated on 29 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc