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

[BUG] [CAMERA] Flutter camera freezes when start recording video on Android #40519

Closed
divyanshub024 opened this issue Sep 15, 2019 · 40 comments
Closed
Labels
customer: crowd Affects or could affect many people, though not necessarily a specific customer. p: camera The camera plugin package flutter/packages repository. See also p: labels. platform-android Android applications specifically

Comments

@divyanshub024
Copy link

Description

I'm using Flutter camera plugin camera: ^0.5.4+1. For some reason, my camera freezes when I start recording video.
This is the error I'm getting.

I/flutter (28050): startVideoRecording
I/RequestQueue(28050): Repeating capture request cancelled.
I/CameraDeviceState(28050): Legacy camera service transitioning to state IDLE
E/CameraDevice-0-LE(28050): Surface with size (w=3840, h=2160) and format 0x22 is not valid, size not in valid set: [2048x1536, 1920x1440, 2048x1080, 1920x1080, 2560x800, 1440x1080, 1280x960, 1280x720, 1280x480, 1280x400, 864x480, 640x640, 800x480, 720x480, 768x432, 640x480, 576x432, 640x360, 480x360, 480x320, 384x288, 352x288, 320x240, 240x160, 176x144, 160x120]
E/CameraDevice-0-LE(28050): submitRequestList - cannot use a surface that wasn't configured
E/MediaRecorder(28050): stop called in an invalid state: 8
I/flutter (28050): Error: videoRecordingFailed
I/flutter (28050): Error Message: null

Here is my code of start and stop video recording. The same code use to work before but it's not working now.

Future<String> startVideoRecording() async {
    print('startVideoRecording');
    if (!_controller.value.isInitialized) {
      return null;
    }
    setState(() {
      _isRecording = true;
    });
    _timerKey.currentState.startTimer();

    final Directory extDir = await getApplicationDocumentsDirectory();
    final String dirPath = '${extDir.path}/Videos/Post';
    await Directory(dirPath).create(recursive: true);
    final String filePath = '$dirPath/${_timestamp()}.mp4';

    if (_controller.value.isRecordingVideo) {
      // A recording is already started, do nothing.
      return null;
    }

    try {
      videoPath = filePath;
      await _controller.startVideoRecording(filePath);
    } on CameraException catch (e) {
      _showCameraException(e);
      return null;
    }
    return filePath;
  }

  Future<void> stopVideoRecording() async {
    if (!_controller.value.isRecordingVideo) {
      return null;
    }
    _timerKey.currentState.stopTimer();
    setState(() {
      _isRecording = false;
    });

    try {
      await _controller.stopVideoRecording();
    } on CameraException catch (e) {
      _showCameraException(e);
      return null;
    }
  }

Logs

flutter doctor -v

[✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.14.6 18G87, locale en-IN)
    • Flutter version 1.9.1+hotfix.2 at /Users/divyanshub024/Softwares/flutter
    • Framework revision 2d2a1ffec9 (8 days ago), 2019-09-06 18:39:49 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0

 
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/divyanshub024/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/divyanshub024/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.3, Build version 10G8
    • CocoaPods version 1.7.1

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] IntelliJ IDEA Community Edition (version 2018.3.4)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 32.0.3
    • Dart plugin version 183.5429.25

[✓] Connected device (1 available)
    • ASUS X00TD • J7AAGF01H563MZA • android-arm64 • Android 9 (API 28)

! Doctor found issues in 1 category.

@BondarenkoStas BondarenkoStas added p: camera The camera plugin plugin platform-android Android applications specifically labels Sep 15, 2019
@divyanshub024 divyanshub024 changed the title Flutter camera freezes when start recording video on Android [BUG] [CAMERA] Flutter camera freezes when start recording video on Android Sep 17, 2019
@Sp4Rx
Copy link

Sp4Rx commented Sep 21, 2019

Facing similar error on one of my test Samsung phone (GT N7100) . I have also tried the example flutter camera app (camera: ^0.5.4+1) but it freezes and the recorded video is also corrupted. Here ResolutionPreset is medium.

Logs when recording started:

I/RequestQueue(21539): Repeating capture request cancelled.
I/CameraDeviceState(21539): Legacy camera service transitioning to state IDLE
I/CameraDeviceState(21539): Legacy camera service transitioning to state CONFIGURING
I/RequestThread-1(21539): Configure outputs: 2 surfaces configured.
D/Camera  (21539): app passed NULL surface
I/CameraDeviceState(21539): Legacy camera service transitioning to state IDLE
W/art     (21539): Long monitor contention event with owner method=void java.lang.Object.wait!() from Object.java:4294967294 waiters=0 for 235ms
I/RequestQueue(21539): Repeating capture request set.
W/LegacyRequestMapper(21539): convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
I/CameraDeviceState(21539): Legacy camera service transitioning to state CAPTURING

At this point the surface is working, I can see things moving.


Logs after recording stopped

E/[EGL-ERROR](21539): void __egl_platform_dequeue_buffer(egl_surface*):1618: failed to dequeue buffer from native window (0x530ae438); err = -19, buf = 0x0,max_allowed_dequeued_buffers 3
E/[EGL-ERROR](21539): void __egl_platform_dequeue_buffer(egl_surface*):1618: failed to dequeue buffer from native window (0x530ae438); err = -19, buf = 0x0,max_allowed_dequeued_buffers 3
E/[EGL-ERROR](21539): void __egl_platform_dequeue_buffer(egl_surface*):1618: failed to dequeue buffer from native window (0x530ae438); err = -19, buf = 0x0,max_allowed_dequeued_buffers 3
E/[EGL-ERROR](21539): void __egl_platform_dequeue_buffer(egl_surface*):1618: failed to dequeue buffer from native window (0x530ae438); err = -19, buf = 0x0,max_allowed_dequeued_buffers 3
E/CameraDeviceGLThread-1(21539): Received exception on GL render thread: 
E/CameraDeviceGLThread-1(21539): java.lang.IllegalStateException: swapBuffers: EGL error: 0x300d
E/CameraDeviceGLThread-1(21539): 	at android.hardware.camera2.legacy.SurfaceTextureRenderer.checkEglError(SurfaceTextureRenderer.java:544)
E/CameraDeviceGLThread-1(21539): 	at android.hardware.camera2.legacy.SurfaceTextureRenderer.swapBuffers(SurfaceTextureRenderer.java:537)
E/CameraDeviceGLThread-1(21539): 	at android.hardware.camera2.legacy.SurfaceTextureRenderer.drawIntoSurfaces(SurfaceTextureRenderer.java:741)
E/CameraDeviceGLThread-1(21539): 	at android.hardware.camera2.legacy.GLThreadManager$1.handleMessage(GLThreadManager.java:105)
E/CameraDeviceGLThread-1(21539): 	at android.os.Handler.dispatchMessage(Handler.java:98)
E/CameraDeviceGLThread-1(21539): 	at android.os.Looper.loop(Looper.java:148)
E/CameraDeviceGLThread-1(21539): 	at android.os.HandlerThread.run(HandlerThread.java:61)
I/CameraDeviceState(21539): Legacy camera service transitioning to state ERROR
E/CameraCaptureSession(21539): Session 1: Exception while stopping repeating: 
E/CameraCaptureSession(21539): android.hardware.camera2.CameraAccessException: The camera device has encountered a serious error
E/CameraCaptureSession(21539): 	at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:2000)
E/CameraCaptureSession(21539): 	at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:913)
E/CameraCaptureSession(21539): 	at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:378)
E/CameraCaptureSession(21539): 	at io.flutter.plugins.camera.Camera.closeCaptureSession(Camera.java:508)
E/CameraCaptureSession(21539): 	at io.flutter.plugins.camera.Camera.createCaptureSession(Camera.java:304)
E/CameraCaptureSession(21539): 	at io.flutter.plugins.camera.Camera.createCaptureSession(Camera.java:297)
E/CameraCaptureSession(21539): 	at io.flutter.plugins.camera.Camera.startPreview(Camera.java:436)
E/CameraCaptureSession(21539): 	at io.flutter.plugins.camera.Camera.stopVideoRecording(Camera.java:385)
E/CameraCaptureSession(21539): 	at io.flutter.plugins.camera.CameraPlugin.onMethodCall(CameraPlugin.java:112)
E/CameraCaptureSession(21539): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/CameraCaptureSession(21539): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/CameraCaptureSession(21539): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:643)
E/CameraCaptureSession(21539): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/CameraCaptureSession(21539): 	at android.os.MessageQueue.next(MessageQueue.java:323)
E/CameraCaptureSession(21539): 	at android.os.Looper.loop(Looper.java:135)
E/CameraCaptureSession(21539): 	at android.app.ActivityThread.main(ActivityThread.java:5461)
E/CameraCaptureSession(21539): 	at java.lang.reflect.Method.invoke(Native Method)
E/CameraCaptureSession(21539): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
E/CameraCaptureSession(21539): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I/flutter (21539): Error: videoRecordingFailed
I/flutter (21539): Error Message: The camera device has encountered a serious error
E/RequestThread-1(21539): Timed out while waiting for request to complete.
W/CaptureCollector(21539): Preview buffers dropped for request: 1
E/CameraDeviceState(21539): Cannot receive result while in state: 0
E/CameraDeviceState(21539): Cannot receive result while in state: 0
E/CameraDeviceState(21539): Cannot receive result while in state: 0
E/BufferQueueProducer(21539): [SurfaceTexture-1-21539-31] queueBuffer: BufferQueue has been abandoned

