# Recorder.Builder

Artifact: [androidx.camera:camera-video](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/video/Recorder.java+class:androidx.camera.video.Recorder.Builder) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

*** ** * ** ***


```
class Recorder.Builder
```

<br />

*** ** * ** ***

Builder class for `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder` objects.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#Builder()()` Constructor for `Recorder.Builder`. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder` | `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#build()()` Builds the `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder` instance. |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setAspectRatio(int)(aspectRatio: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the video aspect ratio of this Recorder. |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setAudioMimeType(java.lang.String)(mimeType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Sets the desired audio MIME type for the recording. |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setExecutor(java.util.concurrent.Executor)(executor: https://developer.android.com/reference/java/util/concurrent/Executor.html)` Sets the `https://developer.android.com/reference/java/util/concurrent/Executor.html` that runs the Recorder background task. |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setQualitySelector(androidx.camera.video.QualitySelector)(qualitySelector: https://developer.android.com/reference/kotlin/androidx/camera/video/QualitySelector)` Sets the `https://developer.android.com/reference/kotlin/androidx/camera/video/QualitySelector` of this Recorder. |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setTargetAudioChannelCount(int)(channelCount: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the intended audio channel count for recording. |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setTargetAudioEncodingBitRate(int)(bitrate: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the target audio encoding bitrate of this Recorder. |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setTargetVideoEncodingBitRate(int)(bitrate: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the intended video encoding bitrate for recording. |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setVideoCapabilitiesSource(int)(videoCapabilitiesSource: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the video capabilities source. |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setVideoMimeType(java.lang.String)(mimeType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Sets the desired video MIME type for the recording. |

## Public constructors

### Builder

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
Builder()
```

Constructor for `Recorder.Builder`.

Creates a builder which is pre-populated with appropriate default configuration options.

## Public functions

### build

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
fun build(): Recorder
```

Builds the `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder` instance.

The {code build()} method can be called multiple times, generating a new `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder` instance each time. The returned instance is configured with the options set on this builder.

### setAspectRatio

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
fun setAspectRatio(aspectRatio: Int): Recorder.Builder
```

Sets the video aspect ratio of this Recorder.

The final video resolution will be based on the input aspect ratio and the QualitySelector in `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setQualitySelector(androidx.camera.video.QualitySelector)`. Both settings will be respected. For example, if the aspect ratio is 4:3 and the preferred quality in QualitySelector is HD, then a HD quality resolution with 4:3 aspect ratio such as 1280x960 or 960x720 will be used. CameraX will choose an appropriate one depending on the resolutions supported by the camera and the codec capabilities. With this setting, no other aspect ratios (such as 16:9) will be used, nor any other qualities (such as UHD, FHD and SD). If no resolution with the settings can be found, it will fail to bind VideoCapture. Therefore, a recommended way is to provide a flexible QualitySelector if there is no specific video quality requirement, such as the setting in `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#DEFAULT_QUALITY_SELECTOR()`.

The default value is `https://developer.android.com/reference/kotlin/androidx/camera/core/AspectRatio#RATIO_DEFAULT()`. If no aspect ratio is set, the selected resolution will be based only on the QualitySelector.

| Parameters |
|---|---|
| `aspectRatio: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the aspect ratio. Possible values are `https://developer.android.com/reference/kotlin/androidx/camera/core/AspectRatio#RATIO_4_3()` and `https://developer.android.com/reference/kotlin/androidx/camera/core/AspectRatio#RATIO_16_9()`. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setQualitySelector(androidx.camera.video.QualitySelector)` |   |

### setAudioMimeType

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
fun setAudioMimeType(mimeType: String): Recorder.Builder
```

Sets the desired audio MIME type for the recording.

If not set, CameraX automatically chooses an appropriate audio codec based on device capabilities. Only call this method if a specific override is required.

The supported formats will depend on the device capability and can be queried by `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#getSupportedAudioMimeTypes()` at runtime. The Recorder is designed to support the following MIME types:

