AVFoundation视频捕获将无法保存

时间:2012-06-28 18:16:35

标签: objective-c ios avfoundation

我正在使用AVFoundation来捕捉视频。在我到达这里之前,我的应用程序似乎都很好:

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
  fromConnections:(NSArray *)connections
            error:(NSError *)error
{

NSLog(@"didFinishRecordingToOutputFileAtURL - enter");

BOOL RecordedSuccessfully = YES;
if ([error code] != noErr)
{
    // A problem occurred: Find out if the recording was successful.
    id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey];
    if (value)
    {
        RecordedSuccessfully = [value boolValue];
    }
}
if (RecordedSuccessfully)
{
    //----- RECORDED SUCESSFULLY -----
    NSLog(@"didFinishRecordingToOutputFileAtURL - success");
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputFileURL])
    {
        [library writeVideoAtPathToSavedPhotosAlbum:outputFileURL
                                    completionBlock:^(NSURL *assetURL, NSError *error)
         {
             if (error)
             {

             }
         }];
    }

    [library release];      

}

}

在设备上运行时,我收到“didFinishRecordingToOutputFileAtURL - success”消息,然后崩溃,我收到此错误:

视频/private/var/mobile/Applications/EDC62CED-3710-45B2-A658-A2FE9238F517/tmp/output.mov无法保存到已保存的相册:错误域名= NSOSStatusErrorDomain代码= -12950“电影无法保存播放。” UserInfo = 0xe6749b0 {NSLocalizedDescription =无法播放电影。}

我无法在任何地方找到关于此的大量信息,我不确定发生了什么。

以下是包含临时输出网址的代码:

NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"];
NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:outputPath])
{
    NSError *error;
    if ([fileManager removeItemAtPath:outputPath error:&error] == NO)
    {
        //Error - handle if requried
    }
}
[outputPath release];
//Start recording
[movieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];

[outputURL release];

我已经尝试在保存之后在其他地方释放outputURL,这没有帮助,所以我不认为就是这样。

1 个答案:

答案 0 :(得分:0)

我想出来了。我是一个白痴,并一直忽略了我实际上没有将视频输入连接到捕获会话的事实。糟糕。