gpt4 book ai didi

iphone - AVAssetExportSession 错误 -11820

转载 作者:技术小花猫 更新时间:2023-10-29 11:09:02 26 4
gpt4 key购买 nike

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

我的应用程序的行为很简单:我从相机胶卷中拍摄视频,然后创建一个带有一些音轨的 AVMutableComposition。通过混合合成,我初始化了一个 AVAssetExportSession,它将视频文件存储在我的应用程序的文档目录中。

到此为止一切正常:我的视频已存储,我可以在另一个 Controller 中播放它。如果我将刚刚存储在我的文档文件夹中的视频进行一些编辑(以与第一次 AVmutableComposition,AVAssetExportSession 相同的方式),它又可以了。

但是我第三次执行此过程来编辑视频时,AVAssetExportSession 状态变为“失败”并出现此错误:

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

我读到这是无法导出 session 的一般错误。这是什么意思?为什么我只进行了第三次编辑过程?可能是内存管理错误?一个错误?这是我的 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;
}
};
}];

我在网上做了很多搜索,有些人在 session 的 outputURL 中遇到了问题,但我已经尝试过并且在我的代码中似乎一切正常。我使用 NSDate 为文件分配一个唯一的名称。出于调试目的,我尝试恢复标准字符串名称,但问题仍然存在。有任何想法吗?有人可以向我建议一种替代方法,以使用 AssetWriter insted AVassetExportSession 将 Assets 导出到文档文件夹吗?

最佳答案

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

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

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

或者
只需更改

_assetExport.outputFileType = AVFileTypeQuickTimeMovie;

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

也不要忘记更改扩展名

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

这应该有效。它对我有用。

关于iphone - AVAssetExportSession 错误 -11820,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5624150/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com