Creating an input
Reading media files in Mediabunny revolves around theInput class. One instance of Input represents one media file that you want to read.
1
Import the required classes
2
Create a new input
source specifies where the Input reads data from. See the Streaming guide for available input sources.The formats field specifies which file formats the Input should support. Using ALL_FORMATS means you can load files of any format that Mediabunny supports, but requires including all format parsers. For smaller bundle sizes, specify only the formats you need:Simply creating an instance of
Input will perform zero reads and is practically free. The file will only be read once data is requested.Reading file metadata
Once you have anInput, you can start reading file-level metadata.
Format and MIME type
Duration and timestamps
Methods prefixed with
compute instead of get indicate that the library might need to do more work to retrieve the requested data.Reading track information
You can extract the list of all media tracks in the file:Common track properties
Video track properties
Audio track properties
Packet statistics
You can query aggregate statistics about a track’s encoded packets:Reading media data
Mediabunny has the concept of media sinks for reading media data from tracks. Different sinks provide different levels of abstraction.Reading encoded packets
Loop over all raw encoded packets of a track:Reading decoded video samples
Iterate over decoded video frames:Extracting thumbnails
Generate downscaled thumbnails from a video track:Reading decoded audio samples
Loop over audio samples for playback:Manual decoding with WebCodecs
For full control, combine encoded packets with WebCodecs:Example: Extract metadata from a file
Disposing inputs
When you’re done with anInput, you can dispose of it to free up resources:
using keyword for automatic disposal: