3

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.

Chinmay Shah
  • 247
  • 2
  • 10
  • refer this link : https://stackoverflow.com/questions/43628278/how-to-use-android-camera2-api-to-record-60-fps-video-with-fixed-exposure-time/43646443#43646443 – Ali Dec 28 '18 at 10:55
  • CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES needs to be changed, but where do I change it? – Chinmay Shah Dec 28 '18 at 11:09
  • **CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES** is read-only. You can set **CONTROL_AE_TARGET_FPS_RANGE** but it may only be one of the *available* ranges. – Alex Cohn Dec 30 '18 at 11:19

3 Answers3

7

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();
Chinmay Shah
  • 247
  • 2
  • 10
  • 1
    captureRequest.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_OFF); captureRequest.set(CaptureRequest.SENSOR_FRAME_DURATION, mFrameDuration); – Hugo Nov 29 '20 at 02:27
  • Hi, @Chinmay shah, How do i make sure if it is working or not. I tried above mention code snippet but it doesn't seem working in my case. – Black4Guy Aug 03 '22 at 14:04
1
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.

DmitryArc
  • 4,757
  • 2
  • 37
  • 42
Akash
  • 51
  • 3
0

Use this only if you are very desperate as this is not a professional answer:

Using this application as an example I added this time delay between the capture of frames to force in an UGLY WAY the drop of fps. For example to reach a level of 4 fps aproximatelly, I added in .../kotlin/com/otaliastudios/cameraview/demo/CameraActivity.kt this try-catch snippet:

...
LOG.v("Frame delayMillis:", delay, "FPS:", 1000 / delay)
// This try catch forces a fps of 4fps aprox
try {
    Thread.sleep(250) // Sleep for 1000 milliseconds (1 second)
} catch (e: InterruptedException) {
    // Handle the interrupted exception
    e.printStackTrace()
}
if (DECODE_BITMAP) {
...

Also setting 'USE_FRAME_PROCESSOR' to true.

ricogordo
  • 36
  • 2