After recording stopped the surface freezes.


Flutter doctor:

[√] Flutter (Channel stable, v1.7.8+hotfix.3, on Microsoft Windows [Version 10.0.17763.737], locale en-IN)
    • Flutter version 1.7.8+hotfix.3 at C:\Users\heysu\Documents\flutter
    • Framework revision b712a172f9 (2 months ago), 2019-07-09 13:14:38 -0700
    • Engine revision 54ad777fd2
    • Dart version 2.4.0


[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\heysu\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    • All Android licenses accepted.

[√] Android Studio (version 3.5)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 38.2.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.38.1)
    • VS Code at C:\Users\heysu\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.4.1

[√] Connected device (1 available)
    • GT N7100 • 4df7985e7bf1cf25 • android-arm • Android 6.0.1 (API 23)

More debug info of this phone

Model:GT-N7100
Manufacturer:samsung
Build:6.0.1
SDK:23
------------------------------------------
Camera ID: 0
Camera Facing: Back
SupportLevel:LEGACY
Hardware Support Level:LEGACY
Manual exposure:0
Auto exposure:1
Auto exposure, always flash:1
Auto exposure, auto flash:1
Auto exposure, auto flash, red eye reduction:0
AE Lock:1
Manual focus:1
Auto focus:1
Auto focus macro:1
Auto focus continuous picture:1
Auto focus continuous video:1
Auto focus EDOF:0
White balance off:0
Automatic white balance:1
WB: cloudy day:1
WB: day:1
WB: fluorescent:1
WB: incandescent:1
WB: shade:0
WB: twilight:0
WB: warm fluorescent:0
AWB Lock:1
RawCapture:1
BurstCapture:1
previewSize: 960 * 720 (4:3)
previewSize: 960 * 640 (3:2)
previewSize: 704 * 576 (11:9)
previewSize: 640 * 480 (4:3)
previewSize: 352 * 288 (11:9)
previewSize: 320 * 240 (4:3)
photoSize: 640 * 480 (4:3)
photoSize: 1024 * 768 (4:3)
photoSize: 1280 * 720 (16:9)
photoSize: 1600 * 1200 (4:3)
photoSize: 2560 * 1920 (4:3)
photoSize: 3264 * 2448 (4:3)
photoSize: 2048 * 1536 (4:3)
photoSize: 3264 * 1836 (16:9)
photoSize: 2048 * 1152 (16:9)
photoSize: 3264 * 2176 (3:2)
videoSize: 960 * 720 (4:3)
videoSize: 960 * 640 (3:2)
videoSize: 704 * 576 (11:9)
videoSize: 640 * 480 (4:3)
videoSize: 352 * 288 (11:9)
videoSize: 320 * 240 (4:3)
------------------------------------------
Camera ID: 1
Camera Facing: Front
SupportLevel:LEGACY
Hardware Support Level:LEGACY
Manual exposure:0
Auto exposure:1
Auto exposure, always flash:0
Auto exposure, auto flash:0
Auto exposure, auto flash, red eye reduction:0
AE Lock:0
Manual focus:1
Auto focus:0
Auto focus macro:0
Auto focus continuous picture:0
Auto focus continuous video:0
Auto focus EDOF:0
White balance off:0
Automatic white balance:1
WB: cloudy day:1
WB: day:1
WB: fluorescent:1
WB: incandescent:1
WB: shade:0
WB: twilight:0
WB: warm fluorescent:0
AWB Lock:0
RawCapture:1
BurstCapture:1
previewSize: 704 * 704 (1:1)
previewSize: 640 * 480 (4:3)
previewSize: 320 * 320 (1:1)
previewSize: 320 * 240 (4:3)
photoSize: 1280 * 960 (4:3)
photoSize: 1392 * 1392 (1:1)
photoSize: 640 * 480 (4:3)
photoSize: 1280 * 720 (16:9)
photoSize: 720 * 480 (3:2)
photoSize: 320 * 240 (4:3)
videoSize: 704 * 704 (1:1)
videoSize: 640 * 480 (4:3)
videoSize: 320 * 320 (1:1)
videoSize: 320 * 240 (4:3)

