`AVMutableCompositionTrack.insertTimeRange` 失败并出现错误 -11800

`AVMutableCompositionTrack.insertTimeRange` fails with error -11800

我正在从视频和音频轨道创建 AVMutableComposition

func makeComposition(videoTrack: AVAssetTrack, audioTrack: AVAssetTrack) -> AVComposition {
    let composition = AVMutableComposition()
    /* ... */
    let compositionAudioTrack = composition.addMutableTrack(withMediaType: .audio)!
    try compositionAudioTrack.insertTimeRange(someRange, of: audioTrack, at: .zero) // Error!
    /* ... */
    return composition
}

insertTimeRange(_:of:at:) 失败,出现 AVFoundationError -11800 AVError.code.unknown 和未记录的基础 NSOSStatusError -12780。可能是什么情况?

事实证明,在我调用 insertTimeRange 时,audioTrack 的源 AVAsset 已发布。 AVAssetTrack 保留 weak 对来源 AVAsset 的引用,因此您必须保留 AVAsset 才能使用 AVAssetTrack.