Input for reading and Output for writing. These classes work together to provide a complete media processing pipeline.
Input class
TheInput class represents an input media file and is the starting point for all read operations. It abstracts away the complexity of different file formats and provides a unified interface for reading media data.
Creating an Input
To create anInput, you need to specify:
- formats: An array of supported input formats (MP4, WebM, etc.)
- source: Where to read the data from (file, URL, buffer, etc.)
Reading media data
Once you have anInput, you can access its tracks and read packets:
Input metadata
TheInput class provides access to file-level metadata:
Disposing resources
Output class
TheOutput class orchestrates the creation of new media files. It manages tracks, encoders, and writes the final output to a target destination.
Creating an Output
To create anOutput, specify:
- format: The output format (MP4, WebM, etc.)
- target: Where to write the data (buffer, stream, file, etc.)
Adding tracks
Before starting an output, you must add tracks and configure their sources:Output lifecycle
AnOutput follows a specific lifecycle:
1
Create output
Instantiate the
Output with a format and target.2
Add tracks
Add video, audio, and subtitle tracks with their sources and metadata.
3
Start output
Call
start() to begin accepting media data.4
Add samples
Feed samples or packets to each track’s source.
5
Finalize
Call
finalize() when all media data has been added.Complete example
Here’s a complete example of reading from one file and writing to another:Input and Output together
The power of Mediabunny comes from usingInput and Output together:
Remuxing
Copy media data from one container format to another without re-encoding.
Transcoding
Decode media samples, process them, and re-encode to different codecs.
Editing
Extract, trim, or combine media from multiple sources.
Analysis
Read media data to analyze quality, extract metadata, or generate previews.
Error handling
BothInput and Output can throw errors during operation:
See the Error Handling guide for comprehensive error management strategies.