【问题标题】:error when capturing camera and audio input捕获相机和音频输入时出错
【发布时间】:2010-08-16 17:58:21
【问题描述】:

使用 iOS4 中的一些漂亮的新 API,我试图从 iPhone 的摄像头和麦克风捕获输入并将其保存到文件中。下面是我正在使用的代码。

AVCaptureSession* captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&error];
AVCaptureDeviceInput* videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:captDevice error:&error];
AVCaptureMovieFileOutput * videoOutput = [[AVCaptureMovieFileOutput alloc] init];

if (videoInput && videoOutput && audioInput) 
{
    [captureSession addInput:audioInput];
    [captureSession addInput:videoInput];
    [captureSession addOutput:videoOutput];
    if([captDevice lockForConfiguration:&error])
    {
        if ([captDevice hasTorch]) 
            captDevice.torchMode = AVCaptureTorchModeOn;

        [captDevice unlockForConfiguration];
    }
    else 
    {
        NSLog(@"Could not lock device for config error: %@", error);
    }

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSURL* saveLocationURL = [[NSURL alloc] initFileURLWithPath:[NSString stringWithFormat:@"%@/movie.mov", documentsDirectory]];

    [videoOutput startRecordingToOutputFileURL:saveLocationURL recordingDelegate:self];
    [captureSession startRunning];

    [saveLocationURL release];
}
else 
{
    NSLog(@"Video Error: %@", error);
}   

当 didFinishRecordingToOutputFileAtURL 返回时,我得到一个神秘的错误响应。

Error Domain=AVFoundationErrorDomain Code=-11803 "Cannot Record" UserInfo=0x152f70 {NSLocalizedRecoverySuggestion=Try recording again., AVErrorRecordingSuccessfullyFinishedKey=false, NSLocalizedDescription=Cannot Record}

错误代码 -11803 表示“AVErrorSessionNotRunning”。我能说的就是告诉我一些我不知道的事情。有人知道为什么会话没有运行吗?

【问题讨论】:

    标签: iphone video ios4 video-streaming video-capture


    【解决方案1】:

    [videoOutput startRecordingToOutputFileURL:saveLocationURL recordingDelegate:self];之前调用[captureSession startRunning];

    【讨论】:

    • 修复了报告的问题,但现在我收到了一个新错误。错误域=NSOSStatusErrorDomain 代码=-12673“操作无法完成。(OSStatus 错误-12673。)”UserInfo=0x154190 {AVErrorRecordingSuccessfullyFinishedKey=false}
    • movie.mov 是否已经存在?另见“stringByAppendingPathComponent:”。
    • 我只是想也许它会拒绝覆盖现有文件。 captDevice 初始化在哪里?
    • 你有没有发现这个“OSStatus error -12673”的含义。问题?我遇到了同样的错误。
    • @Meekohi:我也遇到了 -12673 错误,这是由于尝试将文件写入不可写的位置而引起的。一旦使用 NSTemporaryDirectory() 写入我知道是可写的目录,捕获就起作用了。我构建了类似 [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/video.mov", NSTemporaryDirectory()]] 的文件 URL。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-02
    • 1970-01-01
    • 1970-01-01
    • 2015-04-18
    • 1970-01-01
    相关资源
    最近更新 更多