public final class

VideoCapture.Builder<T extends VideoOutput>

extends java.lang.Object

implements UseCaseConfig.Builder<VideoCapture, VideoCaptureConfig, VideoCapture.Builder>, ImageOutputConfig.Builder<VideoCapture.Builder>, ImageInputConfig.Builder<VideoCapture.Builder>, ThreadConfig.Builder<VideoCapture.Builder>

 java.lang.Object

↳androidx.camera.video.VideoCapture.Builder<T>

Overview

Builder for a VideoCapture.

Summary

Constructors
publicBuilder(VideoOutput videoOutput)

Creates a new Builder object.

Methods
public VideoCapture<VideoOutput>build()

Builds a VideoCapture from the current state.

public static VideoCapture.Builder<VideoOutput>fromConfig(VideoCaptureConfig<VideoOutput> configuration)

Generates a Builder from another Config object

public MutableConfiggetMutableConfig()

public VideoCaptureConfig<VideoOutput>getUseCaseConfig()

public VideoCapture.Builder<VideoOutput>setBackgroundExecutor(java.util.concurrent.Executor executor)

Sets the default executor that will be used for background tasks.

public VideoCapture.Builder<VideoOutput>setCaptureOptionUnpacker(CaptureConfig.OptionUnpacker optionUnpacker)

public VideoCapture.Builder<VideoOutput>setCaptureType(UseCaseConfigFactory.CaptureType captureType)

public VideoCapture.Builder<VideoOutput>setCustomOrderedResolutions(java.util.List<Size> resolutions)

public VideoCapture.Builder<VideoOutput>setDefaultCaptureConfig(CaptureConfig captureConfig)

public VideoCapture.Builder<VideoOutput>setDefaultResolution(Size resolution)

Sets the default resolution of the intended target from this configuration.

public VideoCapture.Builder<VideoOutput>setDefaultSessionConfig(SessionConfig sessionConfig)

public VideoCapture.Builder<VideoOutput>setDynamicRange(DynamicRange dynamicRange)

Sets the DynamicRange.

public VideoCapture.Builder<VideoOutput>setHighResolutionDisabled(boolean disabled)

public VideoCapture.Builder<VideoOutput>setMaxResolution(Size resolution)

public VideoCapture.Builder<VideoOutput>setMirrorMode(int mirrorMode)

Sets the mirror mode.

public VideoCapture.Builder<VideoOutput>setResolutionSelector(ResolutionSelector resolutionSelector)

public VideoCapture.Builder<VideoOutput>setSessionOptionUnpacker(SessionConfig.OptionUnpacker optionUnpacker)

public VideoCapture.Builder<VideoOutput>setSupportedResolutions(java.util.List<> resolutions)

public VideoCapture.Builder<VideoOutput>setSurfaceOccupancyPriority(int priority)

public VideoCapture.Builder<VideoOutput>setSurfaceProcessingForceEnabled()

Forces surface processing to be enabled.

public VideoCapture.Builder<VideoOutput>setTargetAspectRatio(int aspectRatio)

setTargetAspectRatio is not supported on VideoCapture

public VideoCapture.Builder<VideoOutput>setTargetClass(java.lang.Class<VideoCapture> targetClass)

public VideoCapture.Builder<VideoOutput>setTargetFrameRate(<any> targetFrameRate)

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

public VideoCapture.Builder<VideoOutput>setTargetName(java.lang.String targetName)

Sets the name of the target object being configured, used only for debug logging.

public VideoCapture.Builder<VideoOutput>setTargetResolution(Size resolution)

setTargetResolution is not supported on VideoCapture

public VideoCapture.Builder<VideoOutput>setTargetRotation(int rotation)

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

public VideoCapture.Builder<VideoOutput>setVideoOutput(VideoOutput videoOutput)

Sets the associated VideoOutput.

public VideoCapture.Builder<VideoOutput>setVideoStabilizationEnabled(boolean enabled)

Enable video stabilization.

public VideoCapture.Builder<VideoOutput>setZslDisabled(boolean disabled)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(VideoOutput videoOutput)

Creates a new Builder object.

Methods

public static VideoCapture.Builder<VideoOutput> fromConfig(VideoCaptureConfig<VideoOutput> configuration)

Generates a Builder from another Config object

Parameters:

configuration: An immutable configuration to pre-populate this builder.

Returns:

The new Builder.

public MutableConfig getMutableConfig()

public VideoCaptureConfig<VideoOutput> getUseCaseConfig()

public VideoCapture.Builder<VideoOutput> setVideoOutput(VideoOutput videoOutput)

Sets the associated VideoOutput.

public VideoCapture<VideoOutput> build()

Builds a VideoCapture from the current state.

Returns:

A VideoCapture populated with the current state.

public VideoCapture.Builder<VideoOutput> setTargetClass(java.lang.Class<VideoCapture> targetClass)

public VideoCapture.Builder<VideoOutput> setTargetName(java.lang.String targetName)

Sets the name of the target object being configured, used only for debug logging.

The name should be a value that can uniquely identify an instance of the object being configured.

If not set, the target name will default to an unique name automatically generated with the class canonical name and random UUID.

Parameters:

targetName: A unique string identifier for the instance of the class being configured.

Returns:

the current Builder.

public VideoCapture.Builder<VideoOutput> setTargetAspectRatio(int aspectRatio)

setTargetAspectRatio is not supported on VideoCapture

To set aspect ratio, see Recorder.Builder.setAspectRatio(int).

public VideoCapture.Builder<VideoOutput> setTargetRotation(int rotation)

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

Valid values include: , , , . Rotation values are relative to the "natural" rotation, .

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

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

Returns:

The current Builder.

See also: VideoCapture.setTargetRotation(int)

public VideoCapture.Builder<VideoOutput> setMirrorMode(int mirrorMode)

Sets the mirror mode.

Valid values include: MirrorMode.MIRROR_MODE_OFF, MirrorMode.MIRROR_MODE_ON and MirrorMode.MIRROR_MODE_ON_FRONT_ONLY. If not set, it defaults to MirrorMode.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 MirrorMode.MIRROR_MODE_ON_FRONT_ONLY is recommended.

Parameters:

mirrorMode: The mirror mode of the intended target.

Returns:

The current Builder.

public VideoCapture.Builder<VideoOutput> setTargetResolution(Size resolution)

setTargetResolution is not supported on VideoCapture

To set resolution, see Recorder.Builder.setQualitySelector(QualitySelector).

public VideoCapture.Builder<VideoOutput> setDefaultResolution(Size resolution)

Sets the default resolution of the intended target from this configuration.

Parameters:

resolution: The default resolution to choose from supported output sizes list.

Returns:

The current Builder.

public VideoCapture.Builder<VideoOutput> setMaxResolution(Size resolution)

public VideoCapture.Builder<VideoOutput> setSupportedResolutions(java.util.List<> resolutions)

public VideoCapture.Builder<VideoOutput> setCustomOrderedResolutions(java.util.List<Size> resolutions)

public VideoCapture.Builder<VideoOutput> setResolutionSelector(ResolutionSelector resolutionSelector)

public VideoCapture.Builder<VideoOutput> setDynamicRange(DynamicRange dynamicRange)

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 VideoCapabilities returned by Recorder.getVideoCapabilities(CameraInfo) via VideoCapabilities.getSupportedDynamicRanges().

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

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

Returns:

The current Builder.

See also: DynamicRange

public VideoCapture.Builder<VideoOutput> setBackgroundExecutor(java.util.concurrent.Executor executor)

Sets the default executor that will be used for background tasks.

If not set, the background executor will default to an automatically generated java.util.concurrent.Executor.

Parameters:

executor: The executor which will be used for background tasks.

Returns:

the current Builder.

public VideoCapture.Builder<VideoOutput> setDefaultSessionConfig(SessionConfig sessionConfig)

public VideoCapture.Builder<VideoOutput> setDefaultCaptureConfig(CaptureConfig captureConfig)

public VideoCapture.Builder<VideoOutput> setSessionOptionUnpacker(SessionConfig.OptionUnpacker optionUnpacker)

public VideoCapture.Builder<VideoOutput> setCaptureOptionUnpacker(CaptureConfig.OptionUnpacker optionUnpacker)

public VideoCapture.Builder<VideoOutput> setSurfaceOccupancyPriority(int priority)

public VideoCapture.Builder<VideoOutput> setZslDisabled(boolean disabled)

public VideoCapture.Builder<VideoOutput> setHighResolutionDisabled(boolean disabled)

public VideoCapture.Builder<VideoOutput> setTargetFrameRate(<any> targetFrameRate)

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 CameraInfo.getSupportedFrameRateRanges().

Parameters:

targetFrameRate: the target frame rate range.

public VideoCapture.Builder<VideoOutput> setVideoStabilizationEnabled(boolean enabled)

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 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 VideoCapabilities.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: True if enable, otherwise false.

Returns:

the current Builder.

See also: VideoCapabilities.isStabilizationSupported()

public VideoCapture.Builder<VideoOutput> setCaptureType(UseCaseConfigFactory.CaptureType captureType)

public VideoCapture.Builder<VideoOutput> setSurfaceProcessingForceEnabled()

Forces surface processing to be enabled.

Typically, surface processing is automatically enabled only when required for a specific effect. However, calling this method will force it to be enabled even if no effect is required. Surface processing creates additional processing through the OpenGL pipeline, affecting performance and memory usage. Camera service may treat the surface differently, potentially impacting video quality and stabilization. So it is generally not recommended to enable it.

One example where it might be useful is to work around device compatibility issues. For example, UHD video recording might not work on some devices, but enabling surface processing could work around the issue.