> Documentation index: https://developer.android.com/reference/llms.txt

# WebmMuxer

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

*** ** * ** ***


```
@UnstableApi
class WebmMuxer : 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 |
|---|
| `class WebmMuxer.Builder` A builder for `WebmMuxer` instances. |

| ### Public functions |
|---|---|
| `Unit` | `addMetadataEntry(metadataEntry: Metadata.Entry!)` Adds `metadata` about the output file. |
| `Int` | `addTrack(format: Format!)` Adds a track of the given media format. |
| `Unit` | `close()` Closes the file. |
| `Unit` | `writeSampleData( trackId: Int, byteBuffer: ByteBuffer!, bufferInfo: BufferInfo! )` Writes encoded sample data. |

### Inherited functions

From [java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable.md.txt) `abstract Unit` `close()`

## Public functions

### addMetadataEntry

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

Adds `metadata` about the output file.

| Parameters |
|---|---|
| `metadataEntry: Metadata.Entry!` | The `Metadata.Entry` to add. |

| Throws |
|---|---|
| `java.lang.IllegalStateException` | If the muxer is closed. |

### addTrack

```
fun addTrack(format: Format!): Int
```

Adds a track of the given media format.

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

| Parameters |
|---|---|
| `format: Format!` | The `Format` of the track. |

| Returns |
|---|---|
| `Int` | A track id for this track, which should be passed to `writeSampleData`. |

| Throws |
|---|---|
| `androidx.media3.muxer.MuxerException` | If the muxer encounters a problem while adding the track. |
| `java.lang.IllegalStateException` | If the muxer is closed. |

### close

```
fun close(): Unit
```

Closes the file.

The muxer cannot be used anymore once this method is called, even if it throws. Implementations must make further calls to this method a no-op and, once it has been called, must throw an `IllegalStateException` from all other methods.

| Throws |
|---|---|
| `androidx.media3.muxer.MuxerException` | If the muxer fails to finish writing the output. |

### writeSampleData

```
fun writeSampleData(
    trackId: Int,
    byteBuffer: ByteBuffer!,
    bufferInfo: BufferInfo!
): Unit
```

Writes encoded sample data.

| Parameters |
|---|---|
| `trackId: Int` | The track id for which this sample is being written. |
| `byteBuffer: ByteBuffer!` | The encoded sample. The muxer takes ownership of the buffer if ` sample copying` is disabled. Otherwise, the position of the buffer is updated but the caller retains ownership. |
| `bufferInfo: BufferInfo!` | The `BufferInfo` related to this sample. |

| Throws |
|---|---|
| `androidx.media3.muxer.MuxerException` | If an error occurs while writing data to the output file. |