使用AVFoundation从video中捕获图片

我正试图从iPad上的video中捕捉图片。 我以苹果的AVCam例子为出发点。

我能够看到我的应用程序中的video,并从中拍照。 我的问题是,结果图像的像素大小是错误的。 我想要一个全屏图片(1024×768),但我得到一个较小的(1024×720)。

这些是我的实例variables:

@property (retain) AVCaptureStillImageOutput *stillImageOutput; @property (retain) AVCaptureVideoPreviewLayer *previewLayer; @property (retain) AVCaptureSession *captureSession; @property (retain) AVCaptureConnection *captureConnection; @property (retain) UIImage *stillImage; 

这里的代码拍照:

 - (void)takePicture { AVCaptureConnection *videoConnection = nil; for (AVCaptureConnection *connection in [[self stillImageOutput] connections]) { for (AVCaptureInputPort *port in [connection inputPorts]) { if ([[port mediaType] isEqual:AVMediaTypeVideo]) { videoConnection = connection; break; } } if (videoConnection) { break; } } NSLog(@"about to request a capture from: %@", [self stillImageOutput]); [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) { CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL); if (exifAttachments) { NSLog(@"attachements: %@", exifAttachments); } else { NSLog(@"no attachments"); } NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; UIImage *image = [[UIImage alloc] initWithData:imageData]; [self setStillImage:image]; [image release]; [[NSNotificationCenter defaultCenter] postNotificationName:kImageCapturedSuccessfully object:nil]; }]; } 

我想调整最终的图片,但这个解决scheme会降低图像的质量。 我也意识到, CFDictionaryRef exifAttachments字典包含一个值PixelYDimension = 720; 但我似乎无法find与之交互的方式。

任何帮助将非常感激。 先谢谢你,祝你有个美好的一天,

亚历克斯。

编辑:我想指出,当我说“从video拍摄照片”我的意思是video从iPad的相机现场直播, 它不是一个录音。

我find了解决我的问题。 在这种情况下,有人会在未来寻找这种情况。

要使用AVFoundation与相机交互,我们需要启动一个AVCaptureSessionvariables。 这样做之后,我们可以修改sessionPreset来指示输出的质量等级或比特率。 有一组不同的常量 。 为了拍摄1024×768图片,我使用了AVCaptureSessionPresetPhoto