siegerts/skill-canvas-video / creating-canvas-video-animations
creating-canvas-video-animations
VerifiedCreates 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.
| File | Kind | Size |
|---|---|---|
| ARCHITECTURE.md | markdown | 2.9 KB |
| ELEMENTS.md | markdown | 3.3 KB |
| EXPORT.md | markdown | 1.4 KB |
| HTML-TEMPLATE.md | markdown | 2.0 KB |
| PLATFORMS.md | markdown | 3.7 KB |
| SKILL.md | skill md | 5.0 KB |
| TIMELINE.md | markdown | 1.6 KB |
| scripts/export.js | script | 3.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); });Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| 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: 194k | Updated | Claude CodeCodex | Verified | Install |