Skip to content

siegerts/skill-canvas-video / creating-canvas-video-animations

creating-canvas-video-animations

Verified

Creates animated video content using HTML5 Canvas and JavaScript. Generates self-contained HTML files with canvas-based animations that can be previewed in a browser and exported to MP4 using Puppeteer and FFmpeg. Use when the user wants to create animated videos, motion graphics, promotional clips, tutorial animations, or any visual content rendered frame-by-frame on canvas.

FileKindSize
ARCHITECTURE.mdmarkdown2.9 KB
ELEMENTS.mdmarkdown3.3 KB
EXPORT.mdmarkdown1.4 KB
HTML-TEMPLATE.mdmarkdown2.0 KB
PLATFORMS.mdmarkdown3.7 KB
SKILL.mdskill md5.0 KB
TIMELINE.mdmarkdown1.6 KB
scripts/export.jsscript3.5 KB

scripts/export.js

View on GitHub
#!/usr/bin/env node
const puppeteer = require('puppeteer');
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

// ── ADAPT THIS BLOCK PER PROJECT ──
const FORMATS = {
    horizontal: { w: 1920, h: 1080, html: 'animation.html', duration: 30000, animClass: 'MyAnimation' },
    vertical:   { w: 1080, h: 1920, html: 'animation-vertical.html', duration: 30000, animClass: 'MyVerticalAnimation' },
};

const FORMAT = process.argv[2] || 'horizontal';
const FPS = 60;
const SCALE = 2; // 2x = 3840x2160 for 1080p source. Use 4 for max quality.

const fmt = FORMATS[FORMAT];
if (!fmt) { console.error(`Unknown format: ${FORMAT}. Use: ${Object.keys(FORMATS).join(', ')}`); process.exit(1); }

const TOTAL_FRAMES = FPS * (fmt.duration / 1000);
const OUT_W = fmt.w * SCALE, OUT_H = fmt.h * SCALE;
const FRAMES_DIR = path.join(__dirname, '..', `frames_${FORMAT}`);
const OUTPUT_FILE = path.join(__dirname, '..', `output_${FORMAT}_${SCALE}x.mp4`);

async function main() {
    if (fs.existsSync(FRAMES_DIR)) fs.rmSync(FRAMES_DIR, { recursive: true });
    fs.mkdirSync(FRAMES_DIR);

    console.log(`Exporting ${FORMAT} at ${OUT_W}x${OUT_H}, ${FPS}fps, ${fmt.duration/1000}s`);

    const browser = await puppeteer.launch({ headless: 'new', args: ['--no-sandbox'] });
    const page = await browser.newPage();
    await page.setViewport({ width: OUT_W, height: OUT_H, deviceScaleFactor: 1 });

    const htmlPath = path.join(__dirname, '..', fmt.html);
    await page.goto(`file://${htmlPath}`, { waitUntil: 'networkidle0' });
    await page.waitForFunction('window.animation && window.animation.isPlaying');
    await page.evaluate(() => window.animation.stop());

    await page.evaluate((w, h, animClass) => {
        const canvas = document.getElementById('canvas');
        canvas.width = w; canvas.height = h;
        canvas.style.width = w + 'px'; canvas.style.height = h + 'px';
        const anim = new window[animClass](canvas);
        window.exportAnim = anim;
        window.renderFrame = function(timeMs) {
            const origRAF = window.requestAnimationFrame;
            window.requestAnimationFrame = function() {};
            const a = window.exportAnim;
            a.isPlaying = true;
            a.startTime = 100000;
            a.animate(100000 + timeMs);
            a.isPlaying = false;
            window.requestAnimationFrame = origRAF;
        };
    }, OUT_W, OUT_H, fmt.animClass);

    await new Promise(r => setTimeout(r, 500));

    for (let frame = 0; frame < TOTAL_FRAMES; frame++) {
        await page.evaluate((t) => window.renderFrame(t), (frame / FPS) * 1000);
        const canvasHandle = await page.$('#canvas');
        await canvasHandle.screenshot({
            path: path.join(FRAMES_DIR, `frame_${String(frame).padStart(5, '0')}.png`),
            type: 'png'
        });
        if (frame % 60 === 0) {
            const pct = ((frame / TOTAL_FRAMES) * 100).toFixed(1);
            console.log(`  Frame ${frame}/${TOTAL_FRAMES} (${pct}%)`);
        }
    }

    await browser.close();

    console.log('Encoding MP4...');
    execSync([
        'ffmpeg', '-y',
        '-framerate', String(FPS),
        '-i', path.join(FRAMES_DIR, 'frame_%05d.png'),
        '-c:v', 'libx264', '-preset', 'slow', '-crf', '18',
        '-pix_fmt', 'yuv420p',
        OUTPUT_FILE
    ].join(' '), { stdio: 'inherit' });

    fs.rmSync(FRAMES_DIR, { recursive: true });
    console.log(`Done: ${OUTPUT_FILE}`);
}

main().catch(err => { console.error(err); process.exit(1); });
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall