Search code examples
javaandroidandroid-cameraandroid-camera2

How to modify frame rate using camera2?


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.


Solution

  • 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();