![](/img/trans.png)
[英]How to stream and convert live video into mp-4. How to use FFMPEG?
[英]How to use AVCaptureSession to stream live preview video, then take a photo, then return to streaming
我有一个应用程序,在拍摄静态照片之前创建自己的实时预览。 应用程序需要对图像数据运行一些处理,因此无法依赖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; object =; userInfo = {AVCaptureSessionErrorKey =“Error Domain = AVFoundationErrorDomain Code = -11800 \\”操作无法完成。 (AVFoundationErrorDomain错误-11800。)\\“UserInfo = 0x19d810 {}”;
XCode中的文档表面上提供了有关错误编号(-11800)的更多信息,“AVErrorUnknown - 错误原因未知。”;
以前我也尝试过调用stopRunning和startRunning,但是在观看WWDC Session 409之后不再这样做了,不鼓励这样做。 当我停止并开始时,我得到一个不同的错误消息-11819,它对应于“AVErrorMediaServicesWereReset - 操作无法完成,因为媒体服务变得不可用。”,这比简单的“未知”要好得多,但不一定更有帮助。
它成功添加了AVCaptureStillImageOutput(即,不发出日志消息)。
我正在测试iPhone 3g(w / 4.1)和iPhone 4。
这个调用发生在主线程中,这也是我原来的AVCaptureSession设置发生的地方。
如何避免错误? 如何切换到更高的分辨率拍摄照片?
谢谢!
由于您正在处理来自AVCaptureSession的视频数据,我假设您在调用sessionSetupForPhoto之前已将AVCaptureVideoDataOutput连接到它。
如果是这样,你能详细说明你在captureOutput中做了什么:didOutputSampleBuffer : ? 无法看到更多内容,我猜测删除旧输出并随后设置照片质量预设可能存在问题。
此外,删除输出时用作迭代器的输出变量隐藏静止图像输出 。 不是问题,但它使代码更难阅读。
无需切换会话。 只需在初始化时将AVCaptureStillImageOutput
添加到会话中,并在要捕获图像时调用以下内容并相应地使用CMSampleBufferRef
:
captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.