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

# VideoEncoderConstraints.Builder

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

*** ** * ** ***


```
class VideoEncoderConstraints.Builder
```

<br />

*** ** * ** ***

Builder for `VideoEncoderConstraints` instances.

## Summary

| ### Public constructors |
|---|
| `Builder(width: Int, height: Int, frameRate: Double)` Creates a new instance. |

| ### Public functions |
|---|---|
| `VideoEncoderConstraints!` | `build()` Builds a `VideoEncoderConstraints` instance. |
| `VideoEncoderConstraints.Builder!` | `@CanIgnoreReturnValue setAllowedCodecs(@C.VideoCodecFlags allowedCodecs: Int)` Sets the `allowed codecs`. |
| `VideoEncoderConstraints.Builder!` | `@CanIgnoreReturnValue setBFramesAllowed(bFramesAllowed: Boolean)` Sets whether `B-frames are allowed`. |
| `VideoEncoderConstraints.Builder!` | `@CanIgnoreReturnValue setBitDepth(bitDepth: Int)` Sets the `bit depth`. |
| `VideoEncoderConstraints.Builder!` | `@CanIgnoreReturnValue setBitrateMode(@VideoEncoderSettings.BitrateMode bitrateMode: Int)` Sets the `bitrate mode`. |
| `VideoEncoderConstraints.Builder!` | `@CanIgnoreReturnValue setKeyFrameIntervalSeconds(keyFrameIntervalSeconds: Float)` Sets the `key-frame interval`, in seconds. |
| `VideoEncoderConstraints.Builder!` | `@CanIgnoreReturnValue setMaxBitrate(maxBitrate: Int)` Sets the `maximum bitrate`, in bits per second, or `NO_VALUE` to clear it. |
| `VideoEncoderConstraints.Builder!` | `@CanIgnoreReturnValue setResolution(width: Int, height: Int, frameRate: Double)` Sets the `width` in pixels, `height` in pixels, and `frame rate` in frames per second. |
| `VideoEncoderConstraints.Builder!` | `@CanIgnoreReturnValue setTargetQuality(targetQuality: Double)` Sets the `target quality`, or `NO_VALUE` to clear it. |

## Public constructors

### Builder

```
Builder(width: Int, height: Int, frameRate: Double)
```

Creates a new instance.

| Parameters |
|---|---|
| `width: Int` | The `width` in pixels. |
| `height: Int` | The `height` in pixels. |
| `frameRate: Double` | The `frame rate` in frames per second. |

| Throws |
|---|---|
| `java.lang.IllegalArgumentException` | if `width` or `height` is not positive, or if `frameRate` is not positive and finite. |

## Public functions

### build

```
fun build(): VideoEncoderConstraints!
```

Builds a `VideoEncoderConstraints` instance.

### setAllowedCodecs

```
@CanIgnoreReturnValue
fun setAllowedCodecs(@C.VideoCodecFlags allowedCodecs: Int): VideoEncoderConstraints.Builder!
```

Sets the `allowed codecs`.

The default is `C.VIDEO_CODEC_FLAG_H264 | C.VIDEO_CODEC_FLAG_H265 |
C.VIDEO_CODEC_FLAG_AV1`.

### setBFramesAllowed

```
@CanIgnoreReturnValue
fun setBFramesAllowed(bFramesAllowed: Boolean): VideoEncoderConstraints.Builder!
```

Sets whether `B-frames are allowed`.

The default is `true`.

### setBitDepth

```
@CanIgnoreReturnValue
fun setBitDepth(bitDepth: Int): VideoEncoderConstraints.Builder!
```

Sets the `bit depth`.

The default is `8`.

### setBitrateMode

```
@CanIgnoreReturnValue
fun setBitrateMode(@VideoEncoderSettings.BitrateMode bitrateMode: Int): VideoEncoderConstraints.Builder!
```

Sets the `bitrate mode`.

The default is `BITRATE_MODE_VBR`.

### setKeyFrameIntervalSeconds

```
@CanIgnoreReturnValue
fun setKeyFrameIntervalSeconds(keyFrameIntervalSeconds: Float): VideoEncoderConstraints.Builder!
```

Sets the `key-frame interval`, in seconds.

The default is one second.

| Throws |
|---|---|
| `java.lang.IllegalArgumentException` | if `keyFrameIntervalSeconds` is not positive and finite. |

### setMaxBitrate

```
@CanIgnoreReturnValue
fun setMaxBitrate(maxBitrate: Int): VideoEncoderConstraints.Builder!
```

Sets the `maximum bitrate`, in bits per second, or `NO_VALUE` to clear it.

The default is `NO_VALUE`.

| Throws |
|---|---|
| `java.lang.IllegalArgumentException` | if `maxBitrate` is not positive and is not `NO_VALUE`. |
| `java.lang.IllegalStateException` | if `targetQuality` is already set. |

### setResolution

```
@CanIgnoreReturnValue
fun setResolution(width: Int, height: Int, frameRate: Double): VideoEncoderConstraints.Builder!
```

Sets the `width` in pixels, `height` in pixels, and `frame rate` in frames per second.

| Throws |
|---|---|
| `java.lang.IllegalArgumentException` | if `width` or `height` is not positive, or if `frameRate` is not positive and finite. |

### setTargetQuality

```
@CanIgnoreReturnValue
fun setTargetQuality(targetQuality: Double): VideoEncoderConstraints.Builder!
```

Sets the `target quality`, or `NO_VALUE` to clear it.

The default is `QUALITY_LEVEL_NEAR_LOSSLESS` when neither `targetQuality` nor `maxBitrate` is set.

| Throws |
|---|---|
| `java.lang.IllegalArgumentException` | if `targetQuality` is not in (0, 100\] and is not `NO_VALUE`. |
| `java.lang.IllegalStateException` | if `maxBitrate` is already set. |