flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.18k stars 27.48k forks source link

[camera] Taking pictures is too slow on some devices #84957

Open nero-angela opened 3 years ago

nero-angela commented 3 years ago

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

  1. Run camera/example with AOS device.
  2. Turn on the flash(torch or always mode).
  3. Press the capture button.
  4. Flash blinks when taking pictures.
  5. When flash is off, pictures are taken.

Expected results: Photo with flash effect applied.

Actual results: Photos without flash effect applied.

TahaTesser commented 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

flutter doctor -v ```console [✓] Flutter (Channel stable, 2.2.2, on Microsoft Windows [Version 10.0.19043.1055], locale en-US) • Flutter version 2.2.2 at C:\Users\Taha\Code\flutter_stable • Framework revision d79295af24 (10 days ago), 2021-06-11 08:56:01 -0700 • Engine revision 91c9fc8fe0 • Dart version 2.13.3 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at C:\Users\Taha\Code\SDK • Platform android-30, build-tools 30.0.3 • ANDROID_SDK_ROOT = C:\Users\Taha\Code\SDK • Java binary at: C:\Users\Taha\Code\openjdk\bin\java.exe • Java version OpenJDK Runtime Environment (build 1.8.0-262-b10) • All Android licenses accepted. [✓] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.10.2) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community • Visual Studio Community 2019 version 16.10.31410.357 • Windows 10 SDK version 10.0.19041.0 [!] Android Studio (not installed) • Android Studio not found; download from https://developer.android.com/studio/index.html (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions). [✓] IntelliJ IDEA Community Edition (version 2021.1) • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.1.1 • Flutter plugin version 57.0.5 • Dart plugin version 211.7233 [✓] VS Code (version 1.57.1) • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.23.0 [✓] Connected device (5 available) • SM M025F (mobile) • R9ZR205XX0A • android-arm • Android 11 (API 30) • sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19043.1055] • Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.114 • Edge (web) • edge • web-javascript • Microsoft Edge 91.0.864.48 ! Doctor found issues in 1 category. ```

Can you please share Android version you're running? Are you using stock firmware or custom rom? Thank you

nero-angela commented 3 years ago

Hi @TahaTesser

My android version is Android 9 (API 28) and I am using the S8 after factory reset.

flutter doctor -v ``` [✓] Flutter (Channel unknown, 2.2.0, on macOS 11.3.1 20E241 darwin-x64, locale ko-KR) • Flutter version 2.2.0 at /Users/nero/Project/FlutterContribution/flutter • Framework revision b22742018b (5 weeks ago), 2021-05-14 19:12:57 -0700 • Engine revision a9d88a4d18 • Dart version 2.13.0 [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) • Android SDK at /Users/nero/Library/Android/sdk • Platform android-30, build-tools 29.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.5, Build version 12E262 • CocoaPods version 1.10.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 3.6) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 44.0.2 • Dart plugin version 192.7761 • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) [✓] VS Code (version 1.57.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.23.0 [✓] Connected device (2 available) • SM G950N (mobile) • ce0317136a2c08f10c • android-arm64 • Android 9 (API 28) • Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.114 ```

https://user-images.githubusercontent.com/26322627/122858776-cffbd200-d355-11eb-9f1d-4c0c64448b5c.mp4

SunlightBro commented 3 years ago

Also reproducible on:

(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 ...)

flutter doctor -v ```console [✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-arm, locale en-DE) • Flutter version 2.2.2 at /Users/davidwimmer/flutter • Framework revision d79295af24 (2 weeks ago), 2021-06-11 08:56:01 -0700 • Engine revision 91c9fc8fe0 • Dart version 2.13.3 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/davidwimmer/Library/Android/sdk • Platform android-30, build-tools 30.0.3 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.5.1, Build version 12E507 • CocoaPods version 1.10.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] ... all my IDEs ... [✓] Connected device (2 available) • ONEPLUS A6003 (mobile) • b0a181c6 • android-arm64 • Android 10 (API 29) • Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.114 ```
dblanco10 commented 3 years ago

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.

dblanco10 commented 3 years ago

This problem is also reproducible on these devices:

The flash light turns off in the moment the photo is taken.

Doppelklick commented 3 years ago

