Jump to content

Search In
  • More options...
Find results that contain...
Find results in...

Video generation using Fabric js ,gsap and Ffmpeg

Recommended Posts

const renderer: Renderer = (config) =>
    new Promise((resolve, reject) => {
        try {
            const { width, height, fps, makeScene, silent = true } = config;
            const canvas = new fabric.StaticCanvas(null, { width, height });

            const anim = new TimelineMax({ paused: true });
            const stream = new Readable();
            typeCheck(reject, config);
            let totalFrames: number;
            let currentFrame = 0;
            const renderFrames = () => {
                anim.progress(currentFrame++ / totalFrames);
                if (currentFrame <= totalFrames) {
                    const buffer = Buffer.from(
                        canvas.toDataURL().replace(/^data:\w+\/\w+;base64,/, ""),
                } else {

            makeScene(fabric, canvas, anim, () => {
                const duration =  anim.duration();
                totalFrames = Math.max(1, Math.ceil((duration / 1) * fps));
        } catch (e) {
            reject(new Error("An error occured in the renderer."));
import { renderer, encoder } from "@pankod/canvas2video";
import { Power3 } from "gsap";

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

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


Hey guys try to create a small package using gsap and Fabric js  which can create dynamic video from canvas on the server side.

package is inspired by click here . TimelineMax is used for creating a time frame for all transition, i want to give dynamic delay for the animation of fabric js component, but the problem is ``delay , pause , resume functions of timelinemax are aren't working, the delay properties are in consistence.

i have tried using e.g:- 


in above cases delay was greater than 2 seconds

please help.

Link to post
Share on other sites


There's quite a lot to parse here so bear with me!

First things first: You're using an older version of GSAP. We definitely recommend that you use GSAP 3.

Secondly, what is the expected behaviour of the delays and what is happening for you? Could you break down the GreenSock part for me a little?

  • Like 1
Link to post
Share on other sites



Delay shouldn't be a string, it should be a number. Also the reason why the position parameter is not working is kind of a mystery, based on this it should work:




That is a timeline instance, perhaps something in that package is not working properly.


I'd recommend you to try the delay with a number and create an issue in order to get the position parameter to work in the canvas2video repo.


Happy Tweening!!!

  • Like 2
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.