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());
getOutput can retrieve the Recorder instance.
| Parameters | |
|---|---|
<T : VideoOutput?> |
the type of VideoOutput |
Summary
Nested types |
|---|
class VideoCapture.Builder<T : VideoOutput?> : ExtendableBuilderBuilder for a |
Public functions |
|
|---|---|
DynamicRange |
Returns the dynamic range. |
Int |
Returns the mirror mode. |
T |
Gets the |
ResolutionInfo? |
Returns information about the selected resolution. |
Quality? |
Returns the selected Quality. |
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 |
setTargetRotation(rotation: Int)Sets the desired rotation of the output video. |
String |
toString() |
java-static VideoCapture<T!> |
<T : VideoOutput?> withOutput(videoOutput: T)Create a VideoCapture associated with the given |
Inherited functions |
||
|---|---|---|
|
Public functions
getDynamicRange
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 |
getMirrorMode
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
fun getOutput(): T
Gets the VideoOutput associated with this VideoCapture.
| Returns | |
|---|---|
T |
the value provided to |
getResolutionInfo
fun getResolutionInfo(): ResolutionInfo?
Returns information about the selected resolution.
Note that the getResolution might not be the same as the resolution of the recorded video because the video might have been rotated according to the camera sensor orientation and the target rotation, and/or have been cropped according to the androidx.camera.core.ViewPort settings. The recorded video resolution can be determined by applying the getRotationDegrees to the size of getCropRect.
The resolution information may change if:
- The use case is unbound and then rebound.
setTargetRotationis called to change the target rotation.
If changes occur, the application should call getResolutionInfo() again to get the latest ResolutionInfo.
| Returns | |
|---|---|
ResolutionInfo? |
the resolution information if the use case is bound by the bindToLifecycle API, or |
getSelectedQuality
fun getSelectedQuality(): Quality?
Returns the selected Quality.
The selected Quality represents the final quality level chosen for the stream. The selected Quality will be one of the specified qualities from the QualitySelector provided by the associated VideoOutput. If HIGHEST or LOWEST is specified in the selector, it will be resolved to an actual Quality value. Even if the stream is later cropped (e.g., by using a ViewPort), this value represents the original quality level of the stream.
This method will return the selected Quality only after the use case is bound using bindToLifecycle. Otherwise, it will return null. The selected Quality may change if the use case is unbound and then rebound.
| Returns | |
|---|---|
Quality? |
The selected Quality if the use case is bound, or null otherwise. |
getTargetFrameRate
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
getTargetRotation
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. |
| See also | |
|---|---|
setTargetRotation |
isVideoStabilizationEnabled
fun isVideoStabilizationEnabled(): Boolean
Returns whether video stabilization is enabled.
setTargetRotation
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 |
withOutput
java-static fun <T : VideoOutput?> withOutput(videoOutput: T): VideoCapture<T!>
Create a VideoCapture associated with the given VideoOutput.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |