Skip to main content

Why Migrate to Node.js?

Browser WebCodecs is perfect for client-side video processing, but server-side encoding unlocks:

Privacy & Security

Process sensitive videos server-side without client uploads

Computational Power

Use dedicated hardware encoders (NVENC, VideoToolbox, QuickSync)

Batch Processing

Process thousands of videos in parallel worker threads

Isomorphic Code

Share effects code between browser preview and server export

API Compatibility

node-webcodecs implements 100% of the browser WebCodecs API. Code that works in Chrome/Firefox/Safari works in Node.js without changes.
Key takeaway: The only difference is the import statement and frame sources (no DOM in Node.js).

Key Differences

While the WebCodecs API is identical, the runtime environment differs:

1. No Canvas API (Use node-canvas)

2. Worker Threads (Use useWorkerThread option)

3. Hardware Acceleration

4. File System Access

Isomorphic Code Patterns

Write code that works in both browser and Node.js:

Pattern 1: Shared Effects Module

Pattern 2: Platform-Specific Factories

Pattern 3: Frame Source Abstraction

Migration Checklist

1

Update imports

2

Replace Canvas API with node-canvas

3

Update frame creation

4

Replace IndexedDB with file system

5

Enable worker threads (optional)

6

Add hardware acceleration (optional)

Real-World Example: Isomorphic Video Editor

Here’s a complete example of an effects system that works in both environments:

Performance Comparison

Browser Strengths:
  • Zero installation (runs in any modern browser)
  • Direct access to <video>, <canvas>, WebCam
  • Automatic hardware acceleration
  • Low latency for preview
Browser Limitations:
  • Limited to user’s device hardware
  • No batch processing
  • Privacy concerns (upload required for server processing)
  • Tab backgrounding throttles encoding

Hybrid Architecture

Best practice: Use both browser and Node.js WebCodecs together:
Server endpoint (Node.js):

Common Gotchas

1. Forgetting to import VideoFrame in Node.js
2. Using DOM APIs directly
3. Not specifying format in Node.js

Next Steps

Hardware Acceleration

8-15x faster encoding on server

Worker Threads

Parallel video processing

API Reference

Complete WebCodecs API docs

Cookbook

Real-world recipes