MCPcopy
hub / github.com/Vanilagy/mediabunny

github.com/Vanilagy/mediabunny @v1.50.6 sqlite

repository ↗ · DeepWiki ↗ · release v1.50.6 ↗
2,522 symbols 7,133 edges 175 files 462 documented · 18%
README

Mediabunny - JavaScript media toolkit

<img src="https://github.com/Vanilagy/mediabunny/raw/v1.50.6/docs/public/mediabunny-logo.svg" width="180" height="180">

Mediabunny is a JavaScript library for reading, writing, and converting media (like MP4, WebM, MP3, HLS), directly in the browser. It aims to be a complete toolkit for high-performance media operations on the web. It's written from scratch in pure TypeScript, has zero dependencies, is very performant, and is extremely tree-shakable, meaning you only include what you use. You can think of it a bit like FFmpeg, but built from the ground up for the web.

Documentation | Examples | Sponsoring | License | Discord

Gold sponsors

  <img src="https://github.com/Vanilagy/mediabunny/raw/v1.50.6/docs/public/sponsors/remotion-light.png" width="60" height="60" alt="Remotion">

     Gling AI      Diffusion Studio      Kino      Screen Studio      Tella

Silver sponsors

Ponder

Bronze sponsors

ElevenLabs      React Video Editor      Mux      Jellypod      PhotoCircle

Sponsor Mediabunny's development

Features

Core features include:

  • Wide format support: Read and write MP4, MOV, WebM, MKV, HLS, WAVE, MP3, Ogg, ADTS, FLAC, MPEG-TS
  • Built-in encoding & decoding: Supports 25+ video, audio, and subtitle codecs, hardware-accelerated using the WebCodecs API
  • High precision: Fine-grained, microsecond-accurate reading and writing operations
  • Conversion API: Easy-to-use API with features such as transmuxing, transcoding, resizing, rotation, cropping, resampling, trimming, and more
  • Streaming I/O: Handle reading & writing files of any size with memory-efficient streaming
  • Cross-platform: Works in all browsers as well as in Node, Bun, and Deno using @mediabunny/server
  • Tree-shakable: Only bundle what you use (as small as 5 kB gzipped)
  • Zero dependencies: Implemented in highly performant TypeScript

See full feature list

Quick start

Installation

Install it via npm:

npm install mediabunny

Alternatively, include it directly with a script tag using one of the builds. Doing so exposes a global Mediabunny object.

<script src="https://github.com/Vanilagy/mediabunny/raw/v1.50.6/mediabunny.cjs"></script>

Requires any JavaScript environment that can run ECMAScript 2021 or later. Mediabunny is expected to be run in modern browsers. For types, TypeScript 5.7 or later is required.

Read file metadata

import { Input, ALL_FORMATS, BlobSource } from 'mediabunny';

// Reading from disk
const input = new Input({
    source: new BlobSource(file),
    formats: ALL_FORMATS,
});

const duration = await input.computeDuration(); // in seconds
const videoTrack = await input.getPrimaryVideoTrack();
const audioTrack = await input.getPrimaryAudioTrack();

const displayWidth = await videoTrack.getDisplayWidth();
const displayHeight = await videoTrack.getDisplayHeight();
const rotation = await videoTrack.getRotation();

const sampleRate = await audioTrack.getSampleRate();
const numberOfChannels = await audioTrack.getNumberOfChannels();

const { title, artist, album } = await input.getMetadataTags();

Create new media files

import { Output, Mp4OutputFormat, BufferTarget, CanvasSource, QUALITY_HIGH } from 'mediabunny';

const output = new Output({
    format: new Mp4OutputFormat(),
    target: new BufferTarget(), // Writing to memory
});

// Add a video track backed by a canvas element
const videoSource = new CanvasSource(canvas, {
    codec: 'avc',
    bitrate: QUALITY_HIGH,
});
output.addVideoTrack(videoSource);

await output.start();
// Add frames...
await output.finalize();

const buffer = output.target.buffer; // Final MP4 file

Convert files

import { Input, Output, Conversion, ALL_FORMATS, BlobSource, WebMOutputFormat } from 'mediabunny';

const input = new Input({
    source: new BlobSource(file),
    formats: ALL_FORMATS,
});

const output = new Output({
    format: new WebMOutputFormat(), // Convert to WebM
    target: new BufferTarget(),
});

const conversion = await Conversion.init({ input, output });
await conversion.execute();

See more code snippets

Documentation

Visit the Docs for comprehensive guides, examples and API documentation.

Sponsoring