any update on this? same with Xiaomi Redmit Note 7

wim07101993 commented 3 years ago

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.

timlgl commented 3 years ago

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.

code ```import 'dart:io'; import 'package:camera/camera.dart'; import 'package:flutter/material.dart'; List? cameras; Future main() async { WidgetsFlutterBinding.ensureInitialized(); cameras = await availableCameras(); runApp(CameraApp()); } class CameraApp extends StatefulWidget { @override _CameraAppState createState() => _CameraAppState(); } class _CameraAppState extends State { CameraController? controller; @override void initState() { super.initState(); controller = CameraController(cameras![0], ResolutionPreset.max); controller!.initialize().then((_) { if (!mounted) { return; } setState(() {}); }); } @override void dispose() { controller?.dispose(); super.dispose(); } void takePicture() async { Stopwatch stopwatch = new Stopwatch()..start(); await controller!.takePicture(); debugPrint("takePicture took ${stopwatch.elapsedMilliseconds.toString()}"); } @override Widget build(BuildContext context) { if (!controller!.value.isInitialized) { return Container(); } return MaterialApp( home: Scaffold( floatingActionButton: new FloatingActionButton(onPressed: () => takePicture()), body: CameraPreview(controller!))); } } ```
console output ```I/Camera (17461): runPictureAutoFocus I/Camera (17461): lockAutoFocus D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 4 | aeState: 5 I/Camera (17461): runPrecaptureSequence D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_START | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 D/CameraCaptureCallback(17461): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 4 | aeState: 5 W/CameraCaptureCallback(17461): Metering timeout waiting for pre-capture to finish, moving on with capture I/Camera (17461): captureStillPicture D/Camera (17461): Updating builder with feature: ExposureLockFeature D/Camera (17461): Updating builder with feature: ExposurePointFeature D/Camera (17461): Updating builder with feature: ZoomLevelFeature D/Camera (17461): Updating builder with feature: AutoFocusFeature D/Camera (17461): Updating builder with feature: NoiseReductionFeature I/Camera (17461): updateNoiseReduction | currentSetting: fast D/Camera (17461): Updating builder with feature: FocusPointFeature D/Camera (17461): Updating builder with feature: ResolutionFeature D/Camera (17461): Updating builder with feature: SensorOrientationFeature D/Camera (17461): Updating builder with feature: FlashFeature D/Camera (17461): Updating builder with feature: ExposureOffsetFeature D/Camera (17461): Updating builder with feature: FpsRangeFeature I/Camera (17461): sending capture request I/Camera (17461): onImageAvailable I/Camera (17461): unlockAutoFocus I/flutter (17461): takePicture took 3267 ```
` flutter doctor -v` ``` [✓] Flutter (Channel stable, 2.5.0, on Ubuntu 20.04.3 LTS 5.4.0-89-generic, locale en_US.UTF-8) • Flutter version 2.5.0 at /home/tim/snap/flutter/common/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 4cc385b4b8 (8 weeks ago), 2021-09-07 23:01:49 -0700 • Engine revision f0826da7ef • Dart version 2.14.0 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /home/tim/Android/Sdk • Platform android-30, build-tools 30.0.3 • ANDROID_HOME = /home/tim/Android/Sdk • Java binary at: /snap/android-studio/115/android-studio/jre/bin/java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) • All Android licenses accepted. [✓] Chrome - develop for the web • Chrome at google-chrome [✓] Android Studio (version 2020.3) • Android Studio at /snap/android-studio/115/android-studio • Flutter plugin version 59.0.2 • Dart plugin version 203.8292 • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) [✓] VS Code • VS Code at /snap/code/current • Flutter extension version 3.27.0 [✓] Connected device (2 available) • Pixel 4a 5G (mobile) • 08271JECB05977 • android-arm64 • Android 12 (API 31) • Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.159 • No issues found! ```
markfili commented 2 years ago

what's the best way to debug this and determine a fix? do we play around with AF or AE setup?

alfawzaan commented 2 years ago

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,

pbrejdak commented 2 years ago

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.

