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

*** ** * ** ***


```
public final class VideoCapture<T extends VideoOutput> extends UseCase
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.camera.core.UseCase](https://developer.android.com/reference/androidx/camera/core/UseCase) ||
|   | ↳ | [androidx.camera.video.VideoCapture](https://developer.android.com/reference/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/androidx/camera/video/VideoOutput`. `https://developer.android.com/reference/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/androidx/camera/video/Recorder` as an example,

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

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

## Summary

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

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/DynamicRange` | `https://developer.android.com/reference/androidx/camera/video/VideoCapture#getDynamicRange()()` Returns the dynamic range. |
| `int` | `https://developer.android.com/reference/androidx/camera/video/VideoCapture#getMirrorMode()()` Returns the mirror mode. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html T` | `https://developer.android.com/reference/androidx/camera/video/VideoCapture#getOutput()()` Gets the `https://developer.android.com/reference/androidx/camera/video/VideoOutput` associated with this VideoCapture. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/camera/core/ResolutionInfo` | `https://developer.android.com/reference/androidx/camera/video/VideoCapture#getResolutionInfo()()` Returns information about the selected resolution. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/camera/video/Quality` | `https://developer.android.com/reference/androidx/camera/video/VideoCapture#getSelectedQuality()()` Returns the selected Quality. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/util/Range.html<https://developer.android.com/reference/java/lang/Integer.html>` | `https://developer.android.com/reference/androidx/camera/video/VideoCapture#getTargetFrameRate()()` Returns the target frame rate range, in frames per second, for the associated VideoCapture use case. |
| `int` | `https://developer.android.com/reference/androidx/camera/video/VideoCapture#getTargetRotation()()` Returns the desired rotation of the output video. |
| `boolean` | `https://developer.android.com/reference/androidx/camera/video/VideoCapture#isVideoStabilizationEnabled()()` Returns whether video stabilization is enabled. |
| `void` | `https://developer.android.com/reference/androidx/camera/video/VideoCapture#setMirrorMode(int)(int mirrorMode)` Sets the mirror mode. |
| `void` | `https://developer.android.com/reference/androidx/camera/video/VideoCapture#setTargetRotation(int)(int rotation)` Sets the desired rotation of the output video. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/camera/video/VideoCapture#toString()()` |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/VideoCapture<T>` | `<T extends https://developer.android.com/reference/androidx/camera/video/VideoOutput> https://developer.android.com/reference/androidx/camera/video/VideoCapture#withOutput(T)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html T videoOutput)` Create a VideoCapture associated with the given `https://developer.android.com/reference/androidx/camera/video/VideoOutput`. |

### Inherited methods

From [androidx.camera.core.UseCase](https://developer.android.com/reference/androidx/camera/core/UseCase) `static int` `https://developer.android.com/reference/androidx/camera/core/UseCase#snapToSurfaceRotation(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 359) int orientation)`

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 methods

### getDynamicRange

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

```
public @NonNull DynamicRange getDynamicRange()
```

Returns the dynamic range.

The dynamic range is set by `https://developer.android.com/reference/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/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/androidx/camera/video/VideoCapture.Builder#setDynamicRange(androidx.camera.core.DynamicRange)`, this will return the default of `https://developer.android.com/reference/androidx/camera/core/DynamicRange#SDR()`

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/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)

```
public int getMirrorMode()
```

Returns the mirror mode.

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

| Returns |
|---|---|
| `int` | The mirror mode of the intended target. |

### getOutput

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

```
public @NonNull T getOutput()
```

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

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html T` | the value provided to `https://developer.android.com/reference/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)

```
public @Nullable ResolutionInfo getResolutionInfo()
```

Returns information about the selected resolution.

Note that the `https://developer.android.com/reference/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/androidx/camera/core/ViewPort` settings. The recorded video resolution can be determined by applying the `https://developer.android.com/reference/androidx/camera/core/ResolutionInfo#getRotationDegrees()` to the size of `https://developer.android.com/reference/androidx/camera/core/ResolutionInfo#getCropRect()`.

The resolution information may change if:

- The use case is unbound and then rebound.
- `https://developer.android.com/reference/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/androidx/camera/core/ResolutionInfo`.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/camera/core/ResolutionInfo` | the resolution information if the use case is bound by the `https://developer.android.com/reference/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)

```
public @Nullable Quality getSelectedQuality()
```

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/androidx/camera/video/QualitySelector` provided by the associated `https://developer.android.com/reference/androidx/camera/video/VideoOutput`. If `https://developer.android.com/reference/androidx/camera/video/Quality#HIGHEST()` or `https://developer.android.com/reference/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/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/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://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/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)

```
public @NonNull Range<Integer> getTargetFrameRate()
```

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/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://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/util/Range.html<https://developer.android.com/reference/java/lang/Integer.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)

```
public int getTargetRotation()
```

Returns the desired rotation of the output video.

The rotation can be set prior to constructing a VideoCapture using `https://developer.android.com/reference/androidx/camera/video/VideoCapture.Builder#setTargetRotation(int)` or dynamically by calling `https://developer.android.com/reference/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 |
|---|---|
| `int` | The rotation of the intended target. |

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

### isVideoStabilizationEnabled

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

```
public boolean isVideoStabilizationEnabled()
```

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)

```
public void setMirrorMode(int mirrorMode)
```

Sets the mirror mode.

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

| Parameters |
|---|---|
| `int mirrorMode` | The mirror mode. |

### setTargetRotation

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

```
public void setTargetRotation(int rotation)
```

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

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

For a `https://developer.android.com/reference/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 |
|---|---|
| `int rotation` | 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

```
public @NonNull String toString()
```

### withOutput

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

```
public static @NonNull VideoCapture<T> <T extends VideoOutput> withOutput(@NonNull T videoOutput)
```

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

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