See all sponsors

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 to maintain and expand. This is made possible by the generous financial backing of the sponsors of this project.

If you have derived considerable value from this project, please consider sponsoring it or providing a one-time donation. Thank you! 🩷

License

This project is licensed under the Mozilla Public License 2.0. This is a very permissive weak copyleft license, not much different from the MIT License, allowing you to: - Use Mediabunny for any purpose, commercial or non-commercial, without royalties - Use Mediabunny in open- and closed-source projects - Freely distribute projects built with Mediabunny - Inspect and modify Mediabunny's source code

However, you have the following obligation: - If you modify Mediabunny's licensed source code (e.g. in a fork) and then distribute it, you must publicly publish your modifications under the Mozilla Public License 2.0.

This ensures that library usage remains permissive for everybody, while any improvements to Mediabunny remain in the open, benefiting everyone.

You are not allowed to: - Remove the license and copyright headers from any Mediabunny source file - Claim the "Mediabunny" trademark

And finally, Mediabunny - like any other library - comes with no warranty of any kind and is not liable for any direct or indirect damages.

This is not legal advice. Refer to the full text of the Mozilla Public License 2.0 for the binding license agreement.

Implementation & development

Mediabunny is implemented from scratch in pure TypeScript with zero dependencies. At its core, the library is a collection of multiplexers and demultiplexers (one for every container format), which are then connected together via abstractions around the WebCodecs API. The logic is heavily pipelined and lazy, keeping performance high and memory usage low. If this stuff interests you, refer to the Technical overview for more.

For development, clone this repository and install it using a modern version of Node.js and npm. The build system uses TypeScript, esbuild, API Extractor, Vite, and VitePress.

npm install # Install dependencies
npm run watch # Build bundles on watch mode

npm run build # Production build with type definitions

npm run check # Type checking
npm run lint # ESLint

npm run docs:generate # Generates API docs
npm run docs:dev # Start docs development server
npm run dev # Start examples development server, will run at http://localhost:5173/examples/[name]/

npm run docs:build # Build docs and examples

Extension points exported contracts — how you extend this code

InputVideoTrackBacking (Interface)
(no doc) [6 implementers]
src/input-track.ts
Ac3FrameInfo (Interface)
(no doc)
src/codec-data.ts
Box (Interface)
(no doc)
src/isobmff/isobmff-boxes.ts
EBMLElement (Interface)
(no doc)
src/matroska/ebml.ts
Window (Interface)
(no doc)
examples/hls-transcoding/hls-transcoding.ts
InputAudioTrackBacking (Interface)
(no doc) [20 implementers]
src/input-track.ts
Eac3SubstreamInfo (Interface)
(no doc)
src/codec-data.ts
InputTrackBacking (Interface)
(no doc) [1 implementers]
src/input-track.ts

Core symbols most depended-on inside this repo

assert
called by 739
src/misc.ts
add
called by 279
src/resample.ts
readBits
called by 244
shared/bitstream.ts
get
called by 191
src/hls/hls-misc.ts
slice
called by 158
src/reader.ts
skipBits
called by 133
shared/bitstream.ts
start
called by 115
src/output.ts
finalize
called by 109
src/output.ts

Shape

Method 1,323
Function 845
Class 331
Enum 14
Interface 9

Languages

TypeScript100%

Modules by API surface

src/input-track.ts136 symbols
src/output-format.ts130 symbols
src/media-source.ts105 symbols
src/isobmff/isobmff-boxes.ts105 symbols
src/media-sink.ts103 symbols
src/source.ts96 symbols
src/misc.ts94 symbols
src/mpeg-ts/mpeg-ts-demuxer.ts83 symbols
src/isobmff/isobmff-demuxer.ts73 symbols
src/sample.ts68 symbols
src/input-format.ts68 symbols
src/matroska/matroska-demuxer.ts65 symbols

Dependencies from manifests, versioned

@eslint/js9.22.0 · 1×
@fontsource-variable/rubik5.2.6 · 1×
@fontsource/dm-mono5.2.6 · 1×
@mediabunny/prores1.50.6 · 1×
@microsoft/api-extractor7.55.1 · 1×
@stylistic/eslint-plugin4.2.0 · 1×
@tailwindcss/vite4.1.7 · 1×
@types/dom-mediacapture-transform0.1.11 · 1×
@types/dom-webcodecs0.1.13 · 1×
@types/emscripten1.40.1 · 1×
@types/markdown-it-footnote3.0.4 · 1×
@types/node22.13.10 · 1×

For agents

$ claude mcp add mediabunny \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact