Your First Video Encode
This tutorial will have you encoding video frames in under 5 minutes.Install node-webcodecs
Make sure you’ve installed FFmpeg first. See Installation Guide if you haven’t.
What Just Happened?
VideoEncoder setup
VideoEncoder setup
output callback receives:- chunk:
EncodedVideoChunkcontaining compressed data - metadata: Decoder configuration (if this is the first chunk)
Configuration
Configuration
- codec: MIME type or fourCC (see API Reference)
- bitrate: Target bits per second
- width/height: Frame dimensions
Frame lifecycle
Frame lifecycle
.close() is critical:- VideoFrame wraps native C++ memory
- JavaScript GC doesn’t see it
- Forgetting = memory leak!
.close() immediately after encoding.Timestamps
Timestamps
- 30 fps = 33,333 μs per frame
- 60 fps = 16,667 μs per frame
- 1 second = 1,000,000 μs
Full Example (TypeScript)
Common Mistakes
Next Steps
Decode Video
Learn to decode video frames
API Reference
Complete VideoEncoder documentation
Cookbook
Real-world recipes
Hardware Acceleration
8-15x faster encoding