私のアプリケーションでは、 AVCaptureVideoPreviewLayer を表示し、ユーザーがAVCaptureOutputのcaptureStillImageAsynchronouslyFromConnection関数を使用してボタンをクリックすると静止画像をキャプチャしています。これは、iPhone 5 まではうまく機能していましたが、iPhone 5 では完全には機能しませんでした。
私のセットアップコードは次のとおりです。
...
self.imageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[self.imageOutput setOutputSettings:outputSettings];
self.captureSession = [[[AVCaptureSession alloc] init] autorelease];
[self.captureSession addInput:self.rearFacingDeviceInput];
[self.captureSession addOutput:self.imageOutput];
[self.captureSession setSessionPreset:AVCaptureSessionPresetPhoto];
self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
self.previewLayer.frame = CGRectMake(0, 0, 320, 427);
self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspect;
[self.captureSession startRunning];
[outputSettings release];
私のキャプチャ方法は次のとおりです。
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in self.imageOutput.connections){
for (AVCaptureInputPort *port in [connection inputPorts]){
if ([[port mediaType] isEqual:AVMediaTypeVideo] ){
videoConnection = connection;
break;
}
}
if (videoConnection) { break; }
}
//code to abort if not return 'soon'
...
[self.imageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error){
//use image here
}];
iPhone5を使用している場合、captureStillImageAsynchronouslyFromConnectionが完了しません
私はテストしました:
このコードは、更新された iPhone 4s と iPod (iPod touch (第 4 世代)) の両方で動作するため、OS 6 ではありません。
captureSession が実行中です
videoConnection は nil ではありません
imageOutput は nil ではありません
また:
プレビューをサブビューとして配置する必要があるため、UIImagePickerController ではなくこのメソッドを使用しています。
キャプチャ セッションでstopRunningを呼び出すと、iPhone 5 でも数秒かかります。