@Sp4Rx
Copy link

Sp4Rx commented Sep 21, 2019

And the above error comes which @divyanshub024 mentioned is when the ResolutionPreset is high on the CameraController.

 controller = CameraController(
      cameraDescription,
      ResolutionPreset.high,  //This is high
      enableAudio: enableAudio,
    );

Error Logs:

I/RequestQueue(21539): Repeating capture request cancelled.
I/CameraDeviceState(21539): Legacy camera service transitioning to state IDLE
E/CameraDevice-1-LE(21539): Surface with size (w=1280, h=720) and format 0x1 is not valid, size not in valid set: [704x704, 640x480, 320x320, 320x240]
W/CameraDevice-JV-1(21539): Stream configuration failed
E/CameraCaptureSession(21539): Session 1: Failed to create capture session; configuration failed
E/MediaRecorder(21539): stop called in an invalid state: 8
I/flutter (21539): Error: videoRecordingFailed
I/flutter (21539): Error Message: null

All this occurred on Samsung (GT N7100) as far I have tested.

@troy379
Copy link

troy379 commented Oct 17, 2019

I'm having the same freeze for Pixel 3 with Android Q onboard...

@Sp4Rx
Copy link

Sp4Rx commented Oct 19, 2019

I'm having the same freeze for Pixel 3 with Android Q onboard...

@troy379 have you tried low or medium settings?

@troy379
Copy link

troy379 commented Oct 21, 2019

@Sp4Rx Yes, I've tried the medium one and got the same behavior

@divyanshub024
Copy link
Author

For me, it works when ResolutionPreset is medium.

@PerLycke
Copy link

I hope you're not suggesting decreasing the resolution preset is the correct way to counter this bug @divyanshub024

This is something that happens after migrating to the new embedding. I don't know why yet but I'm hopeful @matthew-carroll or someone else from the Flutter team will figure it out. On my Note 10+ it freezes after a couple of seconds moving the camera around. Until this is properly fixed, I guess you need to roll back to a commit before the new embedding commits.

E/CameraCaptureSession( 5749): Session 1: Exception while stopping repeating: 
E/CameraCaptureSession( 5749): android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): The camera device has encountered a serious error
E/CameraCaptureSession( 5749): 	at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:2435)
E/CameraCaptureSession( 5749): 	at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1126)
E/CameraCaptureSession( 5749): 	at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:526)
E/CameraCaptureSession( 5749): 	at io.flutter.plugins.camera.Camera.closeCaptureSession(Camera.java:539)
E/CameraCaptureSession( 5749): 	at io.flutter.plugins.camera.Camera.close(Camera.java:545)
E/CameraCaptureSession( 5749): 	at io.flutter.plugins.camera.Camera$2.onError(Camera.java:203)
E/CameraCaptureSession( 5749): 	at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.notifyError(CameraDeviceImpl.java:1929)
E/CameraCaptureSession( 5749): 	at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.lambda$Sm85frAzwGZVMAK-NE_gwckYXVQ(Unknown Source:0)
E/CameraCaptureSession( 5749): 	at android.hardware.camera2.impl.-$$Lambda$CameraDeviceImpl$CameraDeviceCallbacks$Sm85frAzwGZVMAK-NE_gwckYXVQ.accept(Unknown Source:8)
E/CameraCaptureSession( 5749): 	at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:258)
E/CameraCaptureSession( 5749): 	at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:182)
E/CameraCaptureSession( 5749): 	at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:77)
E/CameraCaptureSession( 5749): 	at android.os.Handler.handleCallback(Handler.java:873)
E/CameraCaptureSession( 5749): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/CameraCaptureSession( 5749): 	at android.os.Looper.loop(Looper.java:216)
E/CameraCaptureSession( 5749): 	at android.app.ActivityThread.main(ActivityThread.java:7263)
E/CameraCaptureSession( 5749): 	at java.lang.reflect.Method.invoke(Native Method)
E/CameraCaptureSession( 5749): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
E/CameraCaptureSession( 5749): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
E/BufferQueueProducer( 5749): [ImageReader-1280x720f23m2-5749-1] dequeueBuffer: attempting to exceed the max dequeued buffer count (9)

