Recorder

public final class Recorder
extends Object implements VideoOutput

java.lang.Object
   ↳ androidx.camera.video.Recorder


An implementation of VideoOutput for starting video recordings that are saved to a File, ParcelFileDescriptor, or MediaStore.

A recorder can be used to save the video frames sent from the VideoCapture use case in common recording formats such as MPEG4.

Usage example of setting up VideoCapture with a recorder as output:

 ProcessCameraProvider cameraProvider = ...;
 CameraSelector cameraSelector = ...;
 ...
 // Create our preview to show on screen
 Preview preview = new Preview.Builder.build();
 // Create the video capture use case with a Recorder as the output
 VideoCapture videoCapture = VideoCapture.withOutput(new Recorder.Builder().build());

 // Bind use cases to Fragment/Activity lifecycle
 cameraProvider.bindToLifecycle(this, cameraSelector, preview, videoCapture);
 

Once the recorder is attached to a video source as a VideoOutput, e.g. using it to create a VideoCapture by calling VideoCapture.withOutput(VideoOutput), a new recording can be generated with one of the prepareRecording methods, such as prepareRecording(Context, MediaStoreOutputOptions). The PendingRecording class then can be used to adjust per-recording settings and to start the recording. It also requires passing a listener to PendingRecording.start(Executor, Consumer) to listen for VideoRecordEvents such as VideoRecordEvent.Start, VideoRecordEvent.Pause, VideoRecordEvent.Resume, and VideoRecordEvent.Finalize. This listener will also receive regular recording status updates via the VideoRecordEvent.Status event.

A recorder can also capture and save audio alongside video. The audio must be explicitly enabled with PendingRecording.withAudioEnabled() before starting the recording.

Summary

Nested classes

class Recorder.Builder

Builder class for Recorder objects. 

Fields

public static final QualitySelector DEFAULT_QUALITY_SELECTOR

Default quality selector for recordings.

Public methods

Executor getExecutor()

Returns the executor provided to the builder for this recorder.

QualitySelector getQualitySelector()

Gets the quality selector of this Recorder.

void onSurfaceRequested(SurfaceRequest request)

Called when a new Surface has been requested by a video frame producer.

PendingRecording prepareRecording(Context context, FileOutputOptions fileOutputOptions)

Prepares a recording that will be saved to a File.