# VideoCapture

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/VideoCapture.java+class:androidx.camera.video.VideoCapture) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

*** ** * ** ***


```
class VideoCapture<T : VideoOutput?> : UseCase
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.camera.core.UseCase](https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase) ||
|   | ↳ | [androidx.camera.video.VideoCapture](https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture) |

*** ** * ** ***

A use case that provides camera stream suitable for video application.

VideoCapture is used to create a camera stream suitable for a video application such as recording a high-quality video to a file. The camera stream is used by the extended classes of `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoOutput`. `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#withOutput(T)` can be used to create a VideoCapture instance associated with the given VideoOutput. Take `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder` as an example,

```kotlin
        VideoCapture<Recorder> videoCapture
                = VideoCapture.withOutput(new Recorder.Builder().build());
```
Then `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#getOutput()` can retrieve the Recorder instance.

| Parameters |
|---|---|
| `<T : https://developer.android.com/reference/kotlin/androidx/camera/video/VideoOutput?>` | the type of VideoOutput |

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture.Builder<T : https://developer.android.com/reference/kotlin/androidx/camera/video/VideoOutput?> : https://developer.android.com/reference/kotlin/androidx/camera/core/ExtendableBuilder, https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase.InteropConfigurable<https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture.Builder<T!>!>` Builder for a `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture`. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/DynamicRange` | `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#getDynamicRange()()` Returns the dynamic range. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#getMirrorMode()()` Returns the mirror mode. |
| `T` | `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#getOutput()()` Gets the `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoOutput` associated with this VideoCapture. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/ResolutionInfo?` | `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#getResolutionInfo()()` Returns information about the selected resolution. |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Quality?` | `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#getSelectedQuality()()` Returns the selected Quality. |
| `https://developer.android.com/reference/android/util/Range.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html!>` | `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#getTargetFrameRate()()` Returns the target frame rate range, in frames per second, for the associated VideoCapture use case. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#getTargetRotation()()` Returns the desired rotation of the output video. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#isVideoStabilizationEnabled()()` Returns whether video stabilization is enabled. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#setMirrorMode(int)(mirrorMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the mirror mode. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#setTargetRotation(int)(rotation: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the desired rotation of the output video. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#toString()()` |
| `java-static https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture<T!>` | `<T : https://developer.android.com/reference/kotlin/androidx/camera/video/VideoOutput?> https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#withOutput(T)(videoOutput: T)` Create a VideoCapture associated with the given `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoOutput`. |

### Inherited functions

From [androidx.camera.core.UseCase](https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase) `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase#snapToSurfaceRotation(int)(orientation: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 359) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

A utility function that can convert the orientation degrees of `https://developer.android.com/reference/android/view/OrientationEventListener.html` to the nearest `https://developer.android.com/reference/android/view/Surface.html` rotation.

## Public functions

### getDynamicRange

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

```
fun getDynamicRange(): DynamicRange
```

Returns the dynamic range.

The dynamic range is set by `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture.Builder#setDynamicRange(androidx.camera.core.DynamicRange)`. If the dynamic range set is not a fully defined dynamic range, such as `https://developer.android.com/reference/kotlin/androidx/camera/core/DynamicRange#HDR_UNSPECIFIED_10_BIT()`, then it will be returned just as provided, and will not be returned as a fully defined dynamic range.

If the dynamic range was not provided to `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture.Builder#setDynamicRange(androidx.camera.core.DynamicRange)`, this will return the default of `https://developer.android.com/reference/kotlin/androidx/camera/core/DynamicRange#SDR()`

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/DynamicRange` | the dynamic range set for this `VideoCapture` use case. |

### getMirrorMode

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

```
fun getMirrorMode(): Int
```

Returns the mirror mode.

The mirror mode is set by `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture.Builder#setMirrorMode(int)`. If not set, it defaults to `https://developer.android.com/reference/kotlin/androidx/camera/core/MirrorMode#MIRROR_MODE_OFF()`.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The mirror mode of the intended target. |

### getOutput

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

```
fun getOutput(): T
```

Gets the `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoOutput` associated with this VideoCapture.

| Returns |
|---|---|
| `T` | the value provided to `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#withOutput(T)` used to create this VideoCapture. |

### getResolutionInfo

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

```
fun getResolutionInfo(): ResolutionInfo?
```

Returns information about the selected resolution.

Note that the `https://developer.android.com/reference/kotlin/androidx/camera/core/ResolutionInfo#getResolution()` might not be the same as the resolution of the recorded video because the video might have been rotated according to the camera sensor orientation and the target rotation, and/or have been cropped according to the `https://developer.android.com/reference/kotlin/androidx/camera/core/ViewPort` settings. The recorded video resolution can be determined by applying the `https://developer.android.com/reference/kotlin/androidx/camera/core/ResolutionInfo#getRotationDegrees()` to the size of `https://developer.android.com/reference/kotlin/androidx/camera/core/ResolutionInfo#getCropRect()`.

The resolution information may change if:

- The use case is unbound and then rebound.
- `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#setTargetRotation(int)` is called to change the target rotation.

If changes occur, the application should call `getResolutionInfo()` again to get the latest `https://developer.android.com/reference/kotlin/androidx/camera/core/ResolutionInfo`.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/ResolutionInfo?` | the resolution information if the use case is bound by the `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/ProcessCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,androidx.camera.core.UseCase...)` API, or ` null` if the use case is not yet bound. |

### getSelectedQuality

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

```
fun getSelectedQuality(): Quality?
```

Returns the selected Quality.

The selected Quality represents the final quality level chosen for the stream. The selected Quality will be one of the specified qualities from the `https://developer.android.com/reference/kotlin/androidx/camera/video/QualitySelector` provided by the associated `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoOutput`. If `https://developer.android.com/reference/kotlin/androidx/camera/video/Quality#HIGHEST()` or `https://developer.android.com/reference/kotlin/androidx/camera/video/Quality#LOWEST()` is specified in the selector, it will be resolved to an actual Quality value. Even if the stream is later cropped (e.g., by using a `https://developer.android.com/reference/kotlin/androidx/camera/core/ViewPort`), this value represents the original quality level of the stream.

