【问题标题】:AVAssetExportSession fails on IOS 13, muxing together audio and videoAVAssetExportSession 在 IOS 13 上失败,将音频和视频混合在一起
【发布时间】:2020-02-05 02:17:25
【问题描述】:

此代码在所有 IOS 13 之前的设备上都有效(并且仍然有效)。目前,在 exportAsynchronously 调用运行后出现此错误:

Error Domain=AVFoundationErrorDomain Code=-11800 "该操作可能 未完成” UserInfo={NSLocalizedFailureReason=未知错误 发生 (-12735), NSLocalizedDescription=操作不能 完成,NSUnderlyingError=0x282e194a0 {错误 Domain=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");   
        }   
    }   

【问题讨论】:

  • stackoverflow.com/questions/58136254/… 可能与 AVURLAsset 初始化有关,您可以尝试使用 AVURLAsset(url: videoInputURL, options: nil)
  • @EDUsta hm,听起来非常好,谢谢,但我刚刚在初始化 AVURLAsset 对象时将options: nil 添加到上面的代码中,正如答案所暗示的那样,但不幸的是结果相同
  • 这个错误有什么进展吗?
  • @KeremKusmezer 我在下面的回复/回答是解决这个问题的方法

标签: swift avfoundation avassetexportsession


【解决方案1】:

问题似乎与 AVAssetExportPresetPassthrough 相关(可能是与 AAC 打交道的组合)

更改为 AVAssetExportPresetLowQuality 或 AVAssetExportPresetHighestQuality 并且视频/音频被正确地混合为一个。同样,这只是一个 IOS 13 问题,很可能是一个错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多