# EncoderFrameWriter

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

*** ** * ** ***


```
@RequiresApi(value = 33)
@ExperimentalApi
public class EncoderFrameWriter implements FrameWriter
```

<br />

*** ** * ** ***

An implementation of `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter` that uses an `https://developer.android.com/reference/android/media/ImageWriter.html` to forward frames to a `https://developer.android.com/reference/androidx/media3/transformer/DefaultCodec` via `https://developer.android.com/reference/android/view/Surface.html`. Sets the `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#USAGE_VIDEO_ENCODE` flag on the buffers.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/media3/transformer/EncoderFrameWriter.Listener` Listener for `https://developer.android.com/reference/androidx/media3/transformer/EncoderFrameWriter` events. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/transformer/EncoderFrameWriter#EncoderFrameWriter(androidx.media3.transformer.Codec.EncoderFactory,androidx.media3.transformer.EncoderFrameWriter.Listener,java.util.concurrent.Executor,android.os.Handler,android.media.metrics.LogSessionId)( https://developer.android.com/reference/androidx/media3/transformer/Codec.EncoderFactory encoderFactory, https://developer.android.com/reference/androidx/media3/transformer/EncoderFrameWriter.Listener listener, https://developer.android.com/reference/java/util/concurrent/Executor.html listenerExecutor, https://developer.android.com/reference/android/os/Handler.html imageReleaseHandler, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/media/metrics/LogSessionId.html logSessionId )` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/transformer/EncoderFrameWriter#close()()` Blocks until all resources are released. |
| `void` | `https://developer.android.com/reference/androidx/media3/transformer/EncoderFrameWriter#configure(androidx.media3.common.Format,long)(https://developer.android.com/reference/androidx/media3/common/Format format, @https://developer.android.com/reference/androidx/media3/common/video/Frame.Usage long usage)` Format and usage support can be `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter.Info#isSupported(androidx.media3.common.Format,long)` on the `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter.Info` before configuring. |
| `synchronized @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/video/AsyncFrame` | `https://developer.android.com/reference/androidx/media3/transformer/EncoderFrameWriter#dequeueInputFrame(java.util.concurrent.Executor,java.lang.Runnable)(https://developer.android.com/reference/java/util/concurrent/Executor.html wakeupExecutor, https://developer.android.com/reference/java/lang/Runnable.html wakeupListener)` Dequeues an `https://developer.android.com/reference/androidx/media3/common/video/AsyncFrame` storing a `https://developer.android.com/reference/androidx/media3/common/video/Frame` of the `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter#configure(androidx.media3.common.Format,long)` format and usage, and a `https://developer.android.com/reference/androidx/media3/common/video/SyncFenceWrapper` that must be waited on before filling the frame. |
| `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter.Info` | `https://developer.android.com/reference/androidx/media3/transformer/EncoderFrameWriter#getInfo()()` Returns the `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter.Info` for this FrameWriter. |
| `void` | `https://developer.android.com/reference/androidx/media3/transformer/EncoderFrameWriter#queueInputFrame(androidx.media3.common.video.Frame,androidx.media3.common.video.SyncFenceWrapper)( https://developer.android.com/reference/androidx/media3/common/video/Frame frame, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/video/SyncFenceWrapper writeCompleteFence )` Queues a filled frame for further processing. |
| `void` | `https://developer.android.com/reference/androidx/media3/transformer/EncoderFrameWriter#signalEndOfStream()()` Notifies this `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter` that the current stream has ended. |

| ### 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 constructors

### EncoderFrameWriter

```
public EncoderFrameWriter(
    Codec.EncoderFactory encoderFactory,
    EncoderFrameWriter.Listener listener,
    Executor listenerExecutor,
    Handler imageReleaseHandler,
    @Nullable LogSessionId logSessionId
)
```

## Public methods

### close

```
public void close()
```

Blocks until all resources are released.

### configure

```
public void configure(Format format, @Frame.Usage long usage)
```

Format and usage support can be `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter.Info#isSupported(androidx.media3.common.Format,long)` on the `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter.Info` before configuring.

Must be called before `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter#dequeueInputFrame(java.util.concurrent.Executor,java.lang.Runnable)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The format to configure. |
| `@https://developer.android.com/reference/androidx/media3/common/video/Frame.Usage long usage` | The `@FrameUsage` flags describing how the frame will be used. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if any frames are dequeued at the point this method is called. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the format or usage is unsupported. |

### dequeueInputFrame

```
synchronized public @Nullable AsyncFrame dequeueInputFrame(Executor wakeupExecutor, Runnable wakeupListener)
```

Dequeues an `https://developer.android.com/reference/androidx/media3/common/video/AsyncFrame` storing a `https://developer.android.com/reference/androidx/media3/common/video/Frame` of the `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter#configure(androidx.media3.common.Format,long)` format and usage, and a `https://developer.android.com/reference/androidx/media3/common/video/SyncFenceWrapper` that must be waited on before filling the frame.

The returned frame must be filled and `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter#queueInputFrame(androidx.media3.common.video.Frame,androidx.media3.common.video.SyncFenceWrapper)` back for processing.

If the `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter` is at capacity, this method returns null and will notify the listener when capacity is available, and it can be called again.

Only the most recent `wakeupListener` will be notified when capacity is available.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/Executor.html wakeupExecutor` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which the `wakeupListener` is invoked. |
| `https://developer.android.com/reference/java/lang/Runnable.html wakeupListener` | A `https://developer.android.com/reference/java/lang/Runnable.html` to be invoked when capacity becomes available. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/video/AsyncFrame` | The dequeued frame, or null if the writer is at capacity. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter#configure(androidx.media3.common.Format,long)` has not been called. |

### getInfo

```
public FrameWriter.Info getInfo()
```

Returns the `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter.Info` for this FrameWriter.

### queueInputFrame

```
public void queueInputFrame(
    Frame frame,
    @Nullable SyncFenceWrapper writeCompleteFence
)
```

Queues a filled frame for further processing.

The queued frame must have been previously `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter#dequeueInputFrame(java.util.concurrent.Executor,java.lang.Runnable)` from this writer.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/video/Frame frame` | The filled frame to queue. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/video/SyncFenceWrapper writeCompleteFence` | A `https://developer.android.com/reference/androidx/media3/common/video/SyncFenceWrapper` that will signal when the caller has finished writing to the frame, or `null` if the write was synchronous. |

### signalEndOfStream

```
public void signalEndOfStream()
```

Notifies this `https://developer.android.com/reference/androidx/media3/common/video/FrameWriter` that the current stream has ended.

More frames may be queued after calling this method, if the current stream changes.