@UnstableApi
public interface Muxer

Known direct subclasses
DefaultMuxer

A default Muxer implementation.

InAppFragmentedMp4Muxer

Muxer implementation that uses a FragmentedMp4Muxer.

InAppMp4Muxer

Muxer implementation that uses an Mp4Muxer.


The muxer for producing media container files.

Summary

Nested types

public interface Muxer.Factory

Factory for muxers.

Public methods

abstract void

Adds metadata about the output file.

abstract int
addTrack(Format format)

Adds a track of the given media format.

abstract void

Closes the file.

abstract void
writeSampleData(
    int trackId,
    ByteBuffer byteBuffer,
    MediaCodec.BufferInfo bufferInfo
)

Writes encoded sample data.

Public methods

addMetadataEntry

abstract void addMetadataEntry(Metadata.Entry metadataEntry)

Adds metadata about the output file.

addTrack

abstract int addTrack(Format format)

Adds a track of the given media format.

Parameters
Format format

The Format of the track.

Returns
int

A track id for this track, which should be passed to writeSampleData.

Throws
androidx.media3.muxer.MuxerException

If the muxer encounters a problem while adding the track.

close

abstract void close()

Closes the file.

The muxer cannot be used anymore once this method returns.

Throws
androidx.media3.muxer.MuxerException

If the muxer fails to finish writing the output.

writeSampleData

abstract void writeSampleData(
    int trackId,
    ByteBuffer byteBuffer,
    MediaCodec.BufferInfo bufferInfo
)

Writes encoded sample data.

Parameters
int trackId

The track id, previously returned by addTrack.

ByteBuffer byteBuffer

A buffer containing the sample data to write to the container.

MediaCodec.BufferInfo bufferInfo

The BufferInfo of the sample.

Throws
androidx.media3.muxer.MuxerException

If the muxer fails to write the sample.