- AAC (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_AUDIO_AAC`)
- AMR-NB (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_AUDIO_AMR_NB`)
- AMR-WB (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_AUDIO_AMR_WB`)
- Opus (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_AUDIO_OPUS`)
- Vorbis (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_AUDIO_VORBIS`)

If a MIME type supported by Recorder is provided, but that MIME type is not supported by the device, an `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` will be thrown when binding the `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture` use case that uses this recorder.

If a custom audio MIME type is set but a video MIME type is left as unspecified, CameraX will automatically select a compatible video codec and container format based on the chosen audio format.

| Parameters |
|---|---|
| `mimeType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The desired audio MIME type. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | This `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` instance. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `mimeType` is not an audio format supported by the Recorder (listed above). |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#getSupportedAudioMimeTypes()` |   |

### setExecutor

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
fun setExecutor(executor: Executor): Recorder.Builder
```

Sets the `https://developer.android.com/reference/java/util/concurrent/Executor.html` that runs the Recorder background task.

The executor is used to run the Recorder tasks, the audio encoding and the video encoding. For the best performance, it's recommended to be an `https://developer.android.com/reference/java/util/concurrent/Executor.html` that is capable of running at least two tasks concurrently, such as a `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html` backed by 2 or more threads.

If not set, the Recorder will be run on the IO executor internally managed by CameraX.

### setQualitySelector

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
fun setQualitySelector(qualitySelector: QualitySelector): Recorder.Builder
```

Sets the `https://developer.android.com/reference/kotlin/androidx/camera/video/QualitySelector` of this Recorder.

The provided quality selector is used to select the resolution of the recording depending on the resolutions supported by the camera and codec capabilities.

If no quality selector is provided, the default is `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#DEFAULT_QUALITY_SELECTOR()`.

`https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setAspectRatio(int)` can be used with to specify the intended video aspect ratio.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/video/QualitySelector` |   |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder#setAspectRatio(int)` |   |

### setTargetAudioChannelCount

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
fun setTargetAudioChannelCount(channelCount: @IntRange(from = 1) Int): Recorder.Builder
```

Sets the intended audio channel count for recording.

Common values are 1 for mono and 2 for stereo. If the requested channel count is not supported by the device, CameraX will fall back to a supported channel count. If this method is not called, an appropriate default channel count will be selected.

| Parameters |
|---|---|
| `channelCount: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the target audio channel count. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | the builder instance. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `channelCount` is less than 1. |

### setTargetAudioEncodingBitRate

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
fun setTargetAudioEncodingBitRate(bitrate: @IntRange(from = 1) Int): Recorder.Builder
```

Sets the target audio encoding bitrate of this Recorder.

Additional checks will be performed on the requested `bitrate` to make sure the specified bitrate is applicable, and sometimes the passed bitrate will be changed internally to ensure the audio recording can proceed smoothly based on the capabilities of the platform.

This API only affects the audio stream and should not be considered the target for the entire recording. The video stream's bitrate is not affected by this API.

If this method isn't called, an appropriate bitrate for normal audio recording is selected by default. Only call this method if a custom bitrate is desired.

| Parameters |
|---|---|
| `bitrate: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the target audio encoding bitrate in bits per second. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if bitrate is 0 or less. |

### setTargetVideoEncodingBitRate

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
fun setTargetVideoEncodingBitRate(bitrate: @IntRange(from = 1) Int): Recorder.Builder
```

Sets the intended video encoding bitrate for recording.

The target video encoding bitrate attempts to keep the actual video encoding bitrate close to the requested `bitrate`. Bitrate may vary during a recording depending on the scene being recorded.

Additional checks will be performed on the requested `bitrate` to make sure the specified bitrate is applicable, and sometimes the passed bitrate will be changed internally to ensure the video recording can proceed smoothly based on the capabilities of the platform.

This API only affects the video stream and should not be considered the target for the entire recording. The audio stream's bitrate is not affected by this API.

If this method isn't called, an appropriate bitrate for normal video recording is selected by default. Only call this method if a custom bitrate is desired.

| Parameters |
|---|---|
| `bitrate: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the target video encoding bitrate in bits per second. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if bitrate is 0 or less. |

### setVideoCapabilitiesSource

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/camera#1.4.0)

```
fun setVideoCapabilitiesSource(videoCapabilitiesSource: Int): Recorder.Builder
```

Sets the video capabilities source.

Possible values include `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#VIDEO_CAPABILITIES_SOURCE_CAMCORDER_PROFILE()` and `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#VIDEO_CAPABILITIES_SOURCE_CODEC_CAPABILITIES()`. The final selected quality from the `https://developer.android.com/reference/kotlin/androidx/camera/video/QualitySelector` will be affected by the source. See the document of the constants for more detail.

`https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#VIDEO_CAPABILITIES_SOURCE_CAMCORDER_PROFILE()` will be the default if not set.

| Parameters |
|---|---|
| `videoCapabilitiesSource: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the video capabilities source. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | the builder instance. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if videoCapabilitiesSource is not one of the possible values. |

### setVideoMimeType

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
fun setVideoMimeType(mimeType: String): Recorder.Builder
```

Sets the desired video MIME type for the recording.

If not set, CameraX automatically chooses an appropriate video codec based on device capabilities. Only call this method if a specific override is required.

The supported formats will depend on the device capability and can be queried by `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#getSupportedVideoMimeTypes()` at runtime. The Recorder is designed to support the following MIME types:

- AV1 (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_VIDEO_AV1`)
- MPEG-4 (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_VIDEO_MPEG4`)
- H.263 (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_VIDEO_H263`)
- H.264 (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_VIDEO_AVC`)
- H.265 (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_VIDEO_HEVC`)
- VP8 (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_VIDEO_VP8`)
- VP9 (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_VIDEO_VP9`)
- APV (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_VIDEO_APV`)
- Dolby Vision (`https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_VIDEO_DOLBY_VISION`)

If a MIME type supported by Recorder is provided, but that MIME type is not supported by the device, an `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` will be thrown when binding the `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture` use case that uses this recorder.

If a custom video MIME type is set but an audio MIME type is left as unspecified, CameraX will automatically select a compatible audio codec and container format based on the chosen video format.

MIME type specific capabilities for a given camera, such as supported qualities and dynamic ranges, can be queried using `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#getVideoCapabilities(androidx.camera.core.CameraInfo,java.lang.String)`.

| Parameters |
|---|---|
| `mimeType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The desired video MIME type. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` | This `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.Builder` instance. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `mimeType` is not a video format supported by the Recorder (listed above). |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#getSupportedVideoMimeTypes()` |   |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#getVideoCapabilities(androidx.camera.core.CameraInfo,java.lang.String)` |   |