Estoy tratando de usar el nuevo AVFoundation framework
para tomar fotos con el iPhone.iPhone SDK 4 AVFoundation - Cómo utilizar captureStillImageAsynchronouslyFromConnection correctamente?
Con un botón presione este se llama methos. Puedo escuchar el sonido del obturador pero no puedo ver la salida del registro. Si llamo a este método varias veces, la vista previa de la cámara se congelará.
¿Hay algún tutorial sobre cómo usar captureStillImageAsynchronouslyFromConnection
?
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:
[[self stillImageOutput].connections objectAtIndex:0]
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer,
NSError *error) {
NSLog(@"inside");
}];
- (void)initCapture { AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] error:nil]; AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init]; captureOutput.alwaysDiscardsLateVideoFrames = YES; dispatch_queue_t queue; queue = dispatch_queue_create("cameraQueue", NULL); [captureOutput setSampleBufferDelegate:self queue:queue]; dispatch_release(queue); NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]; NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key]; [captureOutput setVideoSettings:videoSettings]; self.captureSession = [[AVCaptureSession alloc] init]; self.captureSession.sessionPreset = AVCaptureSessionPresetLow; [self.captureSession addInput:captureInput]; [self.captureSession addOutput:captureOutput]; self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession: self.captureSession]; [self.prevLayer setOrientation:AVCaptureVideoOrientationLandscapeLeft]; self.prevLayer.frame = CGRectMake(0.0, 0.0, 480.0, 320.0); self.prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; [self.view.layer addSublayer: self.prevLayer]; // Setup the default file outputs AVCaptureStillImageOutput *_stillImageOutput = [[[AVCaptureStillImageOutput alloc] init] autorelease]; NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil]; [_stillImageOutput setOutputSettings:outputSettings]; [outputSettings release]; [self setStillImageOutput:_stillImageOutput]; if ([self.captureSession canAddOutput:stillImageOutput]) { [self.captureSession addOutput:stillImageOutput]; } [self.captureSession commitConfiguration]; [self.captureSession startRunning]; }
No sé si esto fue cierto en 2010, pero a finales de 2011, he estado utilizando fácilmente 'captureStillImageAsynchronouslyFromConnection' en el al mismo tiempo que recibe una transmisión de video usando el delegado de AVCaptureVideoDataOutput, 'captureOutput' y mientras usa una previewLayer. Obtengo una imagen de 5 megapíxeles de stillImage, una 852x640 para la alimentación de video y la previewLayer. – mahboudz
El comentario anterior se basó en un iPhone4. En un iPhone 4s, obtengo un 8 megapíxeles todavía, mientras obtengo 852x640 para el video feed y previewLayer. – mahboudz
¿Cuál es la diferencia entre initWithSession y layerWithSession? Los documentos no discuten cuándo usar uno frente al otro. http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVCaptureVideoPreviewLayer_Class/Reference/Reference.html – knite