flutter doctor -v ``` [√] Flutter (Channel stable, 2.10.1, on Microsoft Windows [Version 10.0.19044.1706], locale pl-PL) • Flutter version 2.10.1 at C:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision db747aa133 (4 months ago), 2022-02-09 13:57:35 -0600 • Engine revision ab46186b24 • Dart version 2.16.1 • DevTools version 2.9.2 [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.5) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools • Visual Studio Build Tools 2019 version 16.11.31729.503 • Windows 10 SDK version 10.0.19041.0 [√] Android Studio (version 4.1) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) [√] VS Code (version 1.67.1) • VS Code at C:\Users\pbrejdak\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.40.0 [√] Connected device (4 available) • M2002J9G (mobile) • ae239185 • android-arm64 • Android 11 (API 30) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19044.1706] • Chrome (web) • chrome • web-javascript • Google Chrome 102.0.5005.63 • Edge (web) • edge • web-javascript • Microsoft Edge 101.0.1210.53 [√] HTTP Host Availability • All required HTTP hosts are available ```
erkutalakus commented 2 years ago

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)

qwertyway commented 2 years ago

Same issue Pixel 5a (Android 12), camera package version is 0.9.8+1

Szugalew commented 2 years ago

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.

b1rigu commented 2 years ago

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.

CaoGiaHieu-dev commented 2 years ago

any update?

HE-LU commented 2 years ago

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

pbrejdak commented 2 years ago

@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)

  1. samsung S8
  2. ONEPLUS A6003
  3. Xiaomi MI 8
  4. Samsung Galaxy A6
  5. Samsung Galaxy A50
  6. Xiaomi Redmit Note 7
  7. Google Pixel 4a
  8. Nokia 8.2
  9. Xiaomi Mi 10 Lite
  10. Asus Zenfone 8 (Android 12)
  11. Galaxy A21s
  12. Redmi Note 10 Pro
  13. Pixel 5a
  14. Pixel 6
  15. Samsung Galaxy S9
  16. Huawei P30
  17. Samsung S22 Ultra
  18. Pixel 5
  19. Xiaomi Poco X3 NFC
  20. Xiaomi Redmi Note 8 Pro.
  21. Pixel 6a
migalv commented 2 years ago

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.

mamahd12 commented 2 years ago

I faced the same problem, have anyone figure out the ways to resolve it yet?

divjakLab commented 2 years ago

My customers also run into the same issue.

hubmos commented 2 years ago

Having the same issue.

camelChief commented 1 year ago

It'd be great to see some progress here - having the same issue on a Pixel 6a.

sunderee commented 1 year ago

Same issue on Xiaomi Poco X3 NFC and Xiaomi Redmi Note 8 Pro.

westito commented 1 year ago

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

migalv commented 1 year ago

Hey @westito. Looks like an interesting workaround.

I would like to try it. How should I modify my pubspec to integrate this change?

westito commented 1 year ago

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
migalv commented 1 year ago

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.

Unmodified package
Average time (rear): ~900 milliseconds
Modified package
Average time (rear): ~1100 milliseonds

Could you share your benchmarks? To compare thanks anyway.

pbrejdak commented 1 year ago

@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 :/

westito commented 1 year ago

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

migalv commented 1 year ago

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 😉

camsim99 commented 1 year ago

@westito Yes, the CameraX plugin is in development, so I will follow up on this issue to ensure that the new plugin addresses this.

DmitrySikorsky commented 1 year ago

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.

DmitrySikorsky commented 1 year ago

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.)

DmitrySikorsky commented 1 year ago

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();
JohannesBug commented 1 year ago

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);
Tienisto commented 1 year ago

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);
jchucAD commented 1 year ago

Same issue on my Huawey P30 ...no fix?

RoarGronmo commented 1 year ago

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.

jasonJamEther commented 1 year ago

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.

cmptscpeacock commented 1 year ago

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.

Ritsz123 commented 1 year ago

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

altermark commented 1 year ago

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.

MarkBurvs commented 1 year ago

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.

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.

altermark commented 1 year ago

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

stuartmorgan commented 1 year ago

@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.)

delfme commented 1 year ago

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?

Tienisto commented 1 year ago

@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).

delfme commented 1 year ago

Thx @Tienisto, just checked the fix on my xiaomi mi lite 5g and it works 👍

SpirikleOfficial commented 11 months ago

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.