AVAssetExportSession错误-11820无法完成导出

时间:2012-05-23 22:30:32

标签: ios avassetexportsession

我正在使用AVComposition将两个.m4a音频文件合并在一起。必须在特定时间插入另一个。然后我使用AVAssetExportSession来保存合并音频。

我在导出会话完成处理程序中遇到此错误:

Error Domain=AVFoundationErrorDomain Code=-11820 "Cannot Complete Export" UserInfo=0x1c3760 {NSLocalizedRecoverySuggestion=Try exporting again., NSLocalizedDescription=Cannot Complete Export}

代码 - 合并两个资产:

  AVAsset *originalAsset = [AVAsset assetWithURL:url];
NSURL *recordingAssetUrl = [[NSURL fileURLWithPath: NSTemporaryDirectory()] URLByAppendingPathComponent:kRecordTemp];
AVAsset *recordingAsset = [AVAsset assetWithURL:recordingAssetUrl];

AVMutableComposition *composition = [AVMutableComposition new];

AVMutableCompositionTrack *audioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio 
                                                                 preferredTrackID:kCMPersistentTrackID_Invalid];

//Add the original audio asset to the composition
AVAssetTrack *sourceAudioTrack = [[originalAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
NSError *error = nil;
CMTimeRange sourceRange = CMTimeRangeMake(CMTimeMakeWithSeconds(0, 1), originalAsset.duration);
[audioTrack insertTimeRange:sourceRange ofTrack:sourceAudioTrack atTime:CMTimeMakeWithSeconds(0, 1) error:&error];
if (error) [self showError:error];

//Remove the portion of the original audio asset that will be replaced by the recording
CMTimeRange overwrittenRange = CMTimeRangeMake(self.currentTime, recordingAsset.duration);
[audioTrack removeTimeRange:overwrittenRange];

//Add the recording asset to the composition
AVAssetTrack *recordAudioTrack = [[recordingAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
error = nil;
CMTimeRange recordRange = CMTimeRangeMake(CMTimeMakeWithSeconds(0, 1), recordingAsset.duration);
[audioTrack insertTimeRange:recordRange ofTrack:recordAudioTrack atTime:self.currentTime error:&error];
if (error) [self showError:error];

//Delete the original asset
if([[NSFileManager defaultManager] fileExistsAtPath:url.path]){
    error = nil;
    [[NSFileManager defaultManager] removeItemAtURL:url error:&error];
    if(error) [self showError:error];
}

//Write the composition
AVAssetExportSession * exportSession = [AVAssetExportSession exportSessionWithAsset:composition 
                                                                         presetName:AVAssetExportPresetAppleM4A]; 
exportSession.outputURL = url;
exportSession.outputFileType = AVFileTypeAppleM4A;

[exportSession exportAsynchronouslyWithCompletionHandler:^{
    if(exportSession.status != AVAssetExportSessionStatusCompleted){
        [self showError:exportSession.error];
    }
}];

//Delete the temporary asset
if([[NSFileManager defaultManager] fileExistsAtPath:recordingAssetUrl.path]){
    error = nil;
    [[NSFileManager defaultManager] removeItemAtURL:recordingAssetUrl error:&error];
    if(error) [self showError:error]; //BOOM it blows up here
}

我不确定我应该粘贴哪些代码,因为它是如此普遍的错误。

我正在使用AVAssetWriter编写示例缓冲区来创建从捕获会话中收到的记录资产。捕获会话成功记录并将文件保存到上面列表中使用的URL中。

0 个答案:

没有答案