@matthew-carroll matthew-carroll added this to To do in Add-to-app 2020Q1 via automation Oct 25, 2019
@matthew-carroll
Copy link
Contributor

@bparrishMines do you happen to know anything about this bug? Do you know if the migrated plugin suffers from this?

@bparrishMines
Copy link
Contributor

@matthew-carroll @PerLycke It looks like this was reported before the plugin was migrated. I can test it on previous versions to see where it started misbehaving. It may be caused by adding pause and resume functionality or by the resolution fix by @mklim.

@PerLycke
Copy link

Ok thanks. I did exactly this now to reproduce the issue:

Run ml_vision example package together with latest camera source. In the example app I selected CameraPreviewScanner. Took just a couple of seconds for everything to freeze.

Tested on the Note 10+.

Btw, we have a production app in store with camera sources up to 86d245f with no issues, so it's not the commits you mention @bparrishMines , but something after that.

@PerLycke
Copy link

@bparrishMines It seems like a different issue from the one OP encountered, I'm not completely sure why I ended up posting it here. I hope my steps to reproduce it above makes sense though. Should I open a new issue?

@PerLycke
Copy link

PerLycke commented Oct 26, 2019

Actually never mind. The ml_vision camera streaming seems broken in unmodified state on the Note 10+. I reverted back the camera plugin 6 months and it's still broken, so no recent commits is the cause.

We do some lifting of heavy camera tasks to background thread in our production app, and it's working when having these patches.

Sorry that I didn't spend more time debugging before coming to this conclusion, I thought the ml_vision / camera streaming was working out of the box.

Bottom line: ml_vision camera streaming is not working on the Note 10+.

Edit: Opened a new issue for this, as other might experience the same issue. #43566

@syonip
Copy link

syonip commented Oct 30, 2019

I'm having the same issue as OP, on a Xiaomi A1.
My device can take full HD videos, but when using the flutter camera plugin, any resolution above "medium" causes the the camera to freeze, with the exception ...and format 0x22 is not valid, size not in valid set:...

From doing a bit of online research, it seems that the cause is flutter camera plugin's usage of android's Camera2 API, which many android devices don't support.

I've tested Camera(1) API on the same device and it can record full HD videos.

I've come across this library which implements a good fallback to the old Camera API when necessary: https://github.com/infinum/Android-GoldenEye

It might be a good direction to follow for solving this problem within the flutter camera plugin.

@matthew-carroll matthew-carroll removed this from To do in Add-to-app 2020Q1 Nov 15, 2019
@TahaTesser TahaTesser added customer: crowd Affects or could affect many people, though not necessarily a specific customer. p: first party labels Mar 12, 2020
@Loopex2019
Copy link

After Updating to the latest version (in this case : 0.5.7+4) the video recording works fine for ResolutionPreset.high , but for the ultraHigh , veryHigh and max it doesn't freeze but instead of that it stretches the camera .

@AkhilSaji
Copy link

same here

@aghanti7
Copy link

Same issue as OP. Any updates on this flutter team? Camera plugin is turning out to be a real pain and roadblock in using flutter for a production app!

@ashokYadav0311
Copy link

Hi Team,
any update on this issue.

@ariefwijaya
Copy link

Same here, stop recording always encountered error :

Error Message: Failed to configure camera session

I'm just using Example from camera plugin.

@mesiser
Copy link

mesiser commented Jun 27, 2020

Same problem. Did anyone find any workarounds?

@spideyduulr
Copy link

I also have it in IOS

@harshapulikollu
Copy link

Facing same issue on different devices.

ResolutionPreset is max

  • Emulator with API R:
    Aspect ratio: 0.5625
    Size: 1280 X 720
    Front camera: CameraPreview working and Video records as expected. ✅
    Rear camera: CameraPreview freezes and video corrupted.❌

  • Xiaomi Mi A2 with android 10:
    Aspect ratio: 0.5625
    Size: 1280 X 720
    Front camera: CameraPreview working and Video records as expected.✅
    Rear camera: CameraPreview freezes and video corrupted.❌

  • Xiaomi Redmi 5A with Android 8.1:
    Aspect ratio: 0.5625
    Size: 1280 X 720
    Front camera: CameraPreview freezes, video corrupted, and image preview was weird.❌
    Rear camera: CameraPreview freezes and video corrupted.❌

