这个问题一直让我发疯。我正在尝试使用AVAsset在我的Cocoa应用程序中标记一些歌曲,我将标签信息添加到它并使用AVAssetExportSession导出它。但是,无论我做什么,导出都会失败并显示错误(OSStatus error -620.)" (notEnoughMemoryErr: insufficient physical memory)
。在我的MacBook上,当我这样做时,我总是有3-4个或更多的空闲RAM,所以这是不对的。我尝试删除所有标记信息,以防在某处导致错误,但这没有帮助。
以下是代码:
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:[tempSongPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] options:nil];
AVAssetExportSession *session;
session = [AVAssetExportSession exportSessionWithAsset:asset presetName:AVAssetExportPresetAppleM4A];
session.outputFileType = AVFileTypeAppleM4A;
NSURL *outputURL = [NSURL URLWithString:[[NSString stringWithFormat:@"%@Path/%@", NSTemporaryDirectory(), @"output.m4a"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
session.outputURL = outputURL;
NSLog(@"Asset: %@", asset);
NSLog(@"Session %@", session);
[session exportAsynchronouslyWithCompletionHandler:^{
if (AVAssetExportSessionStatusCompleted == session.status) {
NSLog(@"Completed");
}
NSString *cause;
NSString *stringError;
if (session.error)
{
NSLog(@"%@", session.error);
stringError = [session.error localizedDescription];
cause = session.error.localizedFailureReason;
}
else
stringError = @"Unknown error";
NSLog(@"Error: %@ because %@", stringError, cause);
for (NSString *key in session.error.userInfo.allKeys)
{
NSLog(@"%@: %@", key, [session.error.userInfo objectForKey:key]);
}
}];
有任何帮助吗?我已经坚持这个问题了整整两天。
答案 0 :(得分:4)
内存不足错误是一个红色的鲱鱼。问题是这一行:
NSURL *outputURL = [NSURL URLWithString:[[NSString stringWithFormat:@"%@Path/%@", NSTemporaryDirectory(), @"output.m4a"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
尝试将其替换为:
NSURL *outputURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", NSTemporaryDirectory(), @"output.m4a"] isDirectory:NO];
我刚用上面的测试,它现在工作正常。