2011-04-11 57 views
10

我正在写一个应用程序,使用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插入资产文件夹中的资产吗?

+0

当你不提供正确的AVMutableComposition时,导出器经常失败,所以第三次调试你的AVMutableComposition对象。 – BhushanVU 2013-03-05 09:52:21

回答

-1

问题是_assetExport.outputFileType您已设置类型AVFileTypeQuickTimeMovie。哪种支持类型不太可能。

尝试使用以下代码找出_assetExport支持哪些输出文件类型并使用合适的输出文件类型。

NSLog (@"created exporter. supportedFileTypes: %@", exporter.supportedFileTypes); 

OR
只是改变

_assetExport.outputFileType = AVFileTypeQuickTimeMovie; 

TO

exporter.outputFileType = @"com.apple.m4a-audio"; 

而且不要忘记扩展从

NSString* ext = @".MOV"; to @".m4a" 

钍改变应该工作。它为我工作。

相关问题