public final class

Recorder.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.camera.video.Recorder.Builder

Overview

Builder class for Recorder objects.

Summary

Constructors
publicBuilder()

Constructor for Recorder.Builder.

Methods
public Recorderbuild()

Builds the Recorder instance.

public Recorder.BuildersetAspectRatio(int aspectRatio)

Sets the video aspect ratio of this Recorder.

public Recorder.BuildersetAudioSource(int source)

Sets the audio source for recordings with audio enabled.

public Recorder.BuildersetExecutor(java.util.concurrent.Executor executor)

Sets the java.util.concurrent.Executor that runs the Recorder background task.

public Recorder.BuildersetQualitySelector(QualitySelector qualitySelector)

Sets the QualitySelector of this Recorder.

public Recorder.BuildersetTargetVideoEncodingBitRate(int bitrate)

Sets the intended video encoding bitrate for recording.

public Recorder.BuildersetVideoCapabilitiesSource(int videoCapabilitiesSource)

Sets the video capabilities source.

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

Constructors

public Builder()

Constructor for Recorder.Builder.

Creates a builder which is pre-populated with appropriate default configuration options.

Methods

public Recorder.Builder setExecutor(java.util.concurrent.Executor executor)

Sets the java.util.concurrent.Executor that runs the Recorder background task.

The executor is used to run the Recorder tasks, the audio encoding and the video encoding. For the best performance, it's recommended to be an java.util.concurrent.Executor that is capable of running at least two tasks concurrently, such as a java.util.concurrent.ThreadPoolExecutor backed by 2 or more threads.

If not set, the Recorder will be run on the IO executor internally managed by CameraX.

public Recorder.Builder setQualitySelector(QualitySelector qualitySelector)

Sets the QualitySelector of this Recorder.

The provided quality selector is used to select the resolution of the recording depending on the resolutions supported by the camera and codec capabilities.

If no quality selector is provided, the default is Recorder.DEFAULT_QUALITY_SELECTOR.

Recorder.Builder.setAspectRatio(int) can be used with to specify the intended video aspect ratio.

See also: QualitySelector, Recorder.Builder.setAspectRatio(int)

public Recorder.Builder setVideoCapabilitiesSource(int videoCapabilitiesSource)

Sets the video capabilities source.

Possible values include Recorder.VIDEO_CAPABILITIES_SOURCE_CAMCORDER_PROFILE and Recorder.VIDEO_CAPABILITIES_SOURCE_CODEC_CAPABILITIES. The final selected quality from the QualitySelector will be affected by the source. See the document of the constants for more detail.

Recorder.VIDEO_CAPABILITIES_SOURCE_CAMCORDER_PROFILE will be the default if not set.

Parameters:

videoCapabilitiesSource: the video capabilities source.

Returns:

the builder instance.

public Recorder.Builder setTargetVideoEncodingBitRate(int bitrate)

Sets the intended video encoding bitrate for recording.

The target video encoding bitrate attempts to keep the actual video encoding bitrate close to the requested bitrate. Bitrate may vary during a recording depending on the scene being recorded.

Additional checks will be performed on the requested bitrate to make sure the specified bitrate is applicable, and sometimes the passed bitrate will be changed internally to ensure the video recording can proceed smoothly based on the capabilities of the platform.

This API only affects the video stream and should not be considered the target for the entire recording. The audio stream's bitrate is not affected by this API.

If this method isn't called, an appropriate bitrate for normal video recording is selected by default. Only call this method if a custom bitrate is desired.

Parameters:

bitrate: the target video encoding bitrate in bits per second.

public Recorder.Builder setAspectRatio(int aspectRatio)

Sets the video aspect ratio of this Recorder.

The final video resolution will be based on the input aspect ratio and the QualitySelector in Recorder.Builder.setQualitySelector(QualitySelector). Both settings will be respected. For example, if the aspect ratio is 4:3 and the preferred quality in QualitySelector is HD, then a HD quality resolution with 4:3 aspect ratio such as 1280x960 or 960x720 will be used. CameraX will choose an appropriate one depending on the resolutions supported by the camera and the codec capabilities. With this setting, no other aspect ratios (such as 16:9) will be used, nor any other qualities (such as UHD, FHD and SD). If no resolution with the settings can be found, it will fail to bind VideoCapture. Therefore, a recommended way is to provide a flexible QualitySelector if there is no specific video quality requirement, such as the setting in Recorder.DEFAULT_QUALITY_SELECTOR.

The default value is AspectRatio.RATIO_DEFAULT. If no aspect ratio is set, the selected resolution will be based only on the QualitySelector.

Parameters:

aspectRatio: the aspect ratio. Possible values are AspectRatio.RATIO_4_3 and AspectRatio.RATIO_16_9.

See also: Recorder.Builder.setQualitySelector(QualitySelector)

public Recorder.Builder setAudioSource(int source)

Sets the audio source for recordings with audio enabled.

This will only set the source of audio for recordings, but audio must still be enabled on a per-recording basis with PendingRecording.withAudioEnabled() before starting the recording.

Parameters:

source: The audio source to use. One of AudioSpec.SOURCE_AUTO or AudioSpec.SOURCE_CAMCORDER. Default is AudioSpec.SOURCE_AUTO.

public Recorder build()

Builds the Recorder instance.

The {code build()} method can be called multiple times, generating a new Recorder instance each time. The returned instance is configured with the options set on this builder.