Expertly and easily export GreenSock (GSAP) animation to video.

Overview

gsap-video-export

Expertly and easily export GreenSock (GSAP) animation to video.

gsap-video-export is a simple tool for exporting your GreenSock (GSAP) animations to video. Create video animations with the framework you know and love and use them in your video projects or share them on social media with ease.

What makes gsap-video-export different from other solutions is rather than simply recording an animation as it plays, it instead steps through exporting frame by frame to ensure the result is seamless.

Support this project
Help support the work that goes into creating and maintaining my projects and buy me a coffee via Ko-fi or sponsor me on GitHub Sponsors.

Contents

Getting Started

Installation

gsap-video-export is a command line tool that can be installed directly via NPM.

npm install -g gsap-video-export

Usage

Once installed the tool can be used as per the following example.

gsap-video-export <url>

When using CodePen URLs gsap-video-export will automatically redirect to the full page debug preview.

Options

Options:
      --help            Show help                                                                    [boolean]
      --version         Show version number                                                          [boolean]
  -s, --script          [browser] Custom script                                                       [string]
  -S, --selector        [browser] DOM selector                                  [string] [default: "document"]
  -t, --timeline        [browser] GSAP timeline object                              [string] [default: "gsap"]
  -z, --scale           [browser] Scale factor                                           [number] [default: 1]
  -V, --viewport        [browser] Viewport size                                [string] [default: "1920x1080"]
  -i, --info            [browser] Info only
      --frame-start     [browser] Start frame
      --frame-end       [browser] End frame
  -p, --color           [video] Auto padding color                                  [string] [default: "auto"]
  -c, --codec           [video] Codec                                            [string] [default: "libx264"]
  -e, --input-options   [video] FFmpeg input options                                                  [string]
  -E, --output-options  [video] FFmpeg output options         [string] [default: ""-pix_fmt yuv420p -crf 18""]
  -o, --output          [video] Filename                                       [string] [default: "video.mp4"]
  -f, --fps             [video] Framerate                                               [number] [default: 60]
  -v, --resolution      [video] Output resolution                                   [string] [default: "auto"]

Examples

A huge thanks to @cassiecodes for letting me use her incredible GreenSock pens to demonstrate gsap-video-export.

Page Export

Supplying gsap-video-export with a URL will generate a 1920x1080 video file of the viewport, scrubbing through the GSAP global timeline object at 60fps.

# Animation by @cassiecodes
gsap-video-export https://codepen.io/cassie-codes/pen/RwGEewq
RwGEewq.mp4

Custom Timeline

By default gsap-video-export will scrub through the global GSAP timeline object, although there may be instances where you want to specify which timeline you want to record.

In the example below the global timeline fails due an infinite loop.

# Animation by @SeeMax
gsap-video-export https://codepen.io/SeeMax/pen/bGoxMwj

Using the --timeline -t argument you can specify a different timeline variable to use instead.

# Animation by @SeeMax
gsap-video-export https://codepen.io/SeeMax/pen/bGoxMwj -t tl
bGoxMwj.mp4

Export Element

With the --selector -S argument you can specifiy a DOM selector to capture a specific element. The resulting output video will be the same dimensions as the as the selected element.

gsap-video-export also allows you to run custom JavaScript on the page before the video capture begins with the --script -s argument. In this example a custom.js file is supplied with a snippet to remove the corner banner from the DOM.

// custom.js
document.querySelector('img[alt="HTML5"]').remove()
# Animation by GreenSock
gsap-video-export https://codepen.io/GreenSock/pen/DzXpme -S "#featureBox" -s custom.js 
DzXpme.mp4

Twitter Export

In this example if you visit the pen you might notice the animation is offscreen. This isn't an issue as gsap-video-export will automatically scroll the selected element into the viewport.

It's possible to easily export videos for social media such as Twitter. Using the default settings gsap-video-export will automatically output video in a format that conforms to Twitter's video specifications.

To render your video at the desired resolution use the --resolution -v argument with a <width>x<height> string. For Twitter I recommend using 1080x1080.

# Video by @cassiecodes
https://codepen.io/cassie-codes/pen/mNWxpL -S svg -v 1080x1080

The example above will select the SVG element on the page, with the resulting video resized and automatically padded to 1080x1080.

