Skip to content

camera_avfoundation returns wrong format FTLDefaultCaptureDeviceFormat when using ResolutionPreset.max #163295

@kreiterd

Description

@kreiterd

Steps to reproduce

That is my first issue that I'm creating, so I'm sorry if anything is not following the protocol. I did my best to include all the information you need to reproduce.

  1. Check out the camera example app
  2. Fix the dependency to camera_avfoundation to 0.9.18.4 which introduces the bug, relating to this commit: flutter/packages@0566371 from @mchudy
  3. Change this line of the camera example app
    kIsWeb ? ResolutionPreset.max : ResolutionPreset.medium
    to
    ResolutionPreset.max
    when initializing the controller.
  4. Run the app on iOS (iOS 18.3.1)

So using the max preset the app crashes when loading a camera with the error message in Xcode:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureDevice _setActiveFormat:resetVideoZoomFactorAndMinMaxFrameDurations:sessionPreset:] Unsupported format (<FLTDefaultCaptureDeviceFormat: 0x3003b4940>) - use -formats to discover valid formats'

Given that this was a "minor" patch, flutter pub get updates the camera_avfoundation automatically to a version above 0.9.18.3.

I'm not so familiar with Objective-C, but I think the error is in the file FTLCaptureDevice.m line 38 to 44. When we use the max preset, it asks for the maximum resolution but does not return the AVCaptureDeviceFormat as before the commit, but returns the wrapper FTLDefaultCaptureDeviceFormat, which is not a valid format.

Expected results

Camera uses max resolution without a crash.

Actual results

App crashes with the error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureDevice _setActiveFormat:resetVideoZoomFactorAndMinMaxFrameDurations:sessionPreset:] Unsupported format (<FLTDefaultCaptureDeviceFormat: 0x3003b4940>) - use -formats to discover valid formats'

Code sample

Checkout the current version of the camera example and use camera_avfoundation 0.9.18+4 and the max preset.
dependency_overrides:
camera_avfoundation: 0.9.18+4

main.dart:
Change the initialization of the controller to this:

Future<void> _initializeCameraController(
   CameraDescription cameraDescription) async {
 final CameraController cameraController = CameraController(
   cameraDescription,
    ResolutionPreset.max,
   enableAudio: enableAudio,
   imageFormatGroup: ImageFormatGroup.jpeg,
 );

Screenshots or Video

No response

Logs

Logs
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureDevice _setActiveFormat:resetVideoZoomFactorAndMinMaxFrameDurations:sessionPreset:] Unsupported format (<FLTDefaultCaptureDeviceFormat: 0x3003b4940>) - use -formats to discover valid formats'

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.27.3, on macOS 15.3.1 24D70 darwin-arm64, locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
	! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.97.0)
[✓] Connected device (1 available)
[✓] Network resources

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions