How to set the frame rate at VideoCapture

57 views
Skip to first unread message

yihao wu

unread,
Mar 31, 2023, 2:47:52 AMMar 31
to Android CameraX Discussion Group
hello, How to set the frame rate at androidx.camera.video.VideoCapture?

Trevor McGuire

unread,
Mar 31, 2023, 7:55:11 PMMar 31
to yihao wu, Android CameraX Discussion Group
When you call ProcessCameraProvider.bindToLifecycle(), it will return a Camera object to you. From that Camera object, you can get a CameraInfo, which is used for querying available frame rate ranges, and a CameraControl, which can be used to set the frame rate.

Currently, CameraX only has APIs for querying and setting frame rate via the Camera2 Interop APIs.

From CameraInfo, you can query the frame rate ranges supported by the device:

val camera2Info = Camera2CameraInfo.from(camera.cameraInfo)
val supportedFpsRanges = camera2Info.getCameraCharacteristic(
    CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES
)


From CameraControl, you can set the frame rate range on the camera:

val fpsRange: Range<Int> = ... // Choose from "supportedFpsRanges" above
val camera2Control = Camera2CameraControl.from(camera.cameraControl)
camera2Control.setCaptureRequestOptions(
    CaptureRequestOptions.Builder()
        .setCaptureRequestOption(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange)
        .build()
)




On Thu, Mar 30, 2023 at 11:47 PM yihao wu <wuy...@insta360.com> wrote:
hello, How to set the frame rate at androidx.camera.video.VideoCapture?

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/cbd05d05-8265-42b4-ac8d-8e43e023e40dn%40android.com.

yihao wu

unread,
Apr 3, 2023, 3:05:29 AMApr 3
to Android CameraX Discussion Group, trevor...@google.com, Android CameraX Discussion Group, yihao wu
Thank you. Q1:In addition to setting AE, do you also need to set the frame rate for video recording in Recorder? I set the recording frame rate through reflection,Is this step necessary? private void setVideoFrameRate(Recorder.Builder builder, int fps) { Field field; try { field = Recorder.Builder.class.getDeclaredField("mMediaSpecBuilder"); field.setAccessible(true); MediaSpec.Builder mediaSpecBuilder = (MediaSpec.Builder) field.get(builder); if (mediaSpecBuilder != null) { mediaSpecBuilder.configureVideo( videoBuilder -> videoBuilder.setFrameRate(new Range(fps, fps)) ); Q2:Can I set up AE in the same way as the old VideoCapture? What Builder should I pass in here if I can? Camera2Interop.Extender extender = new Camera2Interop.Extender(builder); extender.setCaptureRequestOption(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, new Range<Integer>(frameRate, frameRate));

Trevor McGuire

unread,
Apr 4, 2023, 11:01:23 AMApr 4
to yihao wu, Android CameraX Discussion Group
Q1:In addition to setting AE, do you also need to set the frame rate for video recording in Recorder? I set the recording frame rate through reflection,Is this step necessary?
Setting it this way will cause the bitrate to scale according to the frame rate. So if your frame rate range is above [30, 30], you'll get a higher bitrate, and vice versa. Otherwise, this won't make much difference; most encoders are timestamp based anyways.

Q2:Can I set up AE in the same way as the old VideoCapture? What Builder should I pass in here if I can?
If you are using the latest alpha release (androidx.camera:camera-video:1.3.0-alpha05), you can do this with VideoCapture.Builder since the Builder class was made public recently. Otherwise, you can do the same thing on the Preview.Builder (or any other use case you're using concurrently) since the FPS range is currently a camera-wide setting.

I hope that helps. We also have an API in the next release that will allow you to set the frame rate directly on VideoCapture.Builder without the need for Camera2Interop/Camera2CameraControl, so keep an eye out for that.

yihao wu

unread,
Apr 10, 2023, 3:42:56 AMApr 10
to Android CameraX Discussion Group, trevor...@google.com, Android CameraX Discussion Group, yihao wu
thanks!
Reply all
Reply to author
Forward
0 new messages