CameraX is super slow (needs ~3 seconds) when taking a photo, while built-in android camera app is quite fast

375 views
Skip to first unread message

Ch Tom

unread,
May 17, 2023, 10:53:14 PM5/17/23
to Android CameraX Discussion Group
Hi thanks for the helpful official CameraX library! However, when using it on some devices, it is super slow (needs ~3 seconds) to merely take a photo.

Context:

* The page is quite simple. Mainly just a preview view + a "take photo" button.
* On some devices it is quite fast; on some devices it is super slow (3 seconds)
* For the devices that are slow using CameraX, it is still very fast if a user uses the built-in camera app in android to take even highest quality photo. Thus it seems not a problem of the device's camera, but a bug in CameraX.
* I use `ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY` (because I need the image to be focused instead of blur, and need it to be of high quality).
* I can provide more information if needed!

Scott Nien

unread,
May 17, 2023, 11:28:05 PM5/17/23
to Android CameraX Discussion Group, ch27...@gmail.com
Hi,  
Thanks for letting us know the issue. 

Some quick questions 
1.  What is the phone model ?
2.  Did you use CameraController or setting any ViewPort ?  
3.  Did you set the flash mode to FLASH_MODE_ON or FLASH_MODE_AUTO ,  and do you shot in the low-light condition ?

Ch Tom

unread,
May 18, 2023, 3:38:18 AM5/18/23
to Android CameraX Discussion Group, scot...@google.com, Ch Tom
Hi thanks for the reply!


1.  What is the phone model ?
I can reproduce on TRT-AL00, i.e. "Huawei Enjoy 7 Plus"

2.  Did you use CameraController or setting any ViewPort ?  
No CameraController in my code. I do have a viewport:
val viewPort: ViewPort = ViewPort.Builder(aspectRatio, viewFinder.display.rotation)
.setScaleType(ViewPort.FILL_CENTER)
.build()

3.  Did you set the flash mode to FLASH_MODE_ON or FLASH_MODE_AUTO ,  and do you shot in the low-light condition ?
There is no code with "flash" keyword, so I guess I use the default value.
Not shot in low-light.

Scott Nien

unread,
May 18, 2023, 4:13:55 AM5/18/23
to Ch Tom, Android CameraX Discussion Group
Hi, 
Got it!   I think this could be caused by the software cropping (it needs software Jpeg decoding / cropping / encoding) triggered by the viewport. 
And unfortunately it is slow in low end devices.  If you are okay with having slightly inconsistent FOV between preview and captured photo,  removing the viewport is one option. 


Ch Tom

unread,
May 18, 2023, 8:05:10 AM5/18/23
to Android CameraX Discussion Group, scot...@google.com, Android CameraX Discussion Group, Ch Tom
Hi thanks for the suggestion! I originally suspect it was a problem caused by focusing. I will make an experiment to remove the software cropping and report the results here.

So if I understand correctly, I should remove the ViewPort (i.e. remove `.setViewPort(viewPort)`).

Ch Tom

unread,
May 18, 2023, 8:10:53 AM5/18/23
to Android CameraX Discussion Group, scot...@google.com, Android CameraX Discussion Group, Ch Tom
Hi you are really expert and thank you! I removed ViewPort, and taking a photo needs only 1 second (originally the super slow 3 second).

On Thursday, May 18, 2023 at 4:13:55 PM UTC+8 scot...@google.com wrote:

Scott Nien

unread,
May 19, 2023, 4:41:55 AM5/19/23
to Ch Tom, Android CameraX Discussion Group
That's great to hear!  

Denny Oommen Mathew

unread,
Feb 16, 2024, 12:39:54 PMFeb 16
to Android CameraX Discussion Group, scot...@google.com, Android CameraX Discussion Group, ch27...@gmail.com
Sorry to bump old thread.

I have the same problem.

Not sure exactly what I am doing wrong.

I use LifecycleCameraController and setup use cases manually using cameraController.setEnabledUseCases. Does that slow things down.

Should I use ProcessCameraProvider and bind use cases.

Denny Oommen Mathew

unread,
Feb 16, 2024, 12:52:41 PMFeb 16
to Android CameraX Discussion Group, Denny Oommen Mathew, scot...@google.com, Android CameraX Discussion Group, ch27...@gmail.com
Not using ViewPort or flash. I do have a flash setting but it is turned OFF while taking photo.

Phone: Samsung s23 Ultra. Takes 2-3 seconds to get the photo in onImageSaved() inside ImageCapture.OnImageSavedCallback.

I prefer not processing photo myself using OnImageCapturedCallback.

If there is a best practices guide on CameraX, please share.

Thanks,
Denny

Scott Nien

unread,
Feb 18, 2024, 9:55:23 PMFeb 18
to Denny Oommen Mathew, Android CameraX Discussion Group, ch27...@gmail.com
Using CameraController (which ViewPort is enabled)  or the ViewPort can help you capture the same FOV as the preview but at the cost of extra software cropping.  
If you prefer to get the image saved sooner,  you can create and bind the use cases directly. 

Denny Oommen Mathew

unread,
Feb 20, 2024, 11:29:34 PMFeb 20
to Android CameraX Discussion Group, scot...@google.com, Android CameraX Discussion Group, ch27...@gmail.com, Denny Oommen Mathew
| If you prefer to get the image saved sooner,  you can create and bind the use cases directly.

For this, I can only use ProcessCameraProvider and not the CameraController one, right.

Thanks for your response!

Scott Nien

unread,
Feb 21, 2024, 10:12:18 AMFeb 21
to Denny Oommen Mathew, Android CameraX Discussion Group, ch27...@gmail.com
That's right.  You can directly use ProcessCameraProvider without CameraController.  

Denny Oommen Mathew

unread,
Feb 21, 2024, 10:59:43 AMFeb 21
to Scott Nien, Android CameraX Discussion Group, ch27...@gmail.com
Thank you. I will explore that route. 
Reply all
Reply to author
Forward
0 new messages