Camera is core feature that many apps use, this needs to fix ASAP.

@apdanduran
Copy link

Has a solution occurred about this problem?

@aghanti7
Copy link

I can't think of anything other than migrating to image_picker :(

@harshapulikollu
Copy link

Has a solution occurred about this problem?

Image capturing and video recording working as expected with medium resolution on emulator and two other devices I tested.
If quality is not your priority then you can try this option, else image picker is the way.

@kuyazee
Copy link

kuyazee commented Oct 28, 2020

I am testing in Asus Zenfone Max 3 and All Presets are not working

Flutter Doctor

[✓] Flutter (Channel stable, 1.22.2, on Mac OS X 10.15.7 19H2, locale en-PH)
    • Flutter version 1.22.2 at /Users/zonilyjamepesquera/flutter
    • Framework revision 84f3d28555 (12 days ago), 2020-10-15 16:26:19 -0700
    • Engine revision b8752bbfff
    • Dart version 2.10.2

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/zonilyjamepesquera/Library/Android/sdk
    • Platform android-29, 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_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.1, Build version 12A7403
    • CocoaPods version 1.9.3

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 49.0.2
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.50.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.15.1

[✓] Connected device (3 available)
    • Redmi 7 (mobile)      • 118af079                  • android-arm64 • Android 9 (API 28)
    • ASUS X00DDA (mobile)  • H4AXHM03W879CD5           • android-arm64 • Android 8.1.0 (API 27)
    • TempuraPhone (mobile) • 00008030-001925DE3C12802E • ios           • iOS 14.0.1

Other Info

  • Redmi 7 (mobile) - Works fine
  • ASUS X00DDA (mobile) - is the Zenfome Max 3 and doesn't work at all
  • TempuraPhone (mobile) - Works fine

@Sp4Rx
Copy link

Sp4Rx commented Oct 28, 2020

Hey @kuyazee could you check this solution? Its a hacky one though
#41370

@aschitz
Copy link

aschitz commented Nov 12, 2020

I have a small freeze when i start or stop recording videos with every resolution setting.
Used device: Samsung S9

@mvanbeusekom
Copy link

mvanbeusekom commented Dec 30, 2020

I am trying to reproduce the issue mentioned by the OP but having a hard time doing so on the current version (0.6.3+2). I am trying to reproduce it using the [camera example] App and tested on the following devices (all I have available at the moment):

  • Samsung Galaxy S6 (SM-G900F);
  • LG Nexus 5X;
  • Emulator (Android Q and R).

Can anyone confirm this is still an issue is in the latest versions of the plugin? If so could you supply some information on the device you are testing on (make/ model/ Android version)?

@harshapulikollu
Copy link

Hi @mvanbeusekom ,
I have upgraded camera plugin from 0.5.7+3 => 0.6.3+2 as suggested. Then I tried the example code provided in camera plugin example page .
After running the on my emulator (Android 11 - API R) I couldn't see the camera preview at all instead I see a message Tap a Camera, even I tried to change cameras from front and rear.
I also tested this on the physical device Xiaomi Redmi 5A (Android 8.0) and found the same issue, the Screen showing Tap a Camera.
As said I tried to click on the radio button to change the cameras from rear to front and vice versa but, not working.

All the permissions were granted for the application, required to access the camera. By downgrading to 0.5.7+3, I was able to access the camera in the same application.

Screenshot_1609437712

@mvanbeusekom
Copy link

Hi @harshapulikollu,

This can happen when you have run flutter pub upgrade. Due to an unfortunate configuration error in the camera 0.6.3+2 release it depends on the wrong version of the camera_platform_interface package which contains a breaking change. This has already been fixed in master but hasn't been published yet.

To work around this issue you can add a dependency override to your pubspec.yaml file and run a flutter pub get command:

  dependency_overrides:
    camera_platform_interface: ">=1.0.4 <1.1.0"

See also issue #73091 for more details.

@harshapulikollu
Copy link

Hi @mvanbeusekom,

Thank you for the suggestion, I added the dependency overrides and now with the camera update(0.6.3+2) version able to access the video and tested the video recording.
It's working as expected on the device( Xiaomi Redmi 5A) and that initially wasn't working.

