Note that there are some explanatory texts on larger screens.

plurals
  1. POAVCaptureOutput captureStillImageAsynchronouslyFromConnection never completes on iPhone5
    text
    copied!<p>In my application I am displaying a <strong>AVCaptureVideoPreviewLayer</strong> and then capturing a still image when the user clicks a button using the <strong>captureStillImageAsynchronouslyFromConnection</strong> function in <strong>AVCaptureOutput</strong>. This has worked well for me up until the iPhone 5, on which it never completes. </p> <p>My setup code is:</p> <pre><code>... 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]; </code></pre> <p>My capture method is:</p> <pre><code>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 }]; </code></pre> <p>captureStillImageAsynchronouslyFromConnection never completes for me using an iPhone5 </p> <p>I have tested:</p> <ul> <li><p>It isn't OS 6 as this code works on both an iPhone 4s and an iPod (iPod touch (4th generation) that have been updated</p></li> <li><p>The captureSession is running</p></li> <li><p>videoConnection is not nil</p></li> <li><p>imageOutput is not nil</p></li> </ul> <p>Also:</p> <ul> <li><p>I'm using this method and not UIImagePickerController because I need to put the preview as a subview.</p></li> <li><p>calling <strong>stopRunning</strong> on the capture Session takes several seconds on the iPhone 5 as well</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload