Skip to main content

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

Problems:
  • Can’t inspect frames
  • No programmatic control
  • Hard to test

2. Text Overlay (Dynamic)

Limitations:
  • Text is fixed at encode time
  • Can’t use variables
  • No conditional display
  • String escaping nightmare for special chars

3. Watermark Overlay

Limitations:
  • Fixed position only
  • Can’t animate
  • No conditional display

4. Extract Thumbnails

Limitations:
  • Frame numbers, not timestamps
  • Can’t inspect frame content
  • No quality validation

5. Resize Video


6. Concatenate Videos

Limitations:
  • Requires intermediate file
  • Must have same codec/dimensions
  • No transition effects

7. Speed Up/Slow Down

Limitations:
  • Fixed multiplier
  • Can’t have variable speed
  • PTS math is confusing

8. Extract Audio


9. Create Slideshow from Images

Limitations:
  • All images same duration
  • No transitions
  • Glob patterns can be unreliable

10. Live Stream Recording

Limitations:
  • 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
##Advantages Summary

Next Steps

API Reference

Complete VideoEncoder docs

Cookbook

More real-world recipes

Hardware Acceleration

8-15x faster encoding

Examples

Working code examples