Features
The conversion API supports:- Transmuxing - Change the container format
- Transcoding - Change track codecs
- Track removal - Remove unwanted tracks
- Compression - Reduce file size with lower bitrates
- Trimming - Extract specific time ranges
- Video resizing & fitting - Change dimensions and aspect ratio
- Video rotation - Rotate video frames
- Video cropping - Extract rectangular regions
- Frame rate adjustment - Change video frame rate
- Audio resampling - Change sample rate and channel count
- Custom processing - Apply filters and effects
Basic usage
1
Create input and output
2
Initialize the conversion
3
Execute the conversion
The
Output passed to the conversion must be fresh - no tracks added, no metadata set, and in the 'pending' state.Monitoring progress
Track conversion progress with theonProgress callback:
A progress of
1 doesn’t mean the conversion is finished - the conversion is only complete when execute() resolves.Video options
Configure video track conversion with thevideo option:
Resizing video
- contain
- cover
- fill
Contains the entire image within the box while preserving aspect ratio. May result in letterboxing.
width or height is provided, the other dimension is calculated automatically to preserve aspect ratio.
Rotating video
Cropping video
Transcoding video
Processing video frames
Apply custom processing to each frame:process function can return:
- A
VideoSample - A
CanvasImageSource(canvas, image, video frame) - An array of either
nullto drop the frame
Audio options
Configure audio track conversion with theaudio option:
Resampling audio
Transcoding audio
Processing audio samples
Track-specific options
Apply different options to each track using functions:Trimming
Extract a specific time range from the input:Metadata tags
Control metadata tags in the output:Discarded tracks
If an input track is excluded from the output, it’s considered discarded:'discarded_by_user'- You setdiscard: true'max_track_count_reached'- No room for more tracks'max_track_count_of_type_reached'- No room for this track type'unknown_source_codec'- Codec not recognized'undecodable_source_codec'- Can’t decode the source'no_encodable_target_codec'- Can’t find an encodable codec for output format
Canceling a conversion
execute() call to throw a ConversionCanceledError.