Mediabunny allows you efficiently read data from any video or audio file, no matter the size: duration, resolution, rotation, tracks, codecs and other metadata, as well as raw or decoded media data from anywhere in the file. Load only what you need.
constinput=newInput({source: newUrlSource('./bigbuckbunny.mp4'),formats: ALL_FORMATS,// .mp4, .webm, .wav, ...
});constduration=awaitinput.computeDuration();constvideoTrack=awaitinput.getPrimaryVideoTrack();const{displayWidth,displayHeight,rotation}=videoTrack;constaudioTrack=awaitinput.getPrimaryAudioTrack();const{sampleRate,numberOfChannels}=audioTrack;// Get the frame halfway through the video
constsink=newVideoSampleSink(videoTrack);constframe=awaitsink.getSample(duration/2);// Loop over all frames of the video
forawait(constframeofsink.samples()){// ...
}
constoutput=newOutput({format: newMp4OutputFormat(),// .mp4
target: newBufferTarget(),// in memory
});// Add video, driven by a canvas
constvideoSource=newCanvasSource(canvas,{codec:'av1',bitrate: QUALITY_HIGH,});output.addVideoTrack(videoSource);// Add audio, driven by audio buffers
constaudioSource=newAudioBufferSource({codec:'opus',bitrate: QUALITY_HIGH,});output.addAudioTrack(audioSource);awaitoutput.start();// Add media data here...
awaitoutput.finalize();const{buffer}=output.target;// Contains the final file
Create new media files, programmatically
Generate new media files (such as MP4 or WebM) directly on the client, and as fast as the hardware allows. Add multiple video, audio, or subtitle tracks, and have precise control down to the microsecond.
Use the Conversion API to transform any media file into any other media file: perform transmuxing, transcoding, resizing, rotation, audio resampling, trimming, and more.
constinput=newInput({source: newBlobSource(file),// Read from disk
formats: ALL_FORMATS,});constoutput=newOutput({format: newWebMOutputFormat(),// Convert to .webm
target: newStreamTarget(writableStream),// Write to disk
});constconversion=awaitConversion.init({input,output});awaitconversion.execute();// Done!
Universal I/O
Read and write files from and to memory, disk, or the network. Create files for offline use, or live-stream them as they're being created. Inject media data from a canvas, webcam, screen, microphone, audio buffer, your own encoding stack, or whatever. It's all up to you.
Wide container & codec support
Mediabunny supports many commonly used container formats and a wide variety of video and audio codecs. And all of them bidirectionally, too! (that means for reading and writing)
Reading BigBuckBunny1080pH264.mov (691 MiB) from disk Ryzen 7600X, RTX 4070, NVMe SSD, measured 2025-06-22
High performance
By reading only what you need, writing progressively, utilizing hardware-accelerated encoding and decoding via the WebCodecs API, and using a pipelined design, Mediabunny is able to get the job done fast.
Built from scratch, for the web
Mediabunny is 100% implemented in TypeScript and has zero dependencies. Its API was designed to be highly tree-shakable, meaning you only include what you use.
Mediabunny is an open-source project released under the MPL-2.0 and is therefore free to use for any purpose, including closed-source commercial use. A permissive license is essential for a foundational library like this to truly thrive. That said, this project requires an immense amount of work and care. This is made possible by the generous financial backing of these awesome sponsors: