What’s in the Cookbook?
This cookbook provides practical, production-ready recipes for common video encoding tasks using node-webcodecs. Each recipe includes complete working code, explanations, and best practices.Recipes
Video Transcoding
Convert between formats and codecs
- H.264 to VP9
- Resolution changes
- Bitrate optimization
Video Watermarking
Add logos and text overlays
- Image watermarks
- Text overlays
- Positioning and scaling
Thumbnail Generation
Extract frames as images
- First frame extraction
- Multiple thumbnails
- Scene detection
WebRTC Recording
Record video from WebRTC streams
- MediaStream capture
- Real-time encoding
- Live streaming
Video Validation
Verify video properties
- Codec detection
- Resolution validation
- Duration checking
Quick Reference
Common Patterns
Basic Encode Pattern
Basic Encode Pattern
Basic Decode Pattern
Basic Decode Pattern
Encode-Decode Roundtrip
Encode-Decode Roundtrip
Common Operations
- Read Video File
- Write Video File
- Process Frames
- Change Resolution
Best Practices
Memory Management
- Always call
frame.close() - Close immediately after use
- Monitor memory usage
- Process in batches
Error Handling
- Implement error callbacks
- Validate inputs
- Check codec support
- Provide fallbacks
Performance
- Use hardware acceleration
- Batch process frames
- Manage queue size
- Profile bottlenecks
Quality
- Choose appropriate bitrate
- Match source resolution
- Test output quality
- Balance size vs quality
Code Style Guide
File Organization
Error Handling
Resource Cleanup
Testing Patterns
Unit Test Example
Next Steps
Transcode Video
Convert between codecs
Add Watermarks
Overlay logos and text
Generate Thumbnails
Extract video frames
Examples
More code examples