-
Notifications
You must be signed in to change notification settings - Fork 28.6k
CameraController with ResolutionPreset.max causes Unsupported format Error #163202
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
Comments
I can confirm it happens on an iPhone 15 (iOS 18.2) and iPhone SE 2022 (18.0) too:
Switching the |
Thanks for your report. I also can reproduce this issue on Output log*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureDevice _setActiveFormat:resetVideoZoomFactorAndMinMaxFrameDurations:sessionPreset:] Unsupported format (<FLTDefaultCaptureDeviceFormat: 0x2809a8070>) - use -formats to discover valid formats'
*** First throw call stack:
(0x180513c60 0x197d43ee4 0x1a3b0d07c 0x100c1cb08 0x100c149a4 0x100c12ac0 0x100c1148c 0x100c1130c 0x1801d3094 0x1801d4094 0x18017a73c 0x18017b1f4 0x180184ec8 0x1db88ce00 0x1db88c92c)
libc++abi: terminating with uncaught exception of type NSException
* thread #22, queue = 'io.flutter.camera.captureSessionQueue', stop reason = signal SIGABRT
frame #0: 0x00000001badf7bbc libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`__pthread_kill:
-> 0x1badf7bbc <+8>: b.lo 0x1badf7bd8 ; <+36>
0x1badf7bc0 <+12>: stp x29, x30, [sp, #-0x10]!
0x1badf7bc4 <+16>: mov x29, sp
0x1badf7bc8 <+20>: bl 0x1badf360c ; cerror_nocancel
Target 0: (Runner) stopped.
Lost connection to device.
Exited. Sample codeimport 'dart:async';
import 'dart:io';
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
// Ensure that plugin services are initialized so that `availableCameras()`
// can be called before `runApp()`
WidgetsFlutterBinding.ensureInitialized();
// Obtain a list of the available cameras on the device.
final cameras = await availableCameras();
// Get a specific camera from the list of available cameras.
final firstCamera = cameras.first;
runApp(
MaterialApp(
theme: ThemeData.dark(),
home: TakePictureScreen(
// Pass the appropriate camera to the TakePictureScreen widget.
camera: firstCamera,
),
),
);
}
// A screen that allows users to take a picture using a given camera.
class TakePictureScreen extends StatefulWidget {
const TakePictureScreen({
super.key,
required this.camera,
});
final CameraDescription camera;
@override
TakePictureScreenState createState() => TakePictureScreenState();
}
class TakePictureScreenState extends State<TakePictureScreen> {
late CameraController _controller;
late Future<void> _initializeControllerFuture;
@override
void initState() {
super.initState();
// To display the current output from the Camera,
// create a CameraController.
_controller = CameraController(
// Get a specific camera from the list of available cameras.
widget.camera,
// Define the resolution to use.
ResolutionPreset.max,
);
// Next, initialize the controller. This returns a Future.
_initializeControllerFuture = _controller.initialize();
}
@override
void dispose() {
// Dispose of the controller when the widget is disposed.
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Take a picture')),
// You must wait until the controller is initialized before displaying the
// camera preview. Use a FutureBuilder to display a loading spinner until the
// controller has finished initializing.
body: FutureBuilder<void>(
future: _initializeControllerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
// If the Future is complete, display the preview.
return CameraPreview(_controller);
} else {
// Otherwise, display a loading indicator.
return const Center(child: CircularProgressIndicator());
}
},
),
floatingActionButton: FloatingActionButton(
// Provide an onPressed callback.
onPressed: () async {
// Take the Picture in a try / catch block. If anything goes wrong,
// catch the error.
try {
// Ensure that the camera is initialized.
await _initializeControllerFuture;
// Attempt to take a picture and get the file `image`
// where it was saved.
final image = await _controller.takePicture();
if (!context.mounted) return;
// If the picture was taken, display it on a new screen.
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => DisplayPictureScreen(
// Pass the automatically generated path to
// the DisplayPictureScreen widget.
imagePath: image.path,
),
),
);
} catch (e) {
// If an error occurs, log the error to the console.
print(e);
}
},
child: const Icon(Icons.camera_alt),
),
);
}
}
// A widget that displays the picture taken by the user.
class DisplayPictureScreen extends StatelessWidget {
final String imagePath;
const DisplayPictureScreen({super.key, required this.imagePath});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Display the Picture')),
// The image is stored as a file on the device. Use the `Image.file`
// constructor with the given path to display the image.
body: Image.file(File(imagePath)),
);
}
}
package versionscamera:
dependency: "direct main"
description:
name: camera
sha256: "413d2b34fe28496c35c69ede5b232fb9dd5ca2c3a4cb606b14efc1c7546cc8cb"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
camera_avfoundation:
dependency: transitive
description:
name: camera_avfoundation
sha256: "08a5cfe9ae69887851913f0301eaf2c2198fc3ddc0e0d20b3bdd26a91306eac9"
url: "https://pub.dev"
source: hosted
version: "0.9.18+6" Flutter versions: Channel stable, 3.29.0
Channel master, 3.30.0-1.0.pre.168 |
I would like to add that specifying the fps is also crashing the app. I had it set to 30 and once I removed the line, it began to work normal, as long as the ResolutionPreset was not max |
@noze12 which version of camera plugin are you using? if it's the latest version, can you try to revert to earlier version and see if it's a regression? |
I was facing the same problem and regressing was not solving. In my case the local cache of the librarie is not crashing, just when the version is created on the CI without any cache. |
I was initially using camera 0.10.6. After upgrading the Flutter version, this issue started occurring without changing the camera version. When I checked the differences in pubspec.lock, I noticed that the version of camera_avfoundation had changed. After reverting it to the previous version, 0.9.16, the issue no longer occurred. Therefore, I suspect that the problem lies somewhere in camera_avfoundation version 0.9.17 or later. |
I was experiencing the same problem.
As stated, there seems to be some problem with the latest version of camera_avfoundation, so I overwrote the version as follows and confirmed that it worked properly. (v0.9.18 seems to work fine as well.) dependency_overrides:
camera_avfoundation: 0.9.18 |
Marking this as a regression based on above tests. Thank @noze12, @masa-futa |
@noze12 can you try on |
I confirmed. 0.9.18 -> OK It looks like this has been fixed: flutter/packages#8630 |
Closing as the OP confirmed the regression has been fixed. |
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 |
Steps to reproduce
flutter pub add camera
Expected results
app starts and displays camera preview
Actual results
app crashs
in Xcode console
When I change resolutionPreset to other value, it works correctly.
Code sample
Code sample
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: