iOS AVFoundation захватывает изображение слишком медленно - PullRequest
2 голосов
/ 23 января 2012

Я создаю сессию и AVCaptureStillImageOutput следующим образом:

__imageCaptureSession = [[AVCaptureSession alloc] init];
__imageCaptureSession.sessionPreset = AVCaptureSessionPresetPhoto;

__imageCapture = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil];
[__imageCapture setOutputSettings:outputSettings];
[__imageCaptureSession addInput:input];
[__imageCaptureSession addOutput:__imageCapture];

вход задняя камера.Чтобы сделать фото я использую код ниже.Проблема в том, что съемка занимает слишком много времени.Возможно ли решить эту проблему?

AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in __imageCapture.connections)
{
  for (AVCaptureInputPort *port in [connection inputPorts])
  {
    if ([[port mediaType] isEqual:AVMediaTypeVideo] )
    {
      videoConnection = connection;
      break;
    }
  }
  if (videoConnection) { break; }
}

[__imageCapture captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {

  //metadata
  CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
  NSMutableDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:(NSDictionary*)exifAttachments]; 

  //image
  NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
  UIImage *image = [[UIImage alloc] initWithData:imageData];

  //send notification
  NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[image retain] ,kImageKey,
                       [metadata retain], kMetadataKey,
                       nil];
  [metadata release];    
  [[NSNotificationCenter defaultCenter]postNotificationName:kTakePhotoNotification object:nil userInfo:dict];

  [__captureSession stopRunning];
  [image release];
}];
...