【问题标题】:AVAssetExportSession Error -11820AVAssetExportSession 错误 -11820
【发布时间】:2011-08-03 04:59:33
【问题描述】:

我正在编写一个使用 AVFoundation 处理视频的应用程序。

我的应用程序的行为很简单:我从相机胶卷中获取视频,然后创建一个带有一些音轨的 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 时,Exporter 经常会失败,所以第三次调试你的 AVMutableComposition 对象。
  • 你在模拟器上吗?我在模拟器上遇到错误,但在真实设备上它成功了

标签: iphone ios avfoundation


【解决方案1】:

问题是_assetExport.outputFileType你设置了AVFileTypeQuickTimeMovie的类型。不太可能支持的类型。

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

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


只需更改

_assetExport.outputFileType = AVFileTypeQuickTimeMovie;

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

别忘了更改扩展名

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

这应该可行。它对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 2016-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多