Open nero-angela opened 3 years ago
Hi @nero-angela I just tried budget videos, with a much slower process (Samsung M02s) and every pic taken has an on-time flash effect using official sample
Can you please share Android version you're running? Are you using stock firmware or custom rom? Thank you
Hi @TahaTesser
My android version is Android 9 (API 28) and I am using the S8 after factory reset.
(This is currently only my own device ... I will update this list, when I can go back to the office, and have more real test devices available ...)
I find the same problem in my device (Xiaomi MI 8, Android 10). The flash light terminates before the picture is taken, even with torch FlashMode on.
This problem is also reproducible on these devices:
The flash light turns off in the moment the photo is taken.
any update on this? same with Xiaomi Redmit Note 7
Same problem with Google Pixel 4a (Android 12), Nokia 8.2 (Android 11).
It seems like it takes long before the camera finds it's focus.
Independently of the flash, I too find the takePicture() method is rather slow (on my Pixel 4a 5G, same on Pixel 4a).
With a very basic example, it takes over 3 seconds. You can find more detailed information below.
what's the best way to debug this and determine a fix? do we play around with AF or AE setup?
you can change the resolution to ResolutionPreset.medium. This are list of available values that you can experiment with
/// 352x288 on iOS, 240p (320x240) on Android and Web low,
/// 480p (640x480 on iOS, 720x480 on Android and Web) medium,
/// 720p (1280x720) high,
/// 1080p (1920x1080) veryHigh,
/// 2160p (3840x2160 on Android and iOS, 4096x2160 on Web) ultraHigh,
/// The highest resolution available. max,
I can report same behavior on Xiaomi Mi 10 Lite (Android 11)
, Asus Zenfone 8 (Android 12)
. however on older LG G6 (Android 9)
it's working properly, maybe some issues related to newer version of Android? Can we get some support on this issue? It really deal breaker if camera is not working properly on half of devices and asking users to wait 1 second after pressing button to take picture is quite ridiculous.
I faced this issue when I upgrade camera package from 0.6.3+4. That version was lightning fast compared to new versions(>=0.7.0)
ps: observed in Galaxy A21s (Android 11) and Redmi Note 10 Pro (Android 12)
Same issue Pixel 5a (Android 12), camera package version is 0.9.8+1
I think the problem is the runPictureAutoFocus()
and runPrecaptureSequence()
functions in Camera.java
take too long. I tested skipping over them and it captures pictures instantly.
Tested on a Pixel 6 and Samsung Galaxy S9.
Just like @Szugalew suggested I skipped the runPictureAutoFocus() and runPrecaptureSequence() in Camera.java and just running the takePictureAfterPrecapture() directly. This resulted in instant picture. Thanks sir.
any update?
We ran into a pretty similar issue. Users report that taking the picture takes too long, and sometimes the image is captured with a delay, not when they pushed the button.
Can anybody provide more clear steps on how to edit and use the edited Camera.java
file? Looks like runPictureAutoFocus
and runPrecaptureSequence
could cause this issue.
Edit: Tested on Samsung S22 Ultra and Pixel 5
@TahaTesser Could you take a look again on this issue? seems like it's more devices, as others pointed it out runPictureAutoFocus()
and runPrecaptureSequence()
seems like causing this lag issue, it's a deal breaker if I have to tell user to hold phone still for 2 seconds because there is lag in internal camera package.
Here's list of devices where is lag based on this issue (will update the list)
Experiencing this issue in a multitude of Android devices too.
Huawei P30 is one of them.
Changing the resolution did not solve the issue for me as @alfawzaan suggests.
I faced the same problem, have anyone figure out the ways to resolve it yet?
My customers also run into the same issue.
Having the same issue.
It'd be great to see some progress here - having the same issue on a Pixel 6a.
Same issue on Xiaomi Poco X3 NFC and Xiaomi Redmi Note 8 Pro.
I made a small modification to disable focus triggering before taking photo. This makes taking photos much faster. The focusing is continuous while preview and this code still waits for a "passive" focus so the picture won't be blurred. The difference between passive and triggered focus (if I understand the documentation correctly) is that triggered focus definitely returns a sharp image, while passive focus can be changed until the image is ready and sharpness is not guaranteed. You can add this code to pubspec.yaml by commit hash ref: https://github.com/westito/plugins/commit/50c11c1514c55a30e9bbda91ade54b5a28f24ae0
Hey @westito. Looks like an interesting workaround.
I would like to try it. How should I modify my pubspec
to integrate this change?
Hey @westito. Looks like an interesting workaround.
I would like to try it. How should I modify my
pubspec
to integrate this change?
Simply add to overrides:
dependency_overrides:
camera_android:
git:
url: git@github.com:westito/plugins.git
ref: quick-take-photo
path: packages/camera/camera_android
Hey @westito I tested your modification and I don't see any big difference to be honest.
I tested on Release mode with a Huawei P30
I've taken 10 to 20 pictures for each test, with different environments (dark, bright, moving pictures, multiple depths, flat, etc...). These are the results for the time elapsed from when I tap the "take picture" button & the camera_controller
returning an image file.
Could you share your benchmarks? To compare thanks anyway.
@migalv same here, it should be fixed by flutter team, which currently doesn't really take it into consideration, even if list of devices is quite big, unfourutantely they focus everything on windows release and mobile devices are not existing to them right now :/
The code in camera_android package mostly copied from official Camera2 API example what is a very basic implementation. Camera2 itself is a low-level access to camera functions and not recommended by Google anymore. I think we should not bother with this implementation anymore, rather deal with CameraX that provides a higher (maybe device-independent) access to the camera. As I see @camsim99 has already started implement it, but I don't know what state it is in. https://github.com/flutter/plugins/pull/6745
If anyone is having this issue maybe you can try this package CamerAwesome. They launched they version 1.0.0 two days ago. I believe they implemented using the CameraX API as @westito suggests.
I haven't tried it yet, but it's quite promising.
Hope it helps anyone. Share your results 😉
@westito Yes, the CameraX plugin is in development, so I will follow up on this issue to ensure that the new plugin addresses this.
Same with Google Pixel 7. Camera is trying to focus while taking photo, so if you move your phone it can take 2-5 seconds to take a picture, but never instantly.
After several hours looking how to fix this I decided to try the Szugalew's solution.
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();
//}
And... it worked! 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.
(To do it you need to copy this package locally 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.)
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();
Building on @DmitrySikorsky's and @Szugalew's solution: If you don't want to modify the camera package itslef you can also use a wrapper function around the takePicture method, instead of just riggering takePicture with a button press.
This results in a sped up process. something like 0.5s-1s instead of 3s-4s
await _cameraController.setFocusMode(FocusMode.locked);
await _cameraController.setExposureMode(ExposureMode.locked);
XFile picture = await _cameraController.takePicture();
await _cameraController.setFocusMode(FocusMode.locked);
await _cameraController.setExposureMode(ExposureMode.locked);
Building on @DmitrySikorsky's and @Szugalew's solution: If you don't want to modify the camera package itslef you can also use a wrapper function around the takePicture method, instead of just riggering takePicture with a button press.
This results in a sped up process. something like 0.5s-1s instead of 3s-4s
await _cameraController.setFocusMode(FocusMode.locked); await _cameraController.setExposureMode(ExposureMode.locked); XFile picture = await _cameraController.takePicture(); await _cameraController.setFocusMode(FocusMode.locked); await _cameraController.setExposureMode(ExposureMode.locked);
It seems to only speed up the first photo. As soon as I want to take a 2nd photo, it is very slow again.
Edit: Actually, it should be like this:
await _controller!.setFocusMode(FocusMode.locked);
await _controller!.setExposureMode(ExposureMode.locked);
final picture = await _controller!.takePicture();
await _controller!.setFocusMode(FocusMode.auto);
await _controller!.setExposureMode(ExposureMode.auto);
Same issue on my Huawey P30 ...no fix?
Just mentioning that this is an issue for Samsung S9+ also (android 10), one ui 2.5. Rather old, the picture takes approx 2-5 sec to snap.
I am having this same issue on Galaxy s22. This is universal enough we really need a fix. I don't mind modifying the java for a solution but I can see the code is bypassing features and efficiency in the name of a quick image capture. A worthwhile trade but not a long term solution.
Same. When using this to take an image, then take another straight after I'm getting inconsistent results. Sometimes image 1 takes 1 second, other times 3 seconds. Image 2 can also take 1-3 seconds.
Currently not a usable solution so please investigate asap.
Building on @DmitrySikorsky's and @Szugalew's solution: If you don't want to modify the camera package itslef you can also use a wrapper function around the takePicture method, instead of just riggering takePicture with a button press. This results in a sped up process. something like 0.5s-1s instead of 3s-4s
await _cameraController.setFocusMode(FocusMode.locked); await _cameraController.setExposureMode(ExposureMode.locked); XFile picture = await _cameraController.takePicture(); await _cameraController.setFocusMode(FocusMode.locked); await _cameraController.setExposureMode(ExposureMode.locked);
It seems to only speed up the first photo. As soon as I want to take a 2nd photo, it is very slow again.
Edit: Actually, it should be like this:
await _controller!.setFocusMode(FocusMode.locked); await _controller!.setExposureMode(ExposureMode.locked); final picture = await _controller!.takePicture(); await _controller!.setFocusMode(FocusMode.auto); await _controller!.setExposureMode(ExposureMode.auto);
In this case exposure is not getting reset. for example if I click a picture in normal light then one in dark and the third one again in normal light, The last picture gets over exposure.
and I'm getting this logs in console
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.camera2.CaptureRequest$Builder.set(android.hardware.camera2.CaptureRequest$Key, java.lang.Object)' on a null object reference
Pinning camera_android
to 0.10.8+3
in pubspec.yaml
has worked for me to eliminate the autofocus timeout without any other code changes. YMMV.
Pinning
camera_android
to0.10.8+3
inpubspec.yaml
has worked for me to eliminate the autofocus timeout without any other code changes. YMMV.
This definitely results in the camera capture being much faster for me when tested on Pixel 7. But it does have to be this exact version (0.10.8+3 of camera_android).
More recent versions of camera_android than that are also really slow.
I have probably found the source of the autofocus timeout bug that delays image capture, but cannot verify.
In this diff of changes between 0.10.8+3 and 0.10.8+4, there is a typo on line 34. There should be
CaptureResult.Key<Integer> afStateKey = CaptureResult.CONTROL_AF_STATE;
instead of
CaptureResult.Key<Integer> afStateKey = CaptureResult.CONTROL_AE_STATE;
Ping commit author @stuartmorgan
@altermark Thanks for finding that mistake! I have a PR up to fix it.
(This is not expected to fix the original issue here, since the issue was filed far earlier than that mistake was introduced.)
Hello guys, Im seeing long time in taking a pic on xiaomi mi lite 5g android 13 (almost 3sec). What is the latest / most effective workaround for this, if any?
@delfme as camera_android v0.10.8+12
has been released, you can either run flutter pub upgrade
or set camera_android: 0.10.8+12
in the pubspec.yaml
(but remove this after flutter pub get
as this is only a transitive dependency).
Thx @Tienisto, just checked the fix on my xiaomi mi lite 5g and it works 👍
Also seeing delay in Samsung M31, Samsung M31s, Poco F4 when calling takePicture(). Please solve this issue as this issue has been lingering for almost 2.5 years now and for a basic and necessary package like camera, really limits the potential for flutter apps.
Hi, I'm making a camera app with samsung s8 device and camera package. However, there is a problem with the shooting speed being too slow on the Android device. It takes about 0.5 to 1.5 second to shoot. (I used camera/example for testing)
The shooting speed on the Android(S8) is too slow, so even if I shoot with the flash on, the flash effect is not applied because the shooting is completed after the flash is off.
I wonder if it's a fundamental problem with the package, or it's a problem that only occurs on my S8.
Steps to Reproduce
Expected results: Photo with flash effect applied.
Actual results: Photos without flash effect applied.