The WebCodecs API has matured significantly, and for many use cases, you no longer need the 25MB FFmpeg.wasm bundle. Here are 5 patterns I use in production.\n\n## 1. Caption Burning on Short Clips\n\nInstead of loading FFmpeg to burn subtitles, use VideoDecoder + OffscreenCanvas:\n\njavascript\nconst decoder = new VideoDecoder({\n output: (frame) => {\n const canvas = new OffscreenCanvas(frame.displayWidth, frame.displayHeight);\n const ctx = canvas.getContext('2d');\n ctx.drawImage(frame, 0, 0);\n ctx.font = '24px sans-serif';\n ctx.fillStyle = 'white';\n ctx.fillText(caption, 20, frame.displayHeight - 40);\n // Encode the modified frame\n encoder.encode(new VideoFrame(canvas, { timestamp: frame.timestamp }));\n frame.close();\n },\n error: console.error\n});\n\n\n*When to use:* Short clips (<60s), simple text overlays.\n**When to stick with FFmpeg:** Complex filters, format conversion.\n\n## 2. Real-time Audio Visualization\n\nAudioDecoder gives you raw PCM samples without AudioContext overhead:\n\n`javascript\nconst audioDecoder = new AudioDecoder({\n output: (audioData) => {\n const samples = new Float32Array(audioData.numberOfFrames);\n audioData.copyTo(samples, { planeIndex: 0 });\n // Feed to your visualizer\n updateWaveform(samples);\n audioData.close();\n },\n error: console.error\n});\n\n\n## 3. Thumbnail Generation at Scale\n\nNeed thumbnails from 100 videos? WebCodecs decodes specific frames without downloading full files:\n\njavascript\nasync function getThumbnail(url, timeOffset) {\n const response = await fetch(url, {\n headers: { Range: ytes=0-500000 } // Just grab the header + first keyframe\n });\n // Demux and decode just the frame you need\n // 10x faster than loading full video into
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)