AVAssetExportSession терпит неудачу на IOS 13, смешивая аудио и видео - PullRequest
3 голосов
/ 07 октября 2019

Этот код работает (и до сих пор работает) на всех устройствах до IOS 13. В настоящее время, однако, я получаю эту ошибку после выполнения exportAsynchronously вызова:

Error Domain = AVFoundationErrorDomain Code = -11800 «Операция не может быть завершена» UserInfo = {NSLocalizedFailureReason = Anпроизошла неизвестная ошибка (-12735), NSLocalizedDescription = Операция не может быть завершена, NSUnderlyingError = 0x282e194a0 {Ошибка домена = NSOSStatusErrorDomain Code = -12735 "(null)"}}

Не уверен, если IOS 13 добавляет/ изменяет некоторые требования в базовой настройке объекта AVAssetExportSession или как? Может ли быть ошибка IOS?


Вот код:

func compileAudioAndVideoToMovie(audioInputURL:URL, videoInputURL:URL) {   
        let docPath:String = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];   
        let videoOutputURL:URL = URL(fileURLWithPath: docPath).appendingPathComponent("video.mp4");   
        do   
        {   
            try FileManager.default.removeItem(at: videoOutputURL);   
        }   
        catch {}   
        let mixComposition = AVMutableComposition();   
        let videoTrack = mixComposition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: kCMPersistentTrackID_Invalid);   
        let videoInputAsset = AVURLAsset(url: videoInputURL);   
        let audioTrack = mixComposition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: kCMPersistentTrackID_Invalid);   
        let audioInputAsset = AVURLAsset(url: audioInputURL);   
        do   
        {   
            try videoTrack?.insertTimeRange(CMTimeRangeMake(start: CMTimeMake(value: 0, timescale: 1000), duration: CMTimeMake(value: 3000, timescale: 1000)), of: videoInputAsset.tracks(withMediaType: AVMediaType.video)[0], at: CMTimeMake(value: 0, timescale: 1000));// Insert an 3-second video clip into the video track   
            try audioTrack?.insertTimeRange(CMTimeRangeMake(start: CMTimeMake(value: 0, timescale: 1000), duration: CMTimeMake(value: 3000, timescale: 1000)), of: audioInputAsset.tracks(withMediaType: AVMediaType.audio)[0], at: CMTimeMake(value: 0, timescale: 1000));// Insert an 3-second audio clip into the audio track   

            let assetExporter = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetPassthrough);   
            assetExporter?.outputFileType = AVFileType.mp4;   
            assetExporter?.outputURL = videoOutputURL;   
            assetExporter?.shouldOptimizeForNetworkUse = false;   
            assetExporter?.exportAsynchronously {   
                switch (assetExporter?.status)   
                {   
                case .cancelled:   
                    print("Exporting cancelled");   
                case .completed:   
                    print("Exporting completed");   
                case .exporting:   
                    print("Exporting ...");   
                case .failed:   
                    print("Exporting failed");   
                default:   
                    print("Exporting with other result");   
                }   
                if let error = assetExporter?.error   
                {   
                    print("Error:\n\(error)");   
                }   
            }   
        }   
        catch   
        {   
            print("Exception when compiling movie");   
        }   
    }   

1 Ответ

0 голосов
/ 08 октября 2019

Проблема, по-видимому, связана с AVAssetExportPresetPassthrough (и, возможно, сочетанием работы с AAC)

Изменение на AVAssetExportPresetLowQuality или AVAssetExportPresetHighestQuality и видео / аудио должным образом объединены в единое целое. Опять же, это просто проблема IOS 13, и, вероятно, ошибка.

...