@UnstableApi
interface Muxer

Known direct subclasses
DefaultMuxer

A default Muxer implementation.

FragmentedMp4Muxer

A muxer for creating a fragmented MP4 file.

InAppMuxer

Muxer implementation that uses an Mp4Muxer or FragmentedMp4Muxer.

Mp4Muxer

A muxer for creating an MP4 container file.


The muxer for producing media container files.

Summary

Nested types

interface Muxer.Factory

Factory for muxers.

Thrown when a muxer failure occurs.

A token representing an added track.

Public functions

Unit

Adds metadata about the output file.

Muxer.TrackToken!
addTrack(format: Format!)

Adds a track of the given media format.

Unit

Closes the file.

Unit
writeSampleData(
    trackToken: Muxer.TrackToken!,
    byteBuffer: ByteBuffer!,
    bufferInfo: MediaCodec.BufferInfo!
)

Writes encoded sample data.

Public functions

addMetadataEntry

fun addMetadataEntry(metadataEntry: Metadata.Entry!): Unit

Adds metadata about the output file.

addTrack

fun addTrack(format: Format!): Muxer.TrackToken!

Adds a track of the given media format.

Parameters
format: Format!

The Format of the track.

Returns
Muxer.TrackToken!

The TrackToken for this track, which should be passed to writeSampleData.

Throws
androidx.media3.muxer.Muxer.MuxerException

If the muxer encounters a problem while adding the track.

close

fun close(): Unit

Closes the file.

The muxer cannot be used anymore once this method returns.

Throws
androidx.media3.muxer.Muxer.MuxerException

If the muxer fails to finish writing the output.

writeSampleData

fun writeSampleData(
    trackToken: Muxer.TrackToken!,
    byteBuffer: ByteBuffer!,
    bufferInfo: MediaCodec.BufferInfo!
): Unit

Writes encoded sample data.

Parameters
trackToken: Muxer.TrackToken!

The TrackToken of the track, previously returned by addTrack.

byteBuffer: ByteBuffer!

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

bufferInfo: MediaCodec.BufferInfo!

The BufferInfo of the sample.

Throws
androidx.media3.muxer.Muxer.MuxerException

If the muxer fails to write the sample.