How to configure AVCaptureSession for high-quality photos and low resolution (video)?

I would like to shoot high resolution still images using AVCaptureSession. Therefore, the AVCaptureSessionpreset is set to Photo.

It works well. On iPhone 4, the final resolution of a still image is at most 2448x3264 pixels, and the preview resolution (video) is 852 × 640 pixels.

Now, since the preview frames are analyzed to detect objects in the scene, I would like to lower their resolution. How can this be done? I tried setting AVVideoSettingswith a smaller width / height on AVCaptureVideoDataOutput, but this will result in the following error message:

AVCaptureVideoDataOutput setVideoSettings:] - videoSettings dictionary contains one or more unsupported (ignored) keys: (AVVideoHeightKey, AVVideoWidthKey

So, it seems like this is the wrong approach to adjust the size of the preview frames obtained with AVCaptureVideoDataOutput/ AVCaptureVideoDataOutputSampleBufferDelegate. Do you have any idea how you can adjust the resolution of the preview frames?

Any recommendations are welcome, thanks.

+4
source share
3 answers

For recordings only: I finished the setup AVCaptureSessionin the preset Lowwhen aiming the camera. As soon as the shutter starts, the application switches to preset Photo, focuses and captures the image. This method takes from 1 to 2.5 seconds to take a picture, which is not so great, but it is at least a workaround.

0

, activeFormat AVCaptureDevice. AVCaptureSessionPresetInputPriority.

activeFormat AVCaptureDeviceFormat, AVCaptureDevice.formats. , . , , highResolutionStillImageDimensions formatDescription ( CMFormatDescription*, CMVideoFormatDescriptionGetDimensions) .

0

AVCaptureVideoDataOutput, , , .

AVCaptureVideoDataOutput:

AVVideoAverageBitRateKey
AVVideoProfileLevelKey
AVVideoExpectedSourceFrameRateKey
AVVideoMaxKeyFrameIntervalKey

For instance:

private static let videoCompressionOptionsMedium = [AVVideoAverageBitRateKey : 1750000,
                                                    AVVideoProfileLevelKey : AVVideoProfileLevelH264BaselineAutoLevel,
                                                    AVVideoExpectedSourceFrameRateKey : Int(30),
                                                    AVVideoMaxKeyFrameIntervalKey : Int(30)]
-1
source

All Articles