I'd like to capture high resolution still images using AVCaptureSession
. Therefore AVCaptureSession
preset is set to Photo
.
This is working well so far. On an iPhone 4 the final still image resolution is at its maximum of 2448x3264 pixels and the preview (video) resolution is 852x640 pixels.
Now, because the preview frames are analyzed to detect objects in the scene, I'd like to lower their resolution. How can this be done?
I've tried to set AVVideoSettings
with a lower width/height to AVCaptureVideoDataOutput
, but this leads to the following error message:
AVCaptureVideoDataOutput setVideoSettings:] - videoSettings dictionary contains one or more unsupported (ignored) keys: (AVVideoHeightKey, AVVideoWidthKey
So it seems this is not the right approach to configure the size of the preview frames received by AVCaptureVideoDataOutput
/ AVCaptureVideoDataOutputSampleBufferDelegate
. Do you have any ideas how the resolution of the preview frames can be configured?
Any advise is welcome, Thank you.
If you want to specify the settings manually, you need to set activeFormat
on the AVCaptureDevice
. This will be implicitly set the session preset to AVCaptureSessionPresetInputPriority
.
The activeFormat
takes a AVCaptureDeviceFormat
but you can only take one from the list of AVCaptureDevice.formats
. You'll need to go through the list and find one that fits your needs. Specifically, check that highResolutionStillImageDimensions
is high enough for desired still capture and formatDescription
(which needs to be inspected with CMFormatDescription*
functions, e.g., CMVideoFormatDescriptionGetDimensions
) matches your desired preview settings.
Just for the records: I ended up configuring AVCaptureSession
in preset Low
while aiming the camera. As soon as the shutter is triggered, the app switches to preset Photo
, performs a focus run and takes the picture. This way it takes between 1 and 2.5 seconds to take a picture, which isn't that great, but it's at least a workaround.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With