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
1
Install node-webcodecs
2
Identify your FFmpeg patterns
List all your current FFmpeg commands and their purposes
3
Map to WebCodecs APIs
- Encoding →
VideoEncoder - Decoding →
VideoDecoder - Filters → Canvas API or image processing libs
4
Refactor with real code
Replace filter strings with JavaScript/TypeScript logic
5
Add tests
Unit test your video logic with Jest
6
Add type safety
Use TypeScript for compile-time error checking
Next Steps
API Reference
Complete VideoEncoder docs
Cookbook
More real-world recipes
Hardware Acceleration
8-15x faster encoding
Examples
Working code examples