簡體   English   中英

AVAssetExportSession exportAsynchronouslyWithCompletionHandle:導出音頻錯誤

[英]AVAssetExportSession exportAsynchronouslyWithCompletionHandle : export audio error

我正在使用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);
            }
        }
    }];
}

會話的錯誤:錯誤域= AVFoundationErrorDomain代碼= -11800“該操作無法完成” UserInfo = {NSLocalizedFailureReason =發生未知錯誤(-12769),NSLocalizedDescription =此操作無法完成,NSUnderlyingError = 0x283a97630 {Error Domain = NSOSStatusErrorDomain Code =- 12769“(null)”}}(此操作無法完成意味着無法完成)

為了解決此問題,我將AVAssetExportSession替換為AVAssetReader和AVAssertWriter進行導出。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM