Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nero-angela opened this issue Jun 21, 2021 · 52 comments
Open

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

nero-angela opened this issue Jun 21, 2021 · 52 comments
Labels
e: device-specific Only manifests on certain devices p: camera The camera plugin P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team

Comments

@nero-angela
Copy link
Contributor

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 TahaTesser added the in triage Presently being triaged by the triage team label Jun 21, 2021
@TahaTesser
Copy link
Member

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
[✓] 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

@TahaTesser TahaTesser added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jun 21, 2021
@nero-angela
Copy link
Contributor Author

nero-angela commented Jun 22, 2021

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
flash_test.mp4

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jun 22, 2021
@TahaTesser TahaTesser changed the title [camera] Taking pictures is too slow on Android. [camera] Taking pictures is too slow on Galaxy S8 Jun 22, 2021
@TahaTesser TahaTesser added e: device-specific Only manifests on certain devices p: camera The camera plugin p: first party platform-android Android applications specifically and removed in triage Presently being triaged by the triage team labels Jun 22, 2021
@stuartmorgan stuartmorgan added the P3 Issues that are less important to the Flutter project label Jun 24, 2021
@SunlightBro
Copy link

Also reproducible on:

  • ONEPLUS A6003 (mobile) • b0a181c6 • android-arm64 • Android 10 (API 29)

(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
[✓] 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
Copy link

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.

@TahaTesser TahaTesser changed the title [camera] Taking pictures is too slow on Galaxy S8 [camera] Taking pictures is too slow on some devices Jun 28, 2021
@dblanco10
Copy link

This problem is also reproducible on these devices:

  • Samsung Galaxy A6 (SM-A600FN/DS, Android 9): do not work well any of the flash modes.
  • Samsung Galaxy A50 (SM-505FN, Android 9): FlashMode.always works fine. FlashMode.torch does not.

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

@Doppelklick
Copy link

Doppelklick commented Aug 26, 2021

any update on this? same with Xiaomi Redmit Note 7

@wim07101993
Copy link

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
Copy link

timlgl commented Oct 31, 2021

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 'package:camera/camera.dart';
import 'package:flutter/material.dart';

List<CameraDescription>? cameras;

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  cameras = await availableCameras();
  runApp(CameraApp());
}

class CameraApp extends StatefulWidget {
  @override
  _CameraAppState createState() => _CameraAppState();
}

class _CameraAppState extends State<CameraApp> {
  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): 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
Copy link

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

@alfawzaan
Copy link

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
Copy link

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
Copy link

erkutalakus commented Jun 14, 2022

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
Copy link

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

@Szugalew
Copy link

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
Copy link

b1rigu commented Aug 3, 2022

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
Copy link

any update?

@HE-LU
Copy link

HE-LU commented Aug 24, 2022

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

@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-android Owned by Android platform team triaged-android Triaged by Android platform team labels Jul 8, 2023
@JohannesBug
Copy link

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
Copy link

Tienisto commented Aug 1, 2023

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
Copy link

jchucAD commented Aug 7, 2023

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

@RoarGronmo
Copy link

RoarGronmo commented Aug 17, 2023

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
Copy link

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
Copy link

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
Copy link

Ritsz123 commented Sep 4, 2023

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
Copy link

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
Copy link

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
Copy link

altermark commented Sep 28, 2023

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 added a commit to stuartmorgan/packages that referenced this issue Sep 28, 2023
Fixes a typo introduced during a testability refactor that caused the
capture state machine to read the wrong value for autofocus state,
breaking the state machine.

Fixes flutter/flutter#135554
Part of flutter/flutter#84957
@stuartmorgan
Copy link
Contributor

stuartmorgan commented Sep 28, 2023

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

auto-submit bot pushed a commit to flutter/packages that referenced this issue Sep 28, 2023
Fixes a typo introduced during a testability refactor that caused the capture state machine to read the wrong value for autofocus state, breaking the state machine.

Fixes flutter/flutter#135554
Part of flutter/flutter#84957
@delfme
Copy link

delfme commented Oct 20, 2023

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
Copy link

Tienisto commented Oct 20, 2023

@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
Copy link

delfme commented Oct 21, 2023

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

@SpirikleOfficial
Copy link

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.

HugoOlthof pushed a commit to moneybird/packages that referenced this issue Dec 13, 2023
Fixes a typo introduced during a testability refactor that caused the capture state machine to read the wrong value for autofocus state, breaking the state machine.

Fixes flutter/flutter#135554
Part of flutter/flutter#84957
@camsim99
Copy link
Contributor

This issue should be fixed in the CameraX implementation of the camera plugin, so please try it out!

If you find a similar issue with that implementation (or any other issues), please feel free to file a separate issue.

@vodemn
Copy link

vodemn commented Apr 5, 2024

@camsim99
I've taken several tens of photos of the same scene and on average it took 1753ms with a fix from #84957 (comment) and 358 without it.
Test code from #134300 (comment)

  camera: 0.10.5+2
  camera_android_camerax: 0.6.1+1

@camsim99 camsim99 moved this from Camera issues to track to camera_android issues solved by camera_android_camerax in Android Camera Re-write Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e: device-specific Only manifests on certain devices p: camera The camera plugin P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team
Projects
Android Camera Re-write
[CONFIRMED] camera_android issues sol...
Development

No branches or pull requests