> 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)

*** ** * ** ***


```
public final class VideoEncoderConstraints.Builder
```

<br />

*** ** * ** ***

Builder for `VideoEncoderConstraints` instances.

## Summary

| ### Public constructors |
|---|
| `Builder(int width, int height, double frameRate)` Creates a new instance. |

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

## Public constructors

### Builder

```
public Builder(int width, int height, double frameRate)
```

Creates a new instance.

| Parameters |
|---|---|
| `int width` | The `width` in pixels. |
| `int height` | The `height` in pixels. |
| `double frameRate` | 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 methods

### build

```
public VideoEncoderConstraints build()
```

Builds a `VideoEncoderConstraints` instance.

### setAllowedCodecs

```
@CanIgnoreReturnValue
public VideoEncoderConstraints.Builder setAllowedCodecs(@C.VideoCodecFlags int allowedCodecs)
```

Sets the `allowed codecs`.

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

### setBFramesAllowed

```
@CanIgnoreReturnValue
public VideoEncoderConstraints.Builder setBFramesAllowed(boolean bFramesAllowed)
```

Sets whether `B-frames are allowed`.

The default is `true`.

### setBitDepth

```
@CanIgnoreReturnValue
public VideoEncoderConstraints.Builder setBitDepth(int bitDepth)
```

Sets the `bit depth`.

The default is `8`.

### setBitrateMode

```
@CanIgnoreReturnValue
public VideoEncoderConstraints.Builder setBitrateMode(@VideoEncoderSettings.BitrateMode int bitrateMode)
```

Sets the `bitrate mode`.

The default is `BITRATE_MODE_VBR`.

### setKeyFrameIntervalSeconds

```
@CanIgnoreReturnValue
public VideoEncoderConstraints.Builder setKeyFrameIntervalSeconds(float keyFrameIntervalSeconds)
```

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
public VideoEncoderConstraints.Builder setMaxBitrate(int maxBitrate)
```

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
public VideoEncoderConstraints.Builder setResolution(int width, int height, double frameRate)
```

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
public VideoEncoderConstraints.Builder setTargetQuality(double targetQuality)
```

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. |