Mediabunny
A complete TypeScript library for reading, writing, and converting media files in the browser, featuring high-performance hardware acceleration and zero dependencies.
Mediabunny is a high-performance JavaScript media toolkit designed for building web-first media applications. Built from scratch in pure TypeScript with zero dependencies, it provides a unified and highly tree-shakable API for reading, writing, and converting video and audio files directly in the browser. The project acts as a modern, web-native alternative to traditional media processing tools like FFmpeg, offering low-level control with high-level abstractions that feel natural in web environments.
Functionally, Mediabunny acts as a comprehensive set of multiplexers and demultiplexers for various container formats. It leverages the WebCodecs API for efficient, hardware-accelerated encoding and decoding, while its pipelined architecture ensures minimal latency and automatic backpressure management during media processing tasks. Whether you are extracting metadata, performing complex conversions, or generating media streams, the library is designed to perform these tasks with microsecond-level precision and efficiency.
Some of the key features are:
- Comprehensive Media Support: Extensive read and write support for container formats such as .mp4, .webm, .mov, .mkv, .ts, .mp3, .wav, .ogg, .aac, and .flac, alongside over 25 different codecs.
- Hardware Acceleration: Utilizes the WebCodecs API to offload intensive tasks to device hardware, resulting in high-performance decoding and encoding.
- Lazy Data Handling: Employs an optimized, on-demand reading strategy, ensuring that only the necessary parts of a file are processed, which is crucial for handling large media files.
- Universal I/O: Capability to read and write data from and to various locations, including memory, disk, and network streams, allowing for high flexibility in input and output sources.
- Server-Side Compatibility: Through the @mediabunny/server extension, the library extends its full suite of capabilities to server-side runtimes like Node.js, Bun, and Deno.
- Metadata Management: Robust tools for reading and writing complex metadata tags, including artist information, cover art, and custom attached files.
- Developer-Centric Design: A highly tree-shakable API that minimizes bundle sizes by including only the components actually utilized by the application.
Mediabunny operates by utilizing specific wrappers around browser-native APIs. When reading, it initializes decoders with the appropriate codec configurations to stream media data efficiently. For writing, it handles the setup of encoders based on the desired output format and input source. A conversion API is also provided, which pipelines these reading and writing processes, enabling seamless file transformations like resizing, rotating, and audio resampling without manual management of the underlying complexities.
Some common use cases include:
- File Conversion & Compression: Efficiently transforming media formats or reducing file sizes directly within a client-side application.
- Metadata Extraction: Reading detailed information such as duration, resolution, rotation, and track metadata from video or audio files.
- Thumbnail Generation: Extracting specific video frames to create image previews for video libraries or dashboards.
- Web-Based Video Editors: Building complex multimedia editing suites that require precise timing, track manipulation, and real-time processing capabilities.
- Live Streaming Applications: Managing live recording or media streaming tasks that require low-latency processing and handling of HLS manifests.
Comments
0Markdown is supported.