How to get the real-time frame rate of the preview?

Skip to first unread message


May 9, 2023, 5:44:39 AMMay 9
to Android CameraX Discussion Group
As the title, is there any methods can help me get the real-time frame rate?

Scott Nien

May 10, 2023, 3:41:21 AMMay 10
to ALLEN X, Android CameraX Discussion Group
One possible way is to invoke internal API mPreviewView.setFrameUpdateListener() and setImplementationMode to COMPATIBLE.   Unfortunately there is no public API exposing the same functionality unless you implement your custom view for the preview. 

On Tue, May 9, 2023 at 5:44 PM 'ALLEN X' via Android CameraX Discussion Group <> wrote:
As the title, is there any methods can help me get the real-time frame rate?

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
To view this discussion on the web visit

Eino-Ville Talvala

May 10, 2023, 1:53:49 PMMay 10
to Scott Nien, ALLEN X, Android CameraX Discussion Group
I think you could also use Camera2Interop's setSessionCaptureCallback to receive the preview CaptureResult objects in onCaptureCompleted, which include a timestamp for start of exposure.
Then you can calculate the time between starts of exposure to get the current frame duration and thus the frame rate.  Note that this is a bit tricky because when exposure time changes, the time between exposure starts isn't equal to the frame duration, so ideally you'd also include the exposure time in the calculation (but that's not available on every device): 

   frame_duration = (frame[N+1].timestamp + frame[N+1].exposureTime) - (frame[N].timestamp + frame[N].exposureTime) 
   fps = 1/ frame_duration

You can also just look at the frame duration field when the device supports listing that, but the timestamp is always available.

Reply all
Reply to author
0 new messages