Flutter camera take too long to take a picture
Asked Answered
M

2

6

I am trying to use the official flutter camera package but the take picture method take a lot of time (like 3-5 seconds) regardless of the resolution picked. Is there a way to speed it up (I am using a Pixel 5 as a development device)? currently I show a message to the user to hold still while it's taking the picture but it feels like a bad UX.

Edit: I downgraded the picture format to jpeg instead of yuv420 and it is slightly quicker.

Marzi answered 14/8, 2021 at 11:19 Comment(0)
P
2

This is a known issue with the official camera package:

https://github.com/flutter/flutter/issues/84957

You can give it a thumbs up to give it more attention.

You can also try using the CamerAwesome package instead. It does not have as many features as the official package, but in my testing, it takes pictures pretty much instantly.

CamerAwesome: https://pub.dev/packages/camerawesome

Pressmark answered 23/7, 2022 at 1:41 Comment(1)
could you show a small example on hot to use the CamerAwesome package?Blancablanch
A
2

Update. To make it really instant the code should be like this:

//final AutoFocusFeature autoFocusFeature = cameraFeatures.getAutoFocus();
//final boolean isAutoFocusSupported = autoFocusFeature.checkIsSupported();
//if (isAutoFocusSupported && autoFocusFeature.getValue() == FocusMode.auto) {
//  runPictureAutoFocus();
//} else {
//  runPrecaptureSequence();
//}
takePictureAfterPrecapture();

In my case (Google Pixel 3, Google Pixel 7) it was because despite camera is already focused in preview mode, when you take a picture it will focus again and it usually takes 1-several seconds to complete, which makes plugin useless in production. (BTW, I tried to fix this from the other side, using image stream, which worked perfectly fast, but in that mode image quality is much lower, it seems to be another issue.)

I've found a workaround for this issue while it is still exists in camera 0.10.5+2.

I've modified the takePicture method inside the Camera.java file. Just commented out 3 lines at the end:

//if (isAutoFocusSupported && autoFocusFeature.getValue() == FocusMode.auto) {
//  runPictureAutoFocus();
//} else {
  runPrecaptureSequence();
//}

Now autofocusing works during preview, and then, when you call takePicture, in most of the cases it will return instantly. Not always, but it is much, much better than it was before. Now it is usable.

(To do it you need to copy this package locally, modify the file, and then add this section to your pubspec.yaml:

dependency_overrides:
  camera_android:
    path: ../camera_android

Don't forget to check path to the local copy.)

Anestassia answered 22/6, 2023 at 6:58 Comment(1)
Yes, it's now better, but still provides poor experience.Upshaw

© 2022 - 2024 — McMap. All rights reserved.