Mediabunny: Reading, writing and converting media in browser

5 hours ago 1

The missing part in the JS ecosystem for building web-first media apps.

Author image

Yonatan, Gling AI

Mediabunny gives you low-level control with high-level ease. It’s fast, lightweight, and finally feels like media processing built for the web, not ported to it.

Author image

Konstantin, Diffusion Studio

bash

npm install mediabunny

Mediabunny allows you efficiently read data from any media 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.

Docs

ts

const input = new Input({ source: new UrlSource('./bigbuckbunny.mp4'), formats: ALL_FORMATS, // .mp4, .webm, .wav, ... }); const duration = await input.computeDuration(); const videoTrack = await input.getPrimaryVideoTrack(); const { displayWidth, displayHeight, rotation } = videoTrack; const audioTrack = await input.getPrimaryAudioTrack(); const { sampleRate, numberOfChannels } = audioTrack; // Get the frame halfway through the video const sink = new VideoSampleSink(videoTrack); const frame = await sink.getSample(duration / 2); // Loop over all frames of the video for await (const frame of sink.samples()) { // ... }

ts

const output = new Output({ format: new Mp4OutputFormat(), // .mp4 target: new BufferTarget(), // in memory }); // Add video, driven by a canvas const videoSource = new CanvasSource(canvas, { codec: 'av1', bitrate: QUALITY_HIGH, }); output.addVideoTrack(videoSource); // Add audio, driven by audio buffers const audioSource = new AudioBufferSource({ codec: 'opus', bitrate: QUALITY_HIGH, }); output.addAudioTrack(audioSource); await output.start(); // Add media data here... await output.finalize(); const { buffer } = output.target; // Contains the final file

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.

Docs

Use the Conversion API to transform any media file into any other media file: perform transmuxing, transcoding, resizing, rotation, audio resampling, trimming, and more.

Docs

ts

const input = new Input({ source: new BlobSource(file), // Read from disk formats: ALL_FORMATS, }); const output = new Output({ format: new WebMOutputFormat(), // Convert to .webm target: new StreamTarget(writableStream), // Write to disk }); const conversion = await Conversion.init({ input, output }); await conversion.execute(); // Done!

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.

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)

See full list

Extract metadata

@remotion/media-parser

233 ops/s

Iterate over all video packets

Mediabunny

10800 packets/s

web-demuxer

2390 packets/s

@remotion/media-parser

842 packets/s

Convert to .webm & resize to 320x180

@remotion/webcodecs

324 frames/s

Reading BigBuckBunny1080pH264.mov (691 MiB) from disk
Ryzen 7600X, RTX 4070, NVMe SSD, measured 2025-06-22

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.

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.

Bundle size, minified + gzipped

Reading .wav files

5.10 kB

Writing .wav files

5.79 kB

Writing .webm files

11.4 kB

Reading .webm files

15.2 kB

Reading .mp4 files

16.0 kB

Writing .mp4 files

17.3 kB

Reading all formats

30.0 kB

@remotion/webcodecs

108 kB

Measured 2025-06-22


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:

Gold sponsors

Individual sponsors

And you

Read Entire Article