As the SVG element itself is not 1080 pixels in either direction it will ultimately be scaled up to hit the target resolution losing quality.

Using the --scale -z you can supply a scale factor allowing you to capture the element at a much higher resolution resulting in better video quality.

# Video by @cassiecodes
https://codepen.io/cassie-codes/pen/mNWxpL -S svg -v 1080x1080 -z 2
mNWxpL.mp4

Coloured Background

gsap-video-export will automatically detect the background colour to autopad the animation with.

It uses the first pixel of the first frame to determine colour of the background. You can override this with --color -p and supply a custom hex value.

# Video by @cassiecodes
https://codepen.io/cassie-codes/pen/VwZBjRq -S svg -z 2 -v 1080x1080
VwZBjRq.mp4

Lossless* Export

*When creating a video with the true lossless setting -crf 0 it will preserve the colour space of the source PNGs and won't be compatible with some media players.

For compatibility simply setting the best lossy setting -crf 1 is enough to create a near lossless video that's compatible with most media players.

The --output-options -E argument will take a double quoted string of FFmpeg output arguments to allow a lot of flexability over the final render.

# Video by @cassiecodes
gsap-video-export https://codepen.io/cassie-codes/pen/VweQjBw -S svg -z 2 -v 1920x1080 -E '"-pix_fmt yuv420p -crf 1"'
VweQjBw.mp4

FAQ

Why does my video fail with the duration error INFINITE?

This can happen on some videos where the selected timeline infinitely repeats and GSAP reports a duration in the thousands of hours.

gsap-video-export will not attempt to capture any video over an hour and will report the INFINITE error.

How can I disable other on screen elements?

You can supply a custom .js file with the --script argument which runs before the capture begins giving you the ability to manipulate the DOM.

Why does my video not render as expected?

gsap-video-export works by stepping manually through the specified timeline exporting each individual frame. As a rule of thumb if you can scrub through your timeline manually you're not going to have any issues.

If you're triggering animations that are not locked to the timeline then this might not be the right tool for the job.

Why does my timeline fail?

gsap-video-export can access block scoped let and const variables and variables on the global scope. If your timeline variable is not exposed at that level then gsap-video-export will not be able to access it.

Consider moving your timeline to a scope the tool can access.

Sponsors

If you find this project useful please considering sponsoring me on GitHub Sponsors and help support the work that goes into creating and maintaining my projects.

Bonus

Sponsors are able to remove the project support message from all my CLI projects, as well as access other additional perks.

Author

Chris Johnson - defaced.dev - @defaced

You might also like...

Flexible and easy Dash/HLS/DRM integration for HTML5 video.

Flexible and easy Dash/HLS/DRM integration for HTML5 video.

This project is made possible with Plyr, Hls.js, Dash.js. Features ๐Ÿ“‘ HLS and DASH playback ๐ŸŽฅ Multi quality supported ๐ŸŽฌ Drm with custom header suppo

Nov 11, 2022

A high-performance, interactive and customizable video player control, built upon Reanimated v2 & GestureHandler v2

A high-performance, interactive and customizable video player control, built upon Reanimated v2 & GestureHandler v2

`JSThread` to `JSThread`, `UIThread` to `UIThread`. React Native Reanimated Expo Player 100% written in Typescript video player component, interaction

Jan 4, 2023

Self hosted media tracker for movies, tv shows, video games, books and audiobooks

MediaTracker ยท Self hosted platform for tracking movies, tv shows, video games, books and audiobooks, highly inspired by flox Demo https://mediatracke

Jan 3, 2023

Rebuilding TikTok with api.video, PWA, Next.js and Typescript ๐ŸŽต

Rebuilding TikTok with api.video, PWA, Next.js and Typescript ๐ŸŽต

Rebuilding TikTok with api.video, PWA, Next.js and Typescript ๐ŸŽต An open-source example application that allows users to list and upload videos in the

Jul 1, 2022

Resurrection of mediagroup / MediaController (renamed) which can be used to sync and control multiple audio / video elements.

media-group (examples) Resurrection of the mediagroup attribute and MediaController API (but renamed) which can be used to sync and control multiple a

Dec 15, 2022

Resurrection of mediagroup / MediaController (renamed) which can be used to sync and control multiple audio / video elements.

media-group (examples) Resurrection of the mediagroup attribute and MediaController API (but renamed) which can be used to sync and control multiple a

Aug 2, 2022

Image, Presentation and Video editor. Canva clone

Image, Presentation and Video editor. Canva clone

React editor [WIP] React editor for graphics, presentations and videos. It should be an alternative to canva.com. Try demo here react-editor-core.verc

Dec 28, 2022

Free Anime Streaming Website Made with PHP and Gogoanime API. No Video ads

Free Anime Streaming Website Made with PHP and Gogoanime API. No Video ads

AniKatsu - Watch High Quality Anime Online Without Ads Demo https://anikatsu.ga This is a PHP application used for browsing, searching and watching an

Nov 7, 2022

A browser extension to skip intro, recap and ads on video streaming plaforms

A browser extension to skip intro, recap and ads on video streaming plaforms

AIO Skipper AIO skipper is a browser extension made for ๐ŸŽฅ binge watchers ๐Ÿ“บ . It automatically skip intro, recaps and ads in Netflix, Prime Video, Di

Nov 2, 2022
Comments
  • Private Pen?

    Private Pen?

    Hey, First I want to say that this is an awesome idea and a super handy tool ๐Ÿ˜

    I just tried it with a private CodePen but it keeps failing. The same pen saved as public works fine. Would it be possible to make it work with private pens as well?

    Thanks ๐Ÿ™

    opened by AntoineW 3
  • Export custom timeline not codepen

    Export custom timeline not codepen

    Hello Hello ๐Ÿ‘‹ I came across this awesome project through the Amazing Pete Barr feed, is there a way to export from a JS file that has already the timeline not from codepen? i mean i have a JS file that has the timeline and want to add a button to export it from the same file.

    Not really an issue, just a question :)

    Have a great day A

    opened by ahmed-adly-khalil 1
Releases(1.0.3)
Owner
Chris Johnson
Chris Johnson
A Chrome extension to help you inspect Mp4 video content and find irregularities in video streams.

MP4Inspector A Chrome extension to help you inspect Mp4 video content and find irregularities in video streams. Installation In chrome navigate to chr

Bitmovin 48 Nov 28, 2022
Video.js - open source HTML5 & Flash video player

Video.js - HTML5 Video Player Video.js is a web video player built from the ground up for an HTML5 world. It supports HTML5 video and Media Source Ext

Video.js 34.8k Jan 5, 2023
HTML5

One file. Any browser. Same UI. Author: John Dyer http://j.hn/ Website: http://mediaelementjs.com/ License: MIT Meaning: Use everywhere, keep copyrigh

MediaElement.js 8k Dec 27, 2022
HTML5

One file. Any browser. Same UI. Author: John Dyer http://j.hn/ Website: http://mediaelementjs.com/ License: MIT Meaning: Use everywhere, keep copyrigh

MediaElement.js 8k Jan 8, 2023
This is a simple web based media player for playing video and audio. Build with pure HTML, CSS and Javascript. No framework or library included.

Aim-Player This is a simple web based media player for playing video and audio. Build with pure HTML, CSS and Javascript. No framework or library incl

Aim Mikel 2 Jun 27, 2021
Enables

HTML5 video made easy All it takes is a single line of code to make HTML5 video and audio tags work in all major browsers. How to enable video and aud

Dave Hall 1.3k Dec 17, 2022
This is a YouTube Video Planner app built with NextJS, GraphQL, Prisma and MongoDB for the MongoDB Atlas Hackathon

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Justin Chau 2 Jan 14, 2022
A tool to download all videos and convert to mp3 inside a video set of bilibili.

bilibili-video2mp3 A tool to download all videos and convert to mp3 inside a video set of bilibili (also works for single video, of course). You will

wxsm 23 Dec 15, 2022
Library to calculate a Mean Opinion Score (MOS) from 1 to 5 for audio and video real time communications

RTC SCORE Library to calculate a Mean Opinion Score (MOS) from 1 to 5 for audio and video real time communications. The first version of the algorithm

Gustavo Garcia 25 Nov 27, 2022
Secretly record audio and video with chromium based browsers

snoop TCC restricts access to the device camera and microphone to protect user data from unauthorized access. But... If you trusted your browser with

BreakPoint Technologies 10 Aug 30, 2022