I am trying to encode a 30 frames per second video using MediaCodec through the Camera\'s PreviewCall back(onPreviewFrame). The video that I encoded always plays very fast(t
No, Android camera does not guarantee stable frame rate, especially at 30 FPS. For example, it may choose longer exposure at low lighting conditions.
But there are some ways we, app developers, can make things worse.
First, by using setPreviewCallback()
instead of setPreviewCallbackWithBuffer()
. This may cause unnecessary pressure on the garbage collector.
Second, if onPreviewFrame()
arrives on the main (UI) thread, you cause any UI action directly delay the camera frames arrival. To keep onPreviewFrame()
on a separate thread, you should open()
the camera on a secondary Looper thread. Here I explained in detail how this can be achieved: Best use of HandlerThread over other similar classes.
Third, check that processing time is less than 20ms.