How to modify frame rate using camera2?

Viewed 4416

I'm trying to modify the frame rate (reduce it) so that we can do real-time operation on it. But cannot change the frame rate.

Possible solutions include :

  • Changing CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES

  • delay setRepeatingRequest

We need to reduce the generated frame rate passed to Surfaceholder so that can apply on operations in it further.

2 Answers

As suggested in the comment, I managed to find the solution and am answering my own question, on how I solved the problem.

We first create an object of mPreviewRequestBuilder and using it to modify frame rate.

private CaptureRequest.Builder mPreviewRequestBuilder;
// We set up a CaptureRequest.Builder with the output Surface.
mPreviewRequestBuilder
                = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mPreviewRequestBuilder.addTarget(surface);        

We can achieve changing this by creating an array of Range and setting this manually as mentioned below.

Range<Integer>[] fps = new Range[size];

Adding custom values to the Range class.

fps[0] = Range.create(2,5);

Once we have managed to create an array of Range, we can set the camera settings as mentioned below:

mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,fps[0]);
mPreviewRequest = mPreviewRequestBuilder.build();
Range<Integer> fpsRange = new Range<>(30,60);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,fpsRange);

This code works and sets the target fps range. However I was able to set the values to 30,60 on S9 plus and it delivers around 45 FPS. Even though [30,60] is not available in ranges.

Related