我正在寫一個應用程序,使用AVFoundation與視頻一起使用。AVAssetExportSession錯誤-11820
我的應用程序的行爲很簡單:我從相機膠捲拍攝視頻,然後用一些音軌創建AVMutableComposition。使用混合組合我初始化一個AVAssetExportSession,它將視頻文件存儲在我的應用程序的文檔目錄中。
直到這一點沒關係:我的視頻被存儲,我可以在另一個控制器中播放它。如果我將剛剛存儲在我的文檔文件夾中的視頻進行一些編輯(以與第一次AVmutableComposition,AVAssetExportSession相同的方式),則再次正常。
但我第三次做這個過程中編輯視頻的AVAssetExportSession狀態變爲「失敗」和與此錯誤:
"Domain=AVFoundationErrorDomain Code=-11820 "Cannot Complete Export" UserInfo=0x1a9260 {NSLocalizedRecoverySuggestion=Try exporting again., NSLocalizedDescription=Cannot Complete Export}"
我已閱讀,是一個普遍的錯誤的會話不能出口。這是什麼意思?爲什麼只有我第三次編輯過程?這可能是內存管理錯誤嗎?一個錯誤?這是我AVAssetExportSession的代碼:
_assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];
_assetExport.shouldOptimizeForNetworkUse = YES;
///data odierna
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"ddMMyyyyHHmmss"];
NSDate *now = [[NSDate alloc] init];
NSString *dateString = [format stringFromDate:now];
[now release];
[format release];
NSString* ext = @".MOV";
NSString* videoName=[NSString stringWithFormat:@"%@%@", dateString, ext];
///data odierna
NSString *exportPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:videoName];
if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath])
{
[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
}
_assetExport.outputFileType = AVFileTypeQuickTimeMovie;
[_assetExport setTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)];
NSURL *exportUrl = [NSURL fileURLWithPath:exportPath] ;
_assetExport.outputURL = exportUrl ;
[_assetExport exportAsynchronouslyWithCompletionHandler:^
{
switch (_assetExport.status)
{
case AVAssetExportSessionStatusFailed:
{
NSLog (@"FAIL %@",_assetExport.error);
if ([[NSFileManager defaultManager] fileExistsAtPath:[_assetExport.outputURL path]])
{
[[NSFileManager defaultManager] removeItemAtPath:[_assetExport.outputURL path] error:nil];
}
[self performSelectorOnMainThread:@selector (ritenta)
withObject:nil
waitUntilDone:NO];
break;
}
case AVAssetExportSessionStatusCompleted:
{
NSLog (@"SUCCESS");
[self performSelectorOnMainThread:@selector (saveVideoToAlbum:)
withObject:exportPath
waitUntilDone:NO];
break;
}
case AVAssetExportSessionStatusCancelled:
{
NSLog (@"CANCELED");
break;
}
};
}];
我也做了網絡上衆多的搜索,有些人曾在會議的outputURL一個問題,但我已經嘗試過,似乎都可以在我的代碼。爲文件分配一個唯一的名字我使用NSDate。出於調試的目的,我試圖恢復一個標準的字符串名稱,但問題依然存在。有任何想法嗎?有人可以向我建議一種替代方法,用AssetWriter將AVassetExportSession插入資產文件夾中的資產嗎?
當你不提供正確的AVMutableComposition時,導出器經常失敗,所以第三次調試你的AVMutableComposition對象。 – BhushanVU 2013-03-05 09:52:21