7

我有一个应用程序可以在拍摄静态照片之前创建自己的实时预览。该应用程序需要对图像数据进行一些处理,因此无法依赖 AVCaptureVideoPreviewLayer。使用 Apple 的示例代码让初始流工作进展顺利。当我尝试切换到更高质量的图像来拍摄快照时,问题就来了。为了响应按钮按下,我尝试重新配置会话以拍摄全分辨率照片。我尝试了很多变体,但这是我最新的示例(仍然不起作用):

- (void)sessionSetupForPhoto
{
 [session beginConfiguration];
 session.sessionPreset = AVCaptureSessionPresetPhoto;
 AVCaptureStillImageOutput *output = [[[AVCaptureStillImageOutput alloc] init] autorelease];
 for (AVCaptureOutput *output in [session outputs]) {
  [session removeOutput:output];
 }
 if ([session canAddOutput:output]){
  [session addOutput:output];
 } else {
  NSLog(@"Not able to add an AVCaptureStillImageOutput");
 }
 [session commitConfiguration];
}

在 commitConfiguration 行之后,我一直收到一条错误消息,如下所示:(也就是说,我收到一个 AVCaptureSessionRuntimeErrorNotification 发送给我的注册观察者)

收到错误:NSConcreteNotification 0x19d870 {name = AVCaptureSessionRuntimeErrorNotification; 对象 = ; userInfo = { AVCaptureSessionErrorKey = "Error Domain=AVFoundationErrorDomain Code=-11800 \"操作无法\U2019完成。(AVFoundationErrorDomain 错误 -11800。)\" UserInfo=0x19d810 {}";

XCode 中的文档表面上提供了有关错误号 (-11800) 的更多信息,“AVErrorUnknown - 错误原因未知。”;

以前我也尝试过调用 stopRunning 和 startRunning,但在观看 WWDC Session 409 后不再这样做,不鼓励这样做。当我停止和启动时,我收到一条不同的错误消息 -11819,它对应于“AVErrorMediaServicesWereReset - 由于媒体服务变得不可用,因此无法完成操作。”,这比简单的“未知”要好得多,但不一定更有帮助。

它成功添加了 AVCaptureStillImageOutput(即,不发出日志消息)。

我正在 iPhone 3g (w/4.1) 和 iPhone 4 上进行测试。

这个调用发生在主线程中,这也是我最初的 AVCaptureSession 设置发生的地方。

我怎样才能避免错误?如何切换到更高分辨率拍摄照片?

谢谢!

4

2 回答 2

2

由于您正在处理来自 AVCaptureSession 的视频数据,因此我假设您在调用sessionSetupForPhoto 之前连接了一个 AVCaptureVideoDataOutput。

如果是这样,您能否详细说明您在captureOutput:didOutputSampleBuffer:中所做的事情?由于无法查看更多内容,我猜测删除旧输出并随后设置照片质量预设可能存在问题。

此外,您在删除输出时用作迭代器的输出变量隐藏了静止图像输出。不是问题,但它使代码更难阅读。

于 2011-04-08T03:39:07.577 回答
1

无需切换会话。只需AVCaptureStillImageOutput在初始化时添加到您的会话中,并在您即将捕获图像并CMSampleBufferRef相应地使用时调用以下命令:

captureStillImageAsynchronouslyFromConnection:videoConnection
   completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) 
{
}
于 2012-04-30T13:02:44.497 回答