VideoCapture


class VideoCapture<T : VideoOutput?> : UseCase


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 VideoOutput. withOutput can be used to create a VideoCapture instance associated with the given VideoOutput. Take Recorder as an example,

        VideoCapture<Recorder> videoCapture
                = VideoCapture.withOutput(new Recorder.Builder().build());
Then getOutput can retrieve the Recorder instance.
Parameters
<T : VideoOutput?>

the type of VideoOutput

Summary

Nested types

Builder for a VideoCapture.

Public functions

DynamicRange

Returns the dynamic range.

Int

Returns the mirror mode.

T

Gets the VideoOutput associated with this VideoCapture.

Range<Int!>

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

Int

Returns the desired rotation of the output video.

Boolean

Returns whether video stabilization is enabled.

Unit

Sets the desired rotation of the output video.

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

Create a VideoCapture associated with the given VideoOutput.

Inherited functions

From androidx.camera.core.UseCase
java-static Int
snapToSurfaceRotation(orientation: @IntRange(from = 0, to = 359) Int)

A utility function that can convert the orientation degrees of OrientationEventListener to the nearest Surface rotation.

Public functions

getDynamicRange

Added in 1.3.0
fun getDynamicRange(): DynamicRange

Returns the dynamic range.

The dynamic range is set by setDynamicRange. If the dynamic range set is not a fully defined dynamic range, such as 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 setDynamicRange, this will return the default of SDR

Returns
DynamicRange

the dynamic range set for this VideoCapture use case.

getMirrorMode

Added in 1.3.0
fun getMirrorMode(): Int

Returns the mirror mode.

The mirror mode is set by setMirrorMode. If not set, it defaults to MIRROR_MODE_OFF.

Returns
Int

The mirror mode of the intended target.

getOutput

Added in 1.1.0
fun getOutput(): T

Gets the VideoOutput associated with this VideoCapture.

Returns
T

the value provided to withOutput used to create this VideoCapture.

getTargetFrameRate

Added in 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 setTargetFrameRate If not set, the target frame rate defaults to the value of FRAME_RATE_RANGE_UNSPECIFIED

Returns
Range<Int!>

The target frame rate of the intended target.

getTargetRotation

Added in 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 setTargetRotation or dynamically by calling setTargetRotation. If not set, the target rotation defaults to the value of getRotation of the default display at the time the use case is bound.

Returns
Int

The rotation of the intended target.

isVideoStabilizationEnabled

Added in 1.4.0
fun isVideoStabilizationEnabled(): Boolean

Returns whether video stabilization is enabled.

setTargetRotation

Added in 1.3.0
fun setTargetRotation(rotation: Int): Unit

Sets the desired rotation of the output video.

Valid values include: ROTATION_0, ROTATION_90, ROTATION_180, ROTATION_270. Rotation values are relative to the "natural" rotation, ROTATION_0.

While rotation can also be set via setTargetRotation, using setTargetRotation(int) allows the target rotation to be set dynamically.

In general, it is best to use an android.view.OrientationEventListener 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 android.view.OrientationEventListener, without re-creating the use case. snapToSurfaceRotation is a helper function to convert the orientation of the android.view.OrientationEventListener to a rotation value. See snapToSurfaceRotation for more information and sample code.

If not set, the target rotation will default to the value of 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 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: Int

Desired rotation of the output video, expressed as one of ROTATION_0, ROTATION_90, ROTATION_180, or ROTATION_270.

toString

fun toString(): String

withOutput

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

Create a VideoCapture associated with the given VideoOutput.

Throws
java.lang.NullPointerException

if videoOutput is null.