# Muxer

Artifact: [androidx.media3:media3-muxer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/muxer/Muxer.java+class:androidx.media3.muxer.Muxer)

*** ** * ** ***


```
@UnstableApi
public interface Muxer extends AutoCloseable
```

<br />

Known direct subclasses [AacMuxer](https://developer.android.com/reference/androidx/media3/muxer/AacMuxer), [DefaultMuxer](https://developer.android.com/reference/androidx/media3/transformer/DefaultMuxer), [FragmentedMp4Muxer](https://developer.android.com/reference/androidx/media3/muxer/FragmentedMp4Muxer), [FrameworkMuxer](https://developer.android.com/reference/androidx/media3/transformer/FrameworkMuxer), [InAppFragmentedMp4Muxer](https://developer.android.com/reference/androidx/media3/transformer/InAppFragmentedMp4Muxer), [InAppMp4Muxer](https://developer.android.com/reference/androidx/media3/transformer/InAppMp4Muxer), [Mp4Muxer](https://developer.android.com/reference/androidx/media3/muxer/Mp4Muxer), [OggMuxer](https://developer.android.com/reference/androidx/media3/muxer/OggMuxer), [WavMuxer](https://developer.android.com/reference/androidx/media3/muxer/WavMuxer), [WebmMuxer](https://developer.android.com/reference/androidx/media3/muxer/WebmMuxer)

|---|---|
| `https://developer.android.com/reference/androidx/media3/muxer/AacMuxer` | A muxer for creating an AAC (Advanced Audio Coding) container file. |
| `https://developer.android.com/reference/androidx/media3/transformer/DefaultMuxer` | A default `https://developer.android.com/reference/androidx/media3/muxer/Muxer` implementation. |
| `https://developer.android.com/reference/androidx/media3/muxer/FragmentedMp4Muxer` | A muxer for creating a fragmented MP4 file. |
| `https://developer.android.com/reference/androidx/media3/transformer/FrameworkMuxer` | `https://developer.android.com/reference/androidx/media3/muxer/Muxer` implementation that uses a `https://developer.android.com/reference/android/media/MediaMuxer.html`. |
| `https://developer.android.com/reference/androidx/media3/transformer/InAppFragmentedMp4Muxer` | `https://developer.android.com/reference/androidx/media3/muxer/Muxer` implementation that uses a `https://developer.android.com/reference/androidx/media3/muxer/FragmentedMp4Muxer`. |
| `https://developer.android.com/reference/androidx/media3/transformer/InAppMp4Muxer` | `https://developer.android.com/reference/androidx/media3/muxer/Muxer` implementation that uses an `https://developer.android.com/reference/androidx/media3/muxer/Mp4Muxer`. |
| `https://developer.android.com/reference/androidx/media3/muxer/Mp4Muxer` | A muxer for creating an MP4 container file. |
| `https://developer.android.com/reference/androidx/media3/muxer/OggMuxer` | A muxer for creating an Ogg container file. |
| `https://developer.android.com/reference/androidx/media3/muxer/WavMuxer` | A muxer for creating a WAV container file. |
| `https://developer.android.com/reference/androidx/media3/muxer/WebmMuxer` | A muxer for creating a WebM container file. |

*** ** * ** ***

A muxer for producing media container files.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/media3/muxer/Muxer.Factory` Factory for muxers. |

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/media3/muxer/Muxer#addMetadataEntry(androidx.media3.common.Metadata.Entry)(https://developer.android.com/reference/androidx/media3/common/Metadata.Entry metadataEntry)` Adds `https://developer.android.com/reference/androidx/media3/common/Metadata.Entry` about the output file. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/muxer/Muxer#addTrack(androidx.media3.common.Format)(https://developer.android.com/reference/androidx/media3/common/Format format)` Adds a track of the given media format. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/muxer/Muxer#close()()` Closes the file. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/muxer/Muxer#writeSampleData(int,java.nio.ByteBuffer,androidx.media3.muxer.BufferInfo)( int trackId, https://developer.android.com/reference/java/nio/ByteBuffer.html byteBuffer, https://developer.android.com/reference/androidx/media3/muxer/BufferInfo bufferInfo )` Writes encoded sample data. |

## Public methods

### addMetadataEntry

```
abstract void addMetadataEntry(Metadata.Entry metadataEntry)
```

Adds `https://developer.android.com/reference/androidx/media3/common/Metadata.Entry` about the output file.

### addTrack

```
abstract int addTrack(Format format)
```

Adds a track of the given media format.

All tracks must be added before any samples are written to any track.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The `https://developer.android.com/reference/androidx/media3/common/Format` of the track. |

| Returns |
|---|---|
| `int` | A track id for this track, which should be passed to `https://developer.android.com/reference/androidx/media3/muxer/Muxer#writeSampleData(int,java.nio.ByteBuffer,androidx.media3.muxer.BufferInfo)`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/muxer/MuxerException` | If the muxer fails to finish writing the output. |

### writeSampleData

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

Writes encoded sample data.

| Parameters |
|---|---|
| `int trackId` | The track id, previously returned by `https://developer.android.com/reference/androidx/media3/muxer/Muxer#addTrack(androidx.media3.common.Format)`. |
| `https://developer.android.com/reference/java/nio/ByteBuffer.html byteBuffer` | A buffer containing the sample data to write to the container. |
| `https://developer.android.com/reference/androidx/media3/muxer/BufferInfo bufferInfo` | The `https://developer.android.com/reference/androidx/media3/muxer/BufferInfo` of the sample. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/muxer/MuxerException` | If the muxer fails to write the sample. |