How can I use AVCaptureVideoDataOutput with a low-resolution preview profile and take high-resolution photos (when previewing)

I want to use AVFoundation Fameworkto preview and capture photos. I created AVCaptureSessionand added AVCaptureVideoDataOutput, AVCaptureStillImageOutputto that session. I set the preset to AVCaptureSessionPresetLow.

Now I want to take a photo in full resolution . But within the captureStillImageAsynchronouslyFromConnectionresolution is the same as in my preview delegate.

Here is my code:

AVCaptureSession* cameraSession = [[AVCaptureSession alloc] init];
cameraSession.sessionPreset = AVCaptureSessionPresetLow;

AVCaptureVideoDataOutput* output = [[AVCaptureVideoDataOutput alloc] init];
[cameraSession addOutput:output];

AVCaptureStillImageOutput* cameraStillImage = [[AVCaptureStillImageOutput alloc] init];
[cameraSession addOutput:cameraStillImage];

// delegation
dispatch_queue_t queue = dispatch_queue_create("MyQueue", NULL);
[output setSampleBufferDelegate:self queue:queue];
dispatch_release(queue);

[cameraSession startRunning];

Photo:

//[cameraSession beginConfiguration];
//[cameraSession setSessionPreset:AVCaptureSessionPresetPhoto];  <-- slow
//[cameraSession commitConfiguration];
[cameraStillImage captureStillImageAsynchronouslyFromConnection:photoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error)
{
    ...
}];

I tried this by changing the preset to a photo just for image capture. But it is very slow (it takes 2-3 seconds to change the preset). I do not want to have such a big delay.

How can i do this? Thank.

+5

All Articles