@UnstableApi
public 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

public interface Muxer.Factory

Factory for muxers.

public final class Muxer.MuxerException extends Exception

Thrown when a muxing failure occurs.

Public methods

abstract void

Adds Metadata about the output file.

abstract int
addTrack(Format format)

Adds a track with the specified format.

abstract long

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

abstract void
release(boolean forCancellation)

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

abstract void
writeSampleData(
    int trackIndex,
    ByteBuffer data,
    long presentationTimeUs,
    @C.BufferFlags int flags
)

Writes the specified sample.

Public methods

addMetadata

abstract void addMetadata(Metadata metadata)

Adds Metadata about the output file.

addTrack

abstract int addTrack(Format format)

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

abstract long getMaxDelayBetweenSamplesMs()

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

abstract void release(boolean forCancellation)

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

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

Parameters
boolean forCancellation

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

abstract void writeSampleData(
    int trackIndex,
    ByteBuffer data,
    long presentationTimeUs,
    @C.BufferFlags int flags
)

Writes the specified sample.

Parameters
int trackIndex

The index of the track, previously returned by addTrack.

ByteBuffer data

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

long presentationTimeUs

The presentation time of the sample in microseconds.

@C.BufferFlags int flags

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.