Migrating from FFmpeg CLI to node-webcodecs
Stop fighting with filter strings. Start writing actual code.About These Examples: The patterns below show the conceptual approach for each FFmpeg operation. Helper functions like
decodeVideo(), composite(), and frameToJPEG() represent application-specific logic you’d implement. For complete, runnable implementations, see the Cookbook recipes.Why Migrate?
Debuggable
Breakpoints and stack traces instead of stderr parsing
Testable
Unit test your video logic with Jest/Mocha
Conditional Logic
Use if/else, loops, variables — not filter DSL
Type Safe
TypeScript catches errors before encoding starts
Pattern Comparison
1. Basic Transcoding
- FFmpeg CLI
- node-webcodecs
- Can’t inspect frames
- No programmatic control
- Hard to test
2. Text Overlay (Dynamic)
- FFmpeg CLI
- node-webcodecs
- Text is fixed at encode time
- Can’t use variables
- No conditional display
- String escaping nightmare for special chars
3. Watermark Overlay
- FFmpeg CLI
- node-webcodecs
- Fixed position only
- Can’t animate
- No conditional display
4. Extract Thumbnails
- FFmpeg CLI
- node-webcodecs
- Frame numbers, not timestamps
- Can’t inspect frame content
- No quality validation
5. Resize Video
- FFmpeg CLI
- node-webcodecs
6. Concatenate Videos
- FFmpeg CLI
- node-webcodecs
- Requires intermediate file
- Must have same codec/dimensions
- No transition effects
7. Speed Up/Slow Down
- FFmpeg CLI
- node-webcodecs
- Fixed multiplier
- Can’t have variable speed
- PTS math is confusing
8. Extract Audio
- FFmpeg CLI
- node-webcodecs
9. Create Slideshow from Images
- FFmpeg CLI
- node-webcodecs
- All images same duration
- No transitions
- Glob patterns can be unreliable
10. Live Stream Recording
- FFmpeg CLI
- node-webcodecs
- Can’t process frames
- No real-time analysis
- Can’t create highlights
Migration Checklist
Map to WebCodecs APIs
- Encoding →
VideoEncoder - Decoding →
VideoDecoder - Filters → Canvas API or image processing libs
| Feature | FFmpeg CLI | node-webcodecs |
|---|---|---|
| Debugging | stderr parsing | Breakpoints, stack traces |
| Conditionals | ❌ Not possible | ✅ if/else, switch |
| Variables | Limited ENV vars | ✅ Full JavaScript |
| Testing | Shell scripts | ✅ Jest/Mocha unit tests |
| Type Safety | ❌ None | ✅ TypeScript |
| Frame Access | ❌ No | ✅ Every frame |
| API Integration | ❌ Hard | ✅ Easy (fetch, DB) |
| Error Handling | Exit codes | try/catch |
| IDE Support | ❌ None | ✅ Autocomplete |