@mvanbeusekom
Copy link

@harshapulikollu thank you very much for confirming it now works on the Xiaomi Redmi 5A, that is very helpful to know.

@divyanshub024, it's been a long time since you posted this issue, but noticed you are still active in the community, could you maybe confirm if this is still an issue on the latest version of the camera plugin?

@divyanshub024
Copy link
Author

Hey @mvanbeusekom!! Looks like this issue does not occur on the latest version. I'm closing this issue. If anyone faces this issue again then we'll reopen this issue.

Thanks!!

@mvanbeusekom
Copy link

Thanks a lot @divyanshub024!

@kamleshwebtech
Copy link

I am still facing this issue. bug log is as:

I/flutter ( 3986): Error: camera initialized
I/RequestQueue( 3986): Repeating capture request cancelled.
I/RequestQueue( 3986): Repeating capture request set.
W/LegacyRequestMapper( 3986): convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
W/LegacyRequestMapper( 3986): mapAeAndFlashMode - Ignore control.aeMode == ON_AUTO_FLASH;camera does not support it
W/LegacyRequestMapper( 3986): convertRequestToMetadata - Ignoring android.lens.focusDistance false, only 0.0f is supported
I/art ( 3986): Do partial code cache collection, code=60KB, data=61KB
I/art ( 3986): After code cache collection, code=60KB, data=61KB
I/art ( 3986): Increasing code cache capacity to 256KB
D/AndroidRuntime( 3986): Shutting down VM
E/AndroidRuntime( 3986): FATAL EXCEPTION: main
E/AndroidRuntime( 3986): Process: com.example.whatsupflutter, PID: 3986
E/AndroidRuntime( 3986): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Enum.ordinal()' on a null object reference
E/AndroidRuntime( 3986): at io.flutter.plugins.camera.DeviceOrientationManager.getMediaOrientation(DeviceOrientationManager.java:60)
E/AndroidRuntime( 3986): at io.flutter.plugins.camera.DeviceOrientationManager.getMediaOrientation(DeviceOrientationManager.java:55)
E/AndroidRuntime( 3986): at io.flutter.plugins.camera.Camera.runPictureCapture(Camera.java:552)
E/AndroidRuntime( 3986): at io.flutter.plugins.camera.Camera.access$1500(Camera.java:73)
E/AndroidRuntime( 3986): at io.flutter.plugins.camera.Camera$3.processCapture(Camera.java:510)
E/AndroidRuntime( 3986): at io.flutter.plugins.camera.Camera$3.onCaptureCompleted(Camera.java:442)
E/AndroidRuntime( 3986): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 3986): at android.hardware.camera2.dispatch.InvokeDispatcher.dispatch(InvokeDispatcher.java:39)
E/AndroidRuntime( 3986): at android.hardware.camera2.dispatch.HandlerDispatcher$1.run(HandlerDispatcher.java:65)
E/AndroidRuntime( 3986): at android.os.Handler.handleCallback(Handler.java:754)
E/AndroidRuntime( 3986): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 3986): at android.os.Looper.loop(Looper.java:165)
E/AndroidRuntime( 3986): at android.app.ActivityThread.main(ActivityThread.java:6375)
E/AndroidRuntime( 3986): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 3986): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
E/AndroidRuntime( 3986): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
I/Process ( 3986): Sending signal. PID: 3986 SIG: 9
Lost connection to device.
Exited (sigterm)

@mvanbeusekom
Copy link

@kamleshwebtech could you please share some more information on your environment? The following information would be very helpful:

  1. The version of the camera plugin you are using;
  2. The output of flutter doctor -v command;

@mmanela
Copy link

mmanela commented Feb 8, 2021

@mvanbeusekom I am new to flutter and the camera plugin but I think I am hitting the same issue. I am using the camera version 0.7.0+2. The camera preview works fine in the emulator by on my device Sony XPeria F5321 (mobile) android-arm64 • Android 8.0.0 (API 26) it errors with the follow and doesn't show the preview. I created an issue with more details (#75641)

The error I am getting is