This method will return the selected Quality only after the use case is bound using `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/ProcessCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,androidx.camera.core.UseCase...)`. Otherwise, it will return null. The selected Quality may change if the use case is unbound and then rebound.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Quality?` | The selected Quality if the use case is bound, or null otherwise. |

### getTargetFrameRate

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

```
fun getTargetFrameRate(): Range<Int!>
```

Returns the target frame rate range, in frames per second, for the associated VideoCapture use case.

The target frame rate can be set prior to constructing a VideoCapture using `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture.Builder#setTargetFrameRate(android.util.Range<java.lang.Integer>)` If not set, the target frame rate defaults to the value of

| Returns |
|---|---|
| `https://developer.android.com/reference/android/util/Range.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html!>` | The target frame rate of the intended target. |

### getTargetRotation

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

```
fun getTargetRotation(): Int
```

Returns the desired rotation of the output video.

The rotation can be set prior to constructing a VideoCapture using `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture.Builder#setTargetRotation(int)` or dynamically by calling `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture#setTargetRotation(int)`. If not set, the target rotation defaults to the value of `https://developer.android.com/reference/android/view/Display.html#getRotation()` of the default display at the time the use case is bound.

Value is one of the following:

- `Surface.ROTATION_0`
- `Surface.ROTATION_90`
- `Surface.ROTATION_180`
- `Surface.ROTATION_270`

<br />

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The rotation of the intended target. |

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

### isVideoStabilizationEnabled

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

```
fun isVideoStabilizationEnabled(): Boolean
```

Returns whether video stabilization is enabled.

### setMirrorMode

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

```
fun setMirrorMode(mirrorMode: Int): Unit
```

Sets the mirror mode.

Valid values include: `https://developer.android.com/reference/kotlin/androidx/camera/core/MirrorMode#MIRROR_MODE_OFF()`, `https://developer.android.com/reference/kotlin/androidx/camera/core/MirrorMode#MIRROR_MODE_ON()` and `https://developer.android.com/reference/kotlin/androidx/camera/core/MirrorMode#MIRROR_MODE_ON_FRONT_ONLY()`. If not set, it defaults to `https://developer.android.com/reference/kotlin/androidx/camera/core/MirrorMode#MIRROR_MODE_OFF()`.

| Parameters |
|---|---|
| `mirrorMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The mirror mode. |

### setTargetRotation

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

```
fun setTargetRotation(rotation: Int): Unit
```

Sets the desired rotation of the output video.

Valid values include: `https://developer.android.com/reference/android/view/Surface.html#ROTATION_0`, `https://developer.android.com/reference/android/view/Surface.html#ROTATION_90`, `https://developer.android.com/reference/android/view/Surface.html#ROTATION_180`, `https://developer.android.com/reference/android/view/Surface.html#ROTATION_270`. Rotation values are relative to the "natural" rotation, `https://developer.android.com/reference/android/view/Surface.html#ROTATION_0`.

While rotation can also be set via `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture.Builder#setTargetRotation(int)`, using `setTargetRotation(int)` allows the target rotation to be set dynamically.

In general, it is best to use an `https://developer.android.com/reference/android/view/OrientationEventListener.html` to set the target rotation. This way, the rotation output will indicate which way is down for a given video. This is important since display orientation may be locked by device default, user setting, or app configuration, and some devices may not transition to a reverse-portrait display orientation. In these cases, set target rotation dynamically according to the `https://developer.android.com/reference/android/view/OrientationEventListener.html`, without re-creating the use case. `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase#snapToSurfaceRotation(int)` is a helper function to convert the orientation of the `https://developer.android.com/reference/android/view/OrientationEventListener.html` to a rotation value. See `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase#snapToSurfaceRotation(int)` for more information and sample code.

If not set, the target rotation will default to the value of `https://developer.android.com/reference/android/view/Display.html#getRotation()` of the default display at the time the use case is bound. To return to the default value, set the value to

```kotlin
context.getSystemService(WindowManager.class).getDefaultDisplay().getRotation();
```

For a `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder` output, calling this method has no effect on the ongoing recording, but will affect recordings started after calling this method. The final rotation degrees of the video, including the degrees set by this method and the orientation of the camera sensor, will be reflected by several possibilities, 1) the rotation degrees is written into the video metadata, 2) the video content is directly rotated, 3) both, i.e. rotation metadata and rotated video content which combines to the target rotation. CameraX will choose a strategy according to the use case.

| Parameters |
|---|---|
| `rotation: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Desired rotation of the output video, expressed as one of `https://developer.android.com/reference/android/view/Surface.html#ROTATION_0`, `https://developer.android.com/reference/android/view/Surface.html#ROTATION_90`, `https://developer.android.com/reference/android/view/Surface.html#ROTATION_180`, or `https://developer.android.com/reference/android/view/Surface.html#ROTATION_270`. Value is one of the following: - `Surface.ROTATION_0` - `Surface.ROTATION_90` - `Surface.ROTATION_180` - `Surface.ROTATION_270` <br /> |

### toString

```
fun toString(): String
```

### withOutput

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

```
java-static fun <T : VideoOutput?> withOutput(videoOutput: T): VideoCapture<T!>
```

Create a VideoCapture associated with the given `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoOutput`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `videoOutput` is null. |