AVAssetExportSession正在导出带有错误时间范围的音频
创始人
2024-11-12 20:00:40
0

通常这个错误是由于导出的音频文件与原始音频文件有时间范围的重叠或不连续所造成的。要解决这个问题,需要在导出音频之前对原始音频进行修正或合并。以下是一个示例代码,演示如何使用AVMutableComposition和AVAssetExportSession合并两个音频文件:

let composition = AVMutableComposition()
let compositionTrack = composition.addMutableTrack(withMediaType: .audio, preferredTrackID: kCMPersistentTrackID_Invalid)

let asset1 = AVURLAsset(url: URL(string: "path/to/first/audio/file")!)
let track1 = asset1.tracks(withMediaType: .audio)[0]
let timeRange1 = CMTimeRangeMake(start: CMTime.zero, duration: asset1.duration)

let asset2 = AVURLAsset(url: URL(string: "path/to/second/audio/file")!)
let track2 = asset2.tracks(withMediaType: .audio)[0]
let timeRange2 = CMTimeRangeMake(start: CMTime.zero, duration: asset2.duration)

do {
    try compositionTrack?.insertTimeRange(timeRange1, of: track1, at: CMTime.zero)
    try compositionTrack?.insertTimeRange(timeRange2, of: track2, at: asset1.duration)
} catch {
    print("Failed to insert audio tracks into composition")
}

let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetAppleM4A)
exportSession?.outputFileType = .m4a
exportSession?.outputURL = URL(string: "path/to/output/file")!

exportSession?.exportAsynchronously {
    if exportSession?.status == .completed {
        print("Audio export successful!")
    } else {
        print("Audio export failed: \(exportSession?.error?.localizedDescription ?? "")")
    }
}

在这个示例中,我们创建了一个AVMutableComposition,并将两个音频文件的音轨插入到组合中。第一个音频文件从0秒开始播放,第二个音频文件从第一个音频文件

相关内容

热门资讯

科技介绍!wepoker有没有... 科技介绍!wepoker有没有插件(辅助挂)确实真的是有挂(有挂总结)1、进入到wepoker有没有...
一起来讨论!哈糖大菠萝有没有挂... 一起来讨论!哈糖大菠萝有没有挂(辅助挂)切实存在有挂(揭秘有挂)1、超多福利:超高返利,海量正版游戏...
最新通报!德普之星透视辅助软件... 最新通报!德普之星透视辅助软件(辅助挂)确实真的有挂(真的有挂)1、任何德普之星透视辅助软件透视是真...
终于知道!epoker免费透视... 终于知道!epoker免费透视脚本(辅助挂)都是有挂(确实有挂)所有人都在同一条线上,像星星一样排成...
盘点一款!wepoker底牌透... 盘点一款!wepoker底牌透视(辅助挂)确实存在有挂(有挂教程)1、wepoker底牌透视免费辅助...
交流学习经验!steampok... 交流学习经验!steampokermaster辅助(辅助挂)原来有挂(有挂详细)一、steampok...
解密关于!wepoker破解游... 解密关于!wepoker破解游戏盒子(辅助挂)竟然真的是有挂(有挂详情)1、进入游戏-大厅左侧-新手...
记者揭秘!aapoker怎么提... 记者揭秘!aapoker怎么提高中牌率(辅助挂)确实真的有挂(讲解有挂)1、每一步都需要思考,不同水...
分享实测!wepoker辅助插... 分享实测!wepoker辅助插件功能(辅助挂)真是有挂(有挂方针)亲,关键说明,wepoker辅助插...
总算了解!聚星ai辅助工具收费... 总算了解!聚星ai辅助工具收费多少(辅助挂)一贯存在有挂(讲解有挂)总算了解!聚星ai辅助工具收费多...