Skip to content

[camera_avfoundation] Camera stream crashing on iPhone 17 with Unsupported pixel format type when using ResolutionPreset.max #175828

Description

@davidmartos96

[!IMPORTANT]
The problem comes from using ResolutionPreset.max and the plugin algorithm picking the highest resolution camera format without checking if it supports yuv/bgra. The highest resolution camera in the iPhone 17 supports only "btp2".
It seems that it's a new format of iOS 26 https://github.com/dotnet/macios/wiki/CoreVideo-iOS-xcode26.0-b1

/// Apple's documentation
pub const kCVPixelFormatType_96VersatileBayerPacked12: OSType = 0x62747032;

What package does this bug report belong to?

camera

What target platforms are you seeing this bug on?

iOS

Have you already upgraded your packages?

Yes

Dependency versions

camera_avfoundation version 0.9.20+1

Steps to reproduce

  1. With any of the new iPhones (17, 17 Pro or 17 Pro Max)
  2. Change the resolution preset to .max
  3. Start streaming camera frames on any of the available image formats available in the plugin (yuv420 and bgra). Function startImageStream

Expected results

No crash

Actual results

Crashes with the following exception on native

NSInvalidArgumentException: *** -[AVCaptureVideoDataOutput setVideoSettings:] Unsupported pixel format type - use -availableVideoCVPixelFormatTypes

Thread 3 Crashed:
0   CoreFoundation                  0x30cb2b8c8         <redacted>
1   libobjc.A.dylib                 0x306ab17c4         objc_exception_throw
2   AVFCapture                      0x3580728c4         <redacted>
3   camera_avfoundation             0x1056f5ec4         -[FLTDefaultCaptureVideoDataOutput setVideoSettings:]
4   camera_avfoundation             0x1056f0ae8         -[FLTCam setVideoFormat:]
5   camera_avfoundation             0x1056ff104         CameraPlugin.sessionQueueInitializeCamera
6   camera_avfoundation             0x1056ff084         closure in CameraPlugin.initializeCamera
7   camera_avfoundation             0x1056fd8d4         thunk for closure
8   libdispatch.dylib               0x37be11adc         <redacted>
9   libdispatch.dylib               0x37be2b7ec         <redacted>
10  libdispatch.dylib               0x37be1a468         <redacted>
11  libdispatch.dylib               0x37be1af44         <redacted>
12  libdispatch.dylib               0x37be253ec         <redacted>
13  libdispatch.dylib               0x37be24ce4         <redacted>
14  libsystem_pthread.dylib         0x3c27053b8         _pthread_wqthread
15  libsystem_pthread.dylib         0x3c27048c0         start_wqthread

Calling availableVideoPixelFormatTypes lists the following one: btp2. Nothing else.
420v and BGRA are not being listed anymore. I cannot find anything regarding that format in the Apple developer docs or even Google. Could it be a bug in the firmware?

Code sample

The camera example app can be used and add the startImageStream call after camera initialization.

Flutter Doctor output

Flutter 3.29

Unfortunately we cannot reproduce it ourselves as we don't have this iPhone to test, but it's a generalized issue that is affecting all of them. Our app relies heavily on camera stream functionality, hopefully this is an easy solution.
Originally we were using BGRA on iOS and after seeing the crash reported by our users we switched our implementation to use YUV, but it seems that it has the same issue complaining about the pixel format.

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listc: crashStack traces logged to the consolee: OS-version specificAffects only some versions of the relevant operating systeme: device-specificOnly manifests on certain devicesneeds repro infoAutomated crash report whose cause isn't yet knownp: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyt: xcode"xcodebuild" on iOS and general Xcode project managementteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform teamworkaround availableThere is a workaround available to overcome the issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions