ffmpeg-webassembly-workers
Complete browser-based FFmpeg system. PROACTIVELY activate for: (1) ffmpeg.wasm setup and loading, (2) Browser video transcoding, (3) React/Vue/Next.js integration, (4) SharedArrayBuffer and COOP/COEP headers, (5) Multi-threaded ffmpeg-core-mt, (6) Cloudflare Workers limitations, (7) Custom ffmpeg.wasm builds, (8) Memory management and cleanup, (9) Progress tracking and UI, (10) IndexedDB core caching. Provides: Framework-specific examples, header configuration, common operation recipes, performance optimization, troubleshooting guides. Ensures: Client-side video processing without server dependencies.
What this skill does
## CRITICAL GUIDELINES ### Windows File Path Requirements **MANDATORY: Always Use Backslashes on Windows for File Paths** When using Edit or Write tools on Windows, you MUST use backslashes (`\`) in file paths, NOT forward slashes (`/`). --- ## Quick Reference | Package | Size | Threading | Install | |---------|------|-----------|---------| | `@ffmpeg/core` | ~31MB | Single | `npm install @ffmpeg/ffmpeg @ffmpeg/util` | | `@ffmpeg/core-mt` | ~31MB | Multi | Requires COOP/COEP headers | | Header | Value | Purpose | |--------|-------|---------| | Cross-Origin-Embedder-Policy | `require-corp` | SharedArrayBuffer | | Cross-Origin-Opener-Policy | `same-origin` | Multi-threading | | Operation | Command | |-----------|---------| | Convert WebM→MP4 | `await ffmpeg.exec(['-i', 'input.webm', 'output.mp4'])` | | Extract frame | `await ffmpeg.exec(['-i', 'video.mp4', '-ss', '5', '-vframes', '1', 'thumb.jpg'])` | ## When to Use This Skill Use for **browser-based video processing**: - Client-side transcoding without server - React/Vue/Next.js FFmpeg integration - Setting up COOP/COEP headers - Cloudflare Workers FFmpeg limitations - Memory management and cleanup --- # FFmpeg WebAssembly & Cloudflare Workers (2025) Guide to running FFmpeg in browsers and edge environments using WebAssembly. ## ffmpeg.wasm Overview **ffmpeg.wasm** is a pure WebAssembly/JavaScript port of FFmpeg that runs directly in browsers without server-side processing. ### Key Features - **Browser-based**: No server required for video processing - **Cross-platform**: Works on any modern browser - **Single-thread**: @ffmpeg/core (~31MB) - **Multi-thread**: @ffmpeg/core-mt (requires SharedArrayBuffer) - **Customizable**: Build your own core with specific codecs ### Limitations - **Performance**: ~10-100x slower than native FFmpeg - **Memory**: Limited by browser memory constraints - **File size**: Core is ~31MB (can be reduced with custom builds) - **Threading**: Multi-thread requires specific headers (COOP/COEP) - **Codecs**: Not all codecs available (licensing restrictions) ## Installation ### npm ```bash npm install @ffmpeg/ffmpeg @ffmpeg/util ``` ### CDN ```html <script src="https://cdn.jsdelivr.net/npm/@ffmpeg/[email protected]/dist/umd/ffmpeg.min.js"></script> ``` ## Basic Usage ### Single-Thread (Browser) ```javascript import { FFmpeg } from '@ffmpeg/ffmpeg'; import { fetchFile, toBlobURL } from '@ffmpeg/util'; const ffmpeg = new FFmpeg(); // Load FFmpeg core const baseURL = 'https://cdn.jsdelivr.net/npm/@ffmpeg/[email protected]/dist/umd'; await ffmpeg.load({ coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, 'text/javascript'), wasmURL: await toBlobURL(`${baseURL}/ffmpeg-core.wasm`, 'application/wasm'), }); // Transcode video await ffmpeg.writeFile('input.webm', await fetchFile(videoFile)); await ffmpeg.exec(['-i', 'input.webm', 'output.mp4']); const data = await ffmpeg.readFile('output.mp4'); // Create blob URL for playback const videoURL = URL.createObjectURL( new Blob([data.buffer], { type: 'video/mp4' }) ); ``` ### Multi-Thread (Requires COOP/COEP Headers) ```javascript import { FFmpeg } from '@ffmpeg/ffmpeg'; import { fetchFile, toBlobURL } from '@ffmpeg/util'; const ffmpeg = new FFmpeg(); // Load multi-threaded core const baseURL = 'https://cdn.jsdelivr.net/npm/@ffmpeg/[email protected]/dist/umd'; await ffmpeg.load({ coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, 'text/javascript'), wasmURL: await toBlobURL(`${baseURL}/ffmpeg-core.wasm`, 'application/wasm'), workerURL: await toBlobURL(`${baseURL}/ffmpeg-core.worker.js`, 'text/javascript'), }); // Use multi-threaded encoding await ffmpeg.exec(['-i', 'input.webm', '-threads', '4', 'output.mp4']); ``` ## Cross-Origin Isolation (SharedArrayBuffer) Multi-threaded ffmpeg.wasm requires SharedArrayBuffer, which needs Cross-Origin Isolation headers. ### Vite Configuration ```javascript // vite.config.js export default { server: { headers: { "Cross-Origin-Embedder-Policy": "require-corp", "Cross-Origin-Opener-Policy": "same-origin", }, }, optimizeDeps: { exclude: ["@ffmpeg/ffmpeg", "@ffmpeg/util"], }, }; ``` ### Next.js Configuration ```javascript // next.config.js module.exports = { async headers() { return [ { source: "/:path*", headers: [ { key: "Cross-Origin-Embedder-Policy", value: "require-corp" }, { key: "Cross-Origin-Opener-Policy", value: "same-origin" }, ], }, ]; }, }; ``` ### Express.js Middleware ```javascript import express from 'express'; const app = express(); app.use((req, res, next) => { res.setHeader("Cross-Origin-Embedder-Policy", "require-corp"); res.setHeader("Cross-Origin-Opener-Policy", "same-origin"); res.setHeader("Cross-Origin-Resource-Policy", "cross-origin"); next(); }); app.use(express.static('public')); app.listen(3000); ``` ### Nginx Configuration ```nginx server { listen 443 ssl; add_header Cross-Origin-Embedder-Policy "require-corp" always; add_header Cross-Origin-Opener-Policy "same-origin" always; location / { root /var/www/html; } } ``` ## React Integration ### React Component ```jsx import { useState, useRef } from 'react'; import { FFmpeg } from '@ffmpeg/ffmpeg'; import { fetchFile, toBlobURL } from '@ffmpeg/util'; function VideoTranscoder() { const [loaded, setLoaded] = useState(false); const [progress, setProgress] = useState(0); const [outputURL, setOutputURL] = useState(null); const ffmpegRef = useRef(new FFmpeg()); const load = async () => { const ffmpeg = ffmpegRef.current; // Progress handler ffmpeg.on('progress', ({ progress }) => { setProgress(Math.round(progress * 100)); }); const baseURL = 'https://cdn.jsdelivr.net/npm/@ffmpeg/[email protected]/dist/umd'; await ffmpeg.load({ coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, 'text/javascript'), wasmURL: await toBlobURL(`${baseURL}/ffmpeg-core.wasm`, 'application/wasm'), }); setLoaded(true); }; const transcode = async (file) => { const ffmpeg = ffmpegRef.current; await ffmpeg.writeFile('input.webm', await fetchFile(file)); await ffmpeg.exec([ '-i', 'input.webm', '-c:v', 'libx264', '-preset', 'ultrafast', '-c:a', 'aac', 'output.mp4' ]); const data = await ffmpeg.readFile('output.mp4'); const url = URL.createObjectURL( new Blob([data.buffer], { type: 'video/mp4' }) ); setOutputURL(url); }; return ( <div> {!loaded ? ( <button onClick={load}>Load FFmpeg (~31MB)</button> ) : ( <> <input type="file" accept="video/*" onChange={(e) => transcode(e.target.files[0])} /> <p>Progress: {progress}%</p> {outputURL && <video src={outputURL} controls />} </> )} </div> ); } ``` ## Common Operations ### Convert WebM to MP4 ```javascript await ffmpeg.exec(['-i', 'input.webm', '-c:v', 'libx264', 'output.mp4']); ``` ### Extract Audio ```javascript await ffmpeg.exec(['-i', 'video.mp4', '-vn', '-c:a', 'libmp3lame', 'audio.mp3']); ``` ### Create Thumbnail ```javascript await ffmpeg.exec(['-i', 'video.mp4', '-ss', '00:00:05', '-vframes', '1', 'thumb.jpg']); ``` ### Trim Video ```javascript await ffmpeg.exec([ '-i', 'input.mp4', '-ss', '00:00:10', '-t', '00:00:30', '-c', 'copy', 'output.mp4' ]); ``` ### Add Watermark ```javascript await ffmpeg.writeFile('logo.png', await fetchFile(logoFile)); await ffmpeg.exec([ '-i', 'input.mp4', '-i', 'logo.png', '-filter_complex', 'overlay=10:10', 'output.m
Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.