VideoCapture.Builder


class VideoCapture.Builder<T : VideoOutput?> : ExtendableBuilder


Builder for a VideoCapture.

Parameters
<T : VideoOutput?>

the type of VideoOutput

Summary

Public constructors

Builder(videoOutput: T)

Creates a new Builder object.

Public functions

VideoCapture<T!>

Builds a VideoCapture from the current state.

VideoCapture.Builder<T!>

Sets the DynamicRange.

VideoCapture.Builder<T!>
setMirrorMode(mirrorMode: Int)

Sets the mirror mode.

VideoCapture.Builder<T!>
setTargetFrameRate(targetFrameRate: Range<Int!>)

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

VideoCapture.Builder<T!>

Sets the rotation of the intended target for images from this configuration.

VideoCapture.Builder<T!>

Enable video stabilization.

Public constructors

Builder

Added in 1.3.0
Builder(videoOutput: T)

Creates a new Builder object.

Public functions

build

Added in 1.3.0
fun build(): VideoCapture<T!>

Builds a VideoCapture from the current state.

Returns
VideoCapture<T!>

A VideoCapture populated with the current state.

setDynamicRange

Added in 1.3.0
fun setDynamicRange(dynamicRange: DynamicRange): VideoCapture.Builder<T!>

Sets the DynamicRange.

The dynamic range specifies how the range of colors, highlights and shadows that are captured by the video producer are displayed on a display. Some dynamic ranges will allow the video to make full use of the extended range of brightness of a display when the video is played back.

The supported dynamic ranges for video capture depend on the capabilities of the camera and the VideoOutput. The supported dynamic ranges can normally be queried through the specific video output. For example, the available dynamic ranges for the Recorder video output can be queried through the androidx.camera.video.VideoCapabilities returned by getVideoCapabilities via getSupportedDynamicRanges.

It is possible to choose a high dynamic range (HDR) with unspecified encoding by providing HDR_UNSPECIFIED_10_BIT.

If the dynamic range is not provided, the returned video capture use case will use a default of SDR.

Returns
VideoCapture.Builder<T!>

The current Builder.

See also
DynamicRange

setMirrorMode

Added in 1.3.0
fun setMirrorMode(mirrorMode: Int): VideoCapture.Builder<T!>

Sets the mirror mode.

Valid values include: MIRROR_MODE_OFF, MIRROR_MODE_ON and MIRROR_MODE_ON_FRONT_ONLY. If not set, it defaults to MIRROR_MODE_OFF.

This API only changes the mirroring behavior on VideoCapture, but does not affect other UseCases. If the application wants to be consistent with the default Preview behavior where the rear camera is not mirrored but the front camera is mirrored, then MIRROR_MODE_ON_FRONT_ONLY is recommended.

Parameters
mirrorMode: Int

The mirror mode of the intended target.

Returns
VideoCapture.Builder<T!>

The current Builder.

setTargetFrameRate

Added in 1.3.0
fun setTargetFrameRate(targetFrameRate: Range<Int!>): VideoCapture.Builder<T!>

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

This target will be used as a part of the heuristics for the algorithm that determines the final frame rate range and resolution of all concurrently bound use cases.

It is not guaranteed that this target frame rate will be the final range, as other use cases as well as frame rate restrictions of the device may affect the outcome of the algorithm that chooses the actual frame rate.

For supported frame rates, see getSupportedFrameRateRanges.

Parameters
targetFrameRate: Range<Int!>

the target frame rate range.

setTargetRotation

Added in 1.3.0
fun setTargetRotation(rotation: Int): VideoCapture.Builder<T!>

Sets the rotation of the intended target for images from this configuration.

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

In general, it is best to additionally set the target rotation dynamically on the use case. See setTargetRotation for additional documentation.

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.

For a Recorder output, 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

The rotation of the intended target.

Returns
VideoCapture.Builder<T!>

The current Builder.

setVideoStabilizationEnabled

Added in 1.4.0
fun setVideoStabilizationEnabled(enabled: Boolean): VideoCapture.Builder<T!>

Enable video stabilization.

It will enable stabilization for the video capture use case. However, it is not guaranteed the stabilization will be enabled for the preview use case. If you want to enable preview stabilization, use setPreviewStabilizationEnabled instead.

Preview stabilization, where streams are stabilized with the same quality of stabilization for Preview and VideoCapture use cases, is enabled. This mode aims to give clients a 'what you see is what you get' effect. In this mode, the FoV reduction will be a maximum of 20 % both horizontally and vertically (10% from left, right, top, bottom) for the given zoom ratio / crop region. The resultant FoV will also be the same across all use cases (that have the same aspect ratio). This is the tradeoff between video stabilization and preview stabilization.

It is recommended to query the device capability via isStabilizationSupported before enabling this feature, otherwise HAL error might be thrown.

If both preview stabilization and video stabilization are enabled or disabled, the final result will be

Preview VideoCapture Result
ON ON Both Preview and VideoCapture will be stabilized, VideoCapture quality might be worse than only VideoCapture stabilized
ON OFF None of Preview and VideoCapture will be stabilized
ON NOT SPECIFIED Both Preview and VideoCapture will be stabilized
OFF ON None of Preview and VideoCapture will be stabilized
OFF OFF None of Preview and VideoCapture will be stabilized
OFF NOT SPECIFIED None of Preview and VideoCapture will be stabilized
NOT SPECIFIED ON Only VideoCapture will be stabilized, Preview might be stabilized depending on devices
NOT SPECIFIED OFF None of Preview and VideoCapture will be stabilized
Parameters
enabled: Boolean

True if enable, otherwise false.

Returns
VideoCapture.Builder<T!>

the current Builder.