# Codec

# Codec

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/transformer/Codec "View this page in Java")

<br />

```
@UnstableApi
interface Codec
```

<br />

Known direct subclasses  
[DefaultCodec](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec)  

|---------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DefaultCodec](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec) | A default[Codec](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec)implementation that uses[MediaCodec](https://developer.android.com/reference/android/media/MediaCodec.html). |

*** ** * ** ***

Provides a layer of abstraction for interacting with decoders and encoders.

[DecoderInputBuffers](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer)are used as both decoders' and encoders' input buffers.

## Summary

|                                                                                                                    ### Nested types                                                                                                                    |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `interface `[Codec.DecoderFactory](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec.DecoderFactory) A factory for[decoder](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec)instances. |
| `interface `[Codec.EncoderFactory](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec.EncoderFactory) A factory for[encoder](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec)instances. |

|                                             ### Public functions                                             |
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!`                    | [getConfigurationFormat](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getConfigurationFormat())`()` Returns the[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)used for configuring the`Codec`.                                                                                          |
| [Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!`                    | [getInputFormat](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getInputFormat())`()` Returns the[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)accepted by the codec.                                                                                                                    |
| [Surface](https://developer.android.com/reference/android/view/Surface.html)`!`                              | [getInputSurface](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getInputSurface())`()` Returns the input[Surface](https://developer.android.com/reference/android/view/Surface.html)of an underlying video encoder.                                                                                                             |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                  | [getMaxPendingFrameCount](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getMaxPendingFrameCount())`()` Returns the maximum number of frames that may be pending in the output`Codec`at a time, or`5`as a default value.                                                                                                         |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`                         | [getName](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getName())`()` Returns the name of the underlying codec.                                                                                                                                                                                                                |
| [ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html)`?`                            | [getOutputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getOutputBuffer())`()` Returns the current output[ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html), or`null`if unavailable.                                                                                                        |
| [MediaCodec.BufferInfo](https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html)`?` | [getOutputBufferInfo](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getOutputBufferInfo())`()` Returns the[BufferInfo](https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html)associated with the current output buffer, or`null`if there is no output buffer available.                              |
| [Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`?`                    | [getOutputFormat](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getOutputFormat())`()` Returns the current output format, or`null`if unavailable.                                                                                                                                                                               |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                          | [isEnded](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#isEnded())`()` Returns whether the`Codec`'s output stream has ended, and no more data can be dequeued.                                                                                                                                                                  |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                          | [maybeDequeueInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#maybeDequeueInputBuffer(androidx.media3.decoder.DecoderInputBuffer))`(inputBuffer: `[DecoderInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer)`!)` Dequeues a writable input buffer, if available. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                | [queueInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#queueInputBuffer(androidx.media3.decoder.DecoderInputBuffer))`(inputBuffer: `[DecoderInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer)`!)` Queues an input buffer to the`Codec`.                         |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                | [release](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#release())`()` Releases the`Codec`.                                                                                                                                                                                                                                     |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                | [releaseOutputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#releaseOutputBuffer(boolean))`(render: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Releases the current output buffer.                                                                                          |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                | [releaseOutputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#releaseOutputBuffer(long))`(renderPresentationTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Renders and releases the current output buffer.                                                                     |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                | [signalEndOfInputStream](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#signalEndOfInputStream())`()` Signals end-of-stream on input to a video encoder.                                                                                                                                                                         |

## Public functions

### getConfigurationFormat

```
fun getConfigurationFormat(): Format!
```

Returns the[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)used for configuring the`Codec`.

The configuration[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)is the input[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)used by the[DecoderFactory](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec.DecoderFactory)or output[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)used by the[EncoderFactory](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec.EncoderFactory)for selecting and configuring the underlying decoder or encoder.  

### getInputFormat

```
fun getInputFormat(): Format!
```

Returns the[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)accepted by the codec.

This format may differ from the[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)returned by[getConfigurationFormat](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getConfigurationFormat()), depending on the underlying codec and configuration format requested.  

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/androidx/media3/transformer/ExportException) | If the underlying decoder or encoder encounters a problem. |

### getInputSurface

```
fun getInputSurface(): Surface!
```

Returns the input[Surface](https://developer.android.com/reference/android/view/Surface.html)of an underlying video encoder.

This method must only be called on video encoders because audio/video decoders and audio encoders don't use a[Surface](https://developer.android.com/reference/android/view/Surface.html)as input.  

### getMaxPendingFrameCount

```
fun getMaxPendingFrameCount(): Int
```

Returns the maximum number of frames that may be pending in the output`Codec`at a time, or`5`as a default value.  

### getName

```
fun getName(): String!
```

Returns the name of the underlying codec.  

### getOutputBuffer

```
fun getOutputBuffer(): ByteBuffer?
```

Returns the current output[ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html), or`null`if unavailable.

This method must not be called on video decoders because they must output to a[Surface](https://developer.android.com/reference/android/view/Surface.html).  

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/androidx/media3/transformer/ExportException) | If the underlying decoder or encoder encounters a problem. |

### getOutputBufferInfo

```
fun getOutputBufferInfo(): MediaCodec.BufferInfo?
```

Returns the[BufferInfo](https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html)associated with the current output buffer, or`null`if there is no output buffer available.

This method returns`null`if and only if[getOutputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getOutputBuffer())returns null.  

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/androidx/media3/transformer/ExportException) | If the underlying decoder or encoder encounters a problem. |

### getOutputFormat

```
fun getOutputFormat(): Format?
```

Returns the current output format, or`null`if unavailable.  

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/androidx/media3/transformer/ExportException) | If the underlying decoder or encoder encounters a problem. |

### isEnded

```
fun isEnded(): Boolean
```

Returns whether the`Codec`'s output stream has ended, and no more data can be dequeued.  

### maybeDequeueInputBuffer

```
fun maybeDequeueInputBuffer(inputBuffer: DecoderInputBuffer!): Boolean
```

Dequeues a writable input buffer, if available.

This method must not be called from video encoders because they must use a[Surface](https://developer.android.com/reference/android/view/Surface.html)to receive input.  

|                                                            Parameters                                                             |
|-----------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `inputBuffer: `[DecoderInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer)`!` | The buffer where the dequeued buffer data is stored, at[inputBuffer.data](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer#data()). |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|----------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether an input buffer is ready to be used. |

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/androidx/media3/transformer/ExportException) | If the underlying decoder or encoder encounters a problem. |

### queueInputBuffer

```
fun queueInputBuffer(inputBuffer: DecoderInputBuffer!): Unit
```

Queues an input buffer to the`Codec`. No buffers may be queued after[end of stream](https://developer.android.com/reference/kotlin/androidx/media3/decoder/Buffer#isEndOfStream())buffer has been queued.

This method must not be called from video encoders because they must use a[Surface](https://developer.android.com/reference/android/view/Surface.html)to receive input.  

|                                                            Parameters                                                             |
|-----------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|
| `inputBuffer: `[DecoderInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer)`!` | The[input buffer](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer). |

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/androidx/media3/transformer/ExportException) | If the underlying decoder or encoder encounters a problem. |

### release

```
fun release(): Unit
```

Releases the`Codec`.  

### releaseOutputBuffer

```
fun releaseOutputBuffer(render: Boolean): Unit
```

Releases the current output buffer.

Only set`render`to`true`when the`Codec`is a video decoder. Setting`render`to`true`will first render the buffer to the output surface. In this case, the surface will release the buffer back to the`Codec`once it is no longer used/displayed.

This should be called after the buffer has been processed. The next output buffer will not be available until the current output buffer has been released.

Calling this method with`render`set to`true`is equivalent to calling[releaseOutputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#releaseOutputBuffer(long))with the presentation timestamp of the[output buffer info](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getOutputBufferInfo()).  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| `render: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether the buffer needs to be rendered to the output[Surface](https://developer.android.com/reference/android/view/Surface.html). |

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/androidx/media3/transformer/ExportException) | If the underlying decoder or encoder encounters a problem. |

### releaseOutputBuffer

```
fun releaseOutputBuffer(renderPresentationTimeUs: Long): Unit
```

Renders and releases the current output buffer.

This method must only be called on video decoders.

This method will first render the buffer to the output surface. The surface will then release the buffer back to the`Codec`once it is no longer used/displayed.

This should be called after the buffer has been processed. The next output buffer will not be available until the current output buffer has been released.  

|                                                Parameters                                                 |
|-----------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------|
| `renderPresentationTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The presentation timestamp to associate with this buffer, in microseconds. |

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/androidx/media3/transformer/ExportException) | If the underlying decoder or encoder encounters a problem. |

### signalEndOfInputStream

```
fun signalEndOfInputStream(): Unit
```

Signals end-of-stream on input to a video encoder.

This method must only be called on video encoders because they must use a[Surface](https://developer.android.com/reference/android/view/Surface.html)as input. For audio/video decoders or audio encoders, the[BUFFER_FLAG_END_OF_STREAM](https://developer.android.com/reference/kotlin/androidx/media3/common/C#BUFFER_FLAG_END_OF_STREAM())flag should be set on the last input buffer[queued](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#queueInputBuffer(androidx.media3.decoder.DecoderInputBuffer)).  

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/androidx/media3/transformer/ExportException) | If the underlying video encoder encounters a problem. |