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

87 views
Skip to first unread message

ALLEN X

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

Scott Nien

unread,
May 10, 2023, 3:41:21 AM5/10/23
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 <camerax-d...@android.com> 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 camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/f785d8e6-719b-4347-b3c6-0da612c75ba4n%40android.com.

Eino-Ville Talvala

unread,
May 10, 2023, 1:53:49 PM5/10/23
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
Forward
0 new messages