gpt4 book ai didi

ios - AVAssetExportSession 导出AsynchronouslyWithCompletionHandle : export audio error

转载 作者:行者123 更新时间:2023-11-29 05:33:17 27 4
gpt4 key购买 nike

我正在使用 AVAssetExportSession exportAsynchronouslyWithCompletionHandler 导出音频,但出现错误。

(在很多音频中,只有一个音频会出现这个问题。)

+ (void)exportAudioWithAsset:(AVAsset *)asset exportPath:(nonnull NSString *)exportPath completion:(nonnull void (^)(BOOL, NSError * _Nullable, NSURL * _Nullable))completion {
if (!asset || !exportPath) {
if (completion) {
completion(NO, nil, nil);
}
return;
}
AVAssetExportSession *session = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetAppleM4A];
session.outputURL = [NSURL fileURLWithPath:exportPath];
session.outputFileType = AVFileTypeAppleM4A;
session.shouldOptimizeForNetworkUse = YES;
[session exportAsynchronouslyWithCompletionHandler:^{
if (session.status == AVAssetExportSessionStatusCompleted) {
NSData *data = [NSData dataWithContentsOfFile:exportPath];
if ([data length] > 0) {
if (completion) {
completion(YES, nil, [NSURL fileURLWithPath:exportPath]);
}
} else {
if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) {
[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
}
if (completion) {
completion(NO, session.error, nil);
}
}
} else {
if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) {
[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
}
if (completion) {
completion(NO, session.error, nil);
}
}
}];
}

session 错误:Error Domain=AVFoundationErrorDomain Code=-11800 "这项操作无法完成"UserInfo={NSLocalizedFailureReason=发生未知错误(-12769), NSLocalizedDescription=这项操作无法完成完成,NSUnderlyingError=0x283a97630 {错误域=NSOSStatusErrorDomain代码=-12769“(空)”}}(此操作无法完成表示无法完成)

最佳答案

为了解决这个问题,我用 AVAssetReader 和 AVAssertWriter 替换 AVAssetExportSession 来导出。

关于ios - AVAssetExportSession 导出AsynchronouslyWithCompletionHandle : export audio error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57324395/

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