Is it possible to limit fps range in android camera.. tried to change the values in .setPreviewFpsRange()... but frame rate are not changed.. it comes continuously 30 frames per second
Asked
Active
Viewed 1.1k times
6
-
how did you check that it is 30 frame per second? can you share the code sample? – Akshatha S R Jan 31 '19 at 07:41
2 Answers
5
You can use public List<int[]> getSupportedPreviewFpsRange ()
to check what FPS range supported by your device. Here is mine:
preview-fps-range-values=(10000,10000),(15000,15000),(15000,30000),(30000,30000);
so if I want to change the fps to 15, I can setPreviewFpsRange(15000,15000)
.

yushulx
- 11,695
- 8
- 37
- 64
-
this worked.. But if only one fps range is available then how to do... any way to restricting call back to avoid more frame rates – Binu Mar 18 '14 at 08:23
-
sure. Based on your strategy, you can do anything in preview callback function to programmatically change the FPS. For example, you can drop frames, or sleep thread for a couple of milliseconds. – yushulx Mar 18 '14 at 09:51
-
used thred.sleep.. but it blocks other thread.. can u give some example for drop frames to do this.. – Binu Mar 18 '14 at 10:48
-
How did you sleep your thread? You should use it in onPreviewFrame(byte[] data, Camera camera), in which you can also deal with all preview frames. – yushulx Mar 19 '14 at 02:29
-
@yushulx can you please take a look on this question : http://stackoverflow.com/questions/30564273/how-to-get-camera-preview-frame-after-every-500ms – sam_k Jun 03 '15 at 15:09
-
**Thread.sleep()** in **onPreviewFrame()** is dangerous, but even worse if this callback comes on the UI thread. You must [open the camera on a separate HandlerThread](https://stackoverflow.com/a/19154438/192373) so that the camera callbacks use that background thread and not the UI thread. – Alex Cohn Sep 26 '17 at 10:30
0
I set the preview frame rate to the lowest rate possible with this code, but you could set it to the highest rate possible by using l_last
instead of l_first
in the List index (mCamera
is a member variable that references the Camera and is set elsewhere in the code).
Camera.Parameters l_params = mCamera.getParameters();
List<int[]> frameRates = l_params.getSupportedPreviewFpsRange();
int l_first = 0;
int l_last = frameRates.size() - 1;
int minFps = (frameRates.get(l_first))[Camera.Parameters.PREVIEW_FPS_MIN_INDEX];
int maxFps = (frameRates.get(l_first))[Camera.Parameters.PREVIEW_FPS_MAX_INDEX];
l_params.setPreviewFpsRange(minFps, maxFps);
mCamera.setParameters(l_params);

Simon Hänisch
- 4,740
- 2
- 30
- 42

BurningThumb
- 31
- 2
-
-
I think it should be l_last instead of l_first in the sixth line: "int maxFps = (frameRates.get(l_last))[Camera.Parameters.PREVIEW_FPS_MAX_INDEX];" – kfir Jan 03 '21 at 13:53