Skip to main content
Mediabunny ships with a powerful built-in file conversion abstraction that makes it easy to convert media files between formats, resize video, change codecs, trim clips, and more.

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 the onProgress 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 the video option:

Resizing video

Contains the entire image within the box while preserving aspect ratio. May result in letterboxing.
If only width or height is provided, the other dimension is calculated automatically to preserve aspect ratio.

Rotating video

Rotation is applied on top of any rotation metadata in the input file and happens before cropping and resizing.

Cropping video

Cropping is applied after rotation but before resizing.

Transcoding video

Processing video frames

Apply custom processing to each frame:
The process function can return:
  • A VideoSample
  • A CanvasImageSource (canvas, image, video frame)
  • An array of either
  • null to drop the frame

Audio options

Configure audio track conversion with the audio option:

Resampling audio

Mediabunny performs automatic up/downmixing using the same algorithm as the Web Audio API.

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:
The output will be 15 seconds long and will begin at timestamp 0. You can also use negative values to add padding:

Metadata tags

Control metadata tags in the output:

Discarded tracks

If an input track is excluded from the output, it’s considered discarded:
Possible discard reasons:
  • 'discarded_by_user' - You set discard: 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

This frees up resources and causes any ongoing execute() call to throw a ConversionCanceledError.

Examples