# WebmMuxer

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/WebmMuxer.java+class:androidx.media3.muxer.WebmMuxer)

*** ** * ** ***


```
@UnstableApi
public final class WebmMuxer implements Muxer
```

<br />

*** ** * ** ***

A muxer for creating a WebM container file.

Muxer supports muxing of:

- Video Codecs:
  - VP8
  - VP9
- Audio Codecs:
  - Opus
  - Vorbis

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/muxer/WebmMuxer.Builder` A builder for `https://developer.android.com/reference/androidx/media3/muxer/WebmMuxer` instances. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/muxer/WebmMuxer#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. |
| `int` | `https://developer.android.com/reference/androidx/media3/muxer/WebmMuxer#addTrack(androidx.media3.common.Format)(https://developer.android.com/reference/androidx/media3/common/Format format)` Adds a track of the given media format. |
| `void` | `https://developer.android.com/reference/androidx/media3/muxer/WebmMuxer#close()()` Closes the file. |
| `void` | `https://developer.android.com/reference/androidx/media3/muxer/WebmMuxer#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. |

| ### Inherited methods |
|---|
| From [java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable.html) |---|---| | `abstract void` | `https://developer.android.com/reference/java/lang/AutoCloseable.html#close()()` | |

## Public methods

### addMetadataEntry

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

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

### addTrack

```
public 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

```
public 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

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

Writes encoded sample data.

| Parameters |
|---|---|
| `int trackId` | The track id for which this sample is being written. |
| `https://developer.android.com/reference/java/nio/ByteBuffer.html byteBuffer` | The encoded sample. The muxer takes ownership of the buffer if `https://developer.android.com/reference/androidx/media3/muxer/WebmMuxer.Builder#setSampleCopyEnabled(boolean)` is disabled. Otherwise, the position of the buffer is updated but the caller retains ownership. |
| `https://developer.android.com/reference/androidx/media3/muxer/BufferInfo bufferInfo` | The `https://developer.android.com/reference/androidx/media3/muxer/BufferInfo` related to this sample. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/muxer/MuxerException` | If an error occurs while writing data to the output file. |