E/CameraCaptureSession(18550): Session 0: Exception while stopping repeating:
E/CameraCaptureSession(18550): android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): The camera device has encountered a serious error
E/CameraCaptureSession(18550): 	at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:2220)
E/CameraCaptureSession(18550): 	at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:993)
E/CameraCaptureSession(18550): 	at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:391)
E/CameraCaptureSession(18550): 	at io.flutter.plugins.camera.Camera.closeCaptureSession(Camera.java:1147)
E/CameraCaptureSession(18550): 	at io.flutter.plugins.camera.Camera.close(Camera.java:1153)
E/CameraCaptureSession(18550): 	at io.flutter.plugins.camera.Camera$1.onError(Camera.java:247)
E/CameraCaptureSession(18550): 	at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks$1.run(CameraDeviceImpl.java:1791)
E/CameraCaptureSession(18550): 	at android.os.Handler.handleCallback(Handler.java:789)
E/CameraCaptureSession(18550): 	at android.os.Handler.dispatchMessage(Handler.java:98)
E/CameraCaptureSession(18550): 	at android.os.Looper.loop(Looper.java:251)
E/CameraCaptureSession(18550): 	at android.app.ActivityThread.main(ActivityThread.java:6589)
E/CameraCaptureSession(18550): 	at java.lang.reflect.Method.invoke(Native Method)
E/CameraCaptureSession(18550): 	at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
E/CameraCaptureSession(18550): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
I/zygote64(18550): Thread[3,tid=18564,WaitingInMainSignalCatcherLoop,Thread*=0x720a0c4400,peer=0x17dc05e8,"Signal Catcher"]: reacting to signal 3
I/zygote64(18550):
I/zygote64(18550): Wrote mini stack traces to '/data/anr/traces.txt.mini'
I/zygote64(18550): Wrote stack traces to '/data/anr/traces.txt'
E/FirebaseInstanceId(18550): binding to the service failed

Flutter Doctor Output

[√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.19042.789], locale en-US)
    • Flutter version 1.22.6 at C:\dev\flutter
    • Framework revision 9b2d32b605 (2 weeks ago), 2021-01-22 14:36:39 -0800
    • Engine revision 2f0af37152
    • Dart version 2.10.5


[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at C:\Users\mmanela\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[!] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code, 64-bit edition (version 1.52.1)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.19.0

[√] Connected device (2 available)
    • F5321 (mobile)                     • BH903K6A5P    • android-arm64 • Android 8.0.0 (API 26)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86   • Android 10 (API 29) (emulator)

! Doctor found issues in 1 category.

@jodafm
Copy link

jodafm commented Jul 9, 2021

I face the same error with a Samsung SM J730G.
This issue should be reopened.


E/CameraCaptureSession(13206): Session 1: Exception while stopping repeating:
E/CameraCaptureSession(13206): android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): The camera device has encountered a serious error
E/CameraCaptureSession(13206): 	at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:2219)
E/CameraCaptureSession(13206): 	at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1003)
E/CameraCaptureSession(13206): 	at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:394)
E/CameraCaptureSession(13206): 	at io.flutter.plugins.camera.Camera.closeCaptureSession(Camera.java:1171)
E/CameraCaptureSession(13206): 	at io.flutter.plugins.camera.Camera.close(Camera.java:1177)
E/CameraCaptureSession(13206): 	at io.flutter.plugins.camera.Camera$1.onError(Camera.java:252)
E/CameraCaptureSession(13206): 	at android.hardware.camera2.impl.CameraDeviceImpl$11.run(CameraDeviceImpl.java:2251)
E/CameraCaptureSession(13206): 	at android.os.Handler.handleCallback(Handler.java:790)
E/CameraCaptureSession(13206): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/CameraCaptureSession(13206): 	at android.os.Looper.loop(Looper.java:164)
E/CameraCaptureSession(13206): 	at android.app.ActivityThread.main(ActivityThread.java:7000)
E/CameraCaptureSession(13206): 	at java.lang.reflect.Method.invoke(Native Method)
E/CameraCaptureSession(13206): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
E/CameraCaptureSession(13206): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.0.1 20B29 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] IntelliJ IDEA Community Edition (version 2020.3.2)
[✓] VS Code (version 1.57.1)
[✓] Connected device (2 available)

• No issues found!

@jodafm
Copy link

jodafm commented Jul 9, 2021

It seems that this issue going to be fixed with this PR: flutter/plugins#3651

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer: crowd Affects or could affect many people, though not necessarily a specific customer. p: camera The camera plugin package flutter/packages repository. See also p: labels. platform-android Android applications specifically
Projects
None yet
Development

No branches or pull requests