@UnstableApi
interface Muxer

Known direct subclasses
DefaultMuxer

A default Muxer implementation.

InAppMuxer

Muxer implementation that uses a Mp4Muxer.


Abstracts media muxing operations.

Query whether sample MIME types are supported and add all tracks, then write sample data to mux samples. Once any sample data has been written, it is not possible to add tracks. After writing all sample data, release the instance to finish writing to the output and return any resources to the system.

Summary

Nested types

interface Muxer.Factory

Factory for muxers.

Thrown when a muxing failure occurs.

Public functions

Unit
addMetadata(metadata: Metadata!)

Adds Metadata about the output file.

Int
addTrack(format: Format!)

Adds a track with the specified format.

Long

Returns the maximum delay allowed between output samples, in milliseconds, or TIME_UNSET if there is no maximum.

Unit
release(forCancellation: Boolean)

Finishes writing the output and releases any resources associated with muxing.

Unit
writeSampleData(
    trackIndex: Int,
    data: ByteBuffer!,
    presentationTimeUs: Long,
    @C.BufferFlags flags: Int
)

Writes the specified sample.

Public functions

addMetadata

fun addMetadata(metadata: Metadata!): Unit

Adds Metadata about the output file.

addTrack

fun addTrack(format: Format!): Int

Adds a track with the specified format.

Parameters
format: Format!

The Format of the track.

Returns
Int

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

Throws
androidx.media3.transformer.Muxer.MuxerException

If the muxer encounters a problem while adding the track.

getMaxDelayBetweenSamplesMs

fun getMaxDelayBetweenSamplesMs(): Long

Returns the maximum delay allowed between output samples, in milliseconds, or TIME_UNSET if there is no maximum.

This is the maximum delay between samples of any track. They can be of the same or of different track types.

This value is used to abort the export when the maximum delay is reached. Note that there is no guarantee that the export will be aborted exactly at that time.

release

fun release(forCancellation: Boolean): Unit

Finishes writing the output and releases any resources associated with muxing.

The muxer cannot be used anymore once this method has been called.

Parameters
forCancellation: Boolean

Whether the reason for releasing the resources is the export cancellation.

Throws
androidx.media3.transformer.Muxer.MuxerException

If the muxer fails to finish writing the output and forCancellation is false.

writeSampleData

fun writeSampleData(
    trackIndex: Int,
    data: ByteBuffer!,
    presentationTimeUs: Long,
    @C.BufferFlags flags: Int
): Unit

Writes the specified sample.

Parameters
trackIndex: Int

The index of the track, previously returned by addTrack.

data: ByteBuffer!

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

presentationTimeUs: Long

The presentation time of the sample in microseconds.

@C.BufferFlags flags: Int

The C.BufferFlags associated with the data. Only BUFFER_FLAG_KEY_FRAME and BUFFER_FLAG_END_OF_STREAM are supported.

Throws
androidx.media3.transformer.Muxer.MuxerException

If the muxer fails to write the sample.