Overview
The EncoderProfile class configures how your compositions are exported. It handles video codecs, quality settings, and format-specific options for FFmpeg.
🎬 Standard Formats H.264 MP4, VP9 WebM - Universal compatibility
🎯 Professional Formats ProRes MOV, PNG Sequence - Maximum quality
H.264 MP4 (Recommended)
Universal compatibility with excellent compression:
import { EncoderProfile } from '@videobgremover/sdk'
// Default settings (CRF 18, medium preset)
const encoder = EncoderProfile . h264 ()
// Custom quality settings
const hq = EncoderProfile . h264 ({
crf: 15 , // Higher quality (12-18 = excellent)
preset: 'slow' // Better compression, slower encoding
})
// Fast encoding for testing
const fast = EncoderProfile . h264 ({
crf: 28 , // Lower quality for speed
preset: 'ultrafast' // Fastest encoding
})
// Web delivery optimized
const web = EncoderProfile . h264 ({
crf: 26 , // Good quality for web
preset: 'medium' // Balanced speed/compression
})
VP9 WebM
Excellent compression for web delivery:
// Default VP9 settings
const encoder = EncoderProfile . vp9 ()
// Custom VP9 settings
const webOptimized = EncoderProfile . vp9 ({
crf: 32 , // Good quality for web (30-35 typical)
preset: 'fast' // Reasonable encoding speed
})
// High quality VP9
const hqVp9 = EncoderProfile . vp9 ({
crf: 24 , // Higher quality
preset: 'slow' // Better compression
})
ProRes 4444 MOV
Highest quality for professional video editing:
// ProRes 4444 (highest quality, large files)
const prores = EncoderProfile . prores4444 ()
// Perfect for: Final Cut Pro, Premiere Pro, DaVinci Resolve
await comp . toFile ( 'professional.mov' , prores )
PNG Sequence
Frame-by-frame output for maximum quality:
// PNG sequence (one file per frame)
const png = EncoderProfile . pngSequence ()
await comp . toFile ( 'frames/frame_%04d.png' , png )
// Custom frame rate
const png24 = EncoderProfile . pngSequence ({ fps: 24 })
await comp . toFile ( 'frames/frame_%04d.png' , png24 )
// Creates: frame_0001.png, frame_0002.png, frame_0003.png, ...
Perfect for further compositing or overlaying on other content:
Transparent WebM
// Transparent WebM with alpha channel
const transparent = EncoderProfile . transparentWebm ()
// Custom quality for transparency
const hqTransparent = EncoderProfile . transparentWebm ({
crf: 20 // Higher quality for clean edges
})
await comp . toFile ( 'overlay.webm' , transparent )
WebM Transparency : Requires libvpx-vp9 decoder for proper alpha channel support. The SDK automatically detects and uses the correct decoder when available.
Stacked Video
Debug format showing video and mask:
// Stacked video (top: video, bottom: mask)
const stacked = EncoderProfile . stackedVideo ()
// Custom layout
const horizontal = EncoderProfile . stackedVideo ({
layout: 'horizontal' // Side-by-side instead of stacked
})
await comp . toFile ( 'debug.mp4' , stacked )
Quality Guidelines
CRF Values (Constant Rate Factor)
Lower CRF = Higher quality, larger files:
CRF Range Quality Use Case File Size
12-18 Excellent Professional work, archival Large 19-23 High General purpose, good balance Medium 24-28 Good Web delivery, streaming Small 29-35 Acceptable Previews, low bandwidth Very Small
Encoding Presets
Balance between speed and compression efficiency:
Preset Speed Compression Use Case
ultrafast Fastest Poor Testing, previews fast Fast Good Development, iteration medium Moderate Better General purpose slow Slow Best Final delivery veryslow Slowest Excellent Archival, maximum compression
// Instagram feed/reels
const instagram = EncoderProfile . h264 ({ crf: 25 , preset: 'medium' })
Professional Workflows
// Final Cut Pro / Premiere Pro
const editing = EncoderProfile . prores4444 ()
// DaVinci Resolve
const grading = EncoderProfile . h264 ({ crf: 12 , preset: 'slow' })
// After Effects
const png = EncoderProfile . pngSequence ({ fps: 30 })
Custom Arguments
Access the raw FFmpeg arguments for advanced use:
const encoder = EncoderProfile . h264 ({ crf: 20 , preset: 'medium' })
// Get FFmpeg arguments
const args = encoder . args ( 'output.mp4' )
console . log ( 'FFmpeg args:' , args )
// Example output:
// ['-c:v', 'libx264', '-crf', '20', '-preset', 'medium', 'output.mp4']
Encoder Properties
const encoder = EncoderProfile . h264 ({ crf: 20 , preset: 'fast' })
console . log ( 'Kind:' , encoder . kind ) // 'h264'
console . log ( 'CRF:' , encoder . crf ) // 20
console . log ( 'Preset:' , encoder . preset ) // 'fast'
Complete Export Example
// Create composition
const comp = new Composition ( background )
comp . add ( video1 , 'main' ). at ( Anchor . CENTER )
comp . add ( video2 , 'pip' ). at ( Anchor . TOP_RIGHT ). size ( SizeMode . CANVAS_PERCENT , { percent: 25 })
// Export in multiple formats
console . log ( 'Exporting preview...' )
await comp . toFile ( 'preview.mp4' , EncoderProfile . h264 ({ crf: 30 , preset: 'ultrafast' }))
console . log ( 'Exporting high quality...' )
await comp . toFile ( 'final.mp4' , EncoderProfile . h264 ({ crf: 18 , preset: 'slow' }))
console . log ( 'Exporting web version...' )
await comp . toFile ( 'web.webm' , EncoderProfile . vp9 ({ crf: 28 }))
console . log ( 'Exporting for editing...' )
await comp . toFile ( 'edit.mov' , EncoderProfile . prores4444 ())
console . log ( '✅ All exports complete!' )
Format Quality File Size Speed Use Case
H.264 CRF 18 Excellent Large Fast General purpose H.264 CRF 28 Good Small Fast Web delivery VP9 CRF 28 Good Very Small Slow Web optimized ProRes 4444 Perfect Very Large Fast Professional editing PNG Sequence Perfect Huge Fast Frame-by-frame work Transparent WebM High Small Slow Further compositing
Advanced Settings
Custom H.264 Settings
// Professional broadcast settings
const broadcast = EncoderProfile . h264 ({
crf: 16 , // Broadcast quality
preset: 'slow' , // Maximum compression efficiency
profile: 'high' , // H.264 profile (if supported)
level: '4.1' // H.264 level (if supported)
})
// Streaming optimized
const streaming = EncoderProfile . h264 ({
crf: 24 ,
preset: 'veryfast' , // Fast encoding for live streaming
tune: 'zerolatency' // Low latency (if supported)
})
File Size Estimation
Approximate file sizes for different settings (30-second 1080p video):
// Ultra high quality: ~100MB
const uhq = EncoderProfile . h264 ({ crf: 12 , preset: 'veryslow' })
// High quality: ~50MB
const hq = EncoderProfile . h264 ({ crf: 18 , preset: 'slow' })
// Good quality: ~25MB
const good = EncoderProfile . h264 ({ crf: 23 , preset: 'medium' })
// Web quality: ~15MB
const web = EncoderProfile . h264 ({ crf: 28 , preset: 'fast' })
// Preview quality: ~8MB
const preview = EncoderProfile . h264 ({ crf: 32 , preset: 'ultrafast' })
Troubleshooting
Encoding Errors
Common encoding issues and solutions:
Unknown Codec
Error: Unknown encoder 'libx264'
Solution : Install FFmpeg with H.264 support
Out of Memory
Error: Cannot allocate memory
Solutions :
Reduce video resolution
Use faster preset
Process shorter segments
Slow Encoding
Solutions :
Use faster preset (fast, ultrafast)
Reduce quality (higher CRF value)
Use fewer layers in composition
Quality Issues
Blocky/Pixelated Output
Solutions :
Lower CRF value (higher quality)
Use slower preset for better compression
Check source video quality
Large File Sizes
Solutions :
Increase CRF value (lower quality)
Use VP9 instead of H.264
Use faster preset (less compression efficiency)