AVMutableComposition偶尔会静音。
创始人
2024-11-13 02:00:39
0

如果您使用AVMutableComposition创建视频并遇到间歇性静音问题,则很可能是由于您的AVAssetTrack中的音频配置不正确而引起的。

以下是一个可能的解决方案,可以检查您的音频配置是否正确:

let composition = AVMutableComposition()
let videoTrack = composition.addMutableTrack(withMediaType: .video, preferredTrackID: kCMPersistentTrackID_Invalid)
let audioTrack = composition.addMutableTrack(withMediaType: .audio, preferredTrackID: kCMPersistentTrackID_Invalid)

// Add your video and audio assets to each track

if let audioAssetTrack = audioAsset.tracks(withMediaType: .audio).first {
    do {
        let audioInputParams = AVMutableAudioMixInputParameters(track: audioTrack)
        let audioTimeRange = CMTimeRangeMake(start: .zero, duration: audioAssetTrack.timeRange.duration)
        try audioInputParams.setVolume(1.0, at: .zero)
        try audioInputParams.setAudioTimePitchAlgorithm(AVAudioTimePitchAlgorithm.timeDomain)
        audioInputParams.audioTimePitchAlgorithm = .varispeed
        try audioInputParams.setAudioMix(myAudioMixes, at: .zero)
        audioInputParams.trackID = audioTrack.trackID
        if let audioMix = AVMutableAudioMix() {
            audioMix.inputParameters = [audioInputParams]
            let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetHighestQuality)
            exportSession?.audioMix = audioMix
            exportSession?.timeRange = videoTrack.timeRange
            exportSession?.outputFileType = .mov
            ...
        }
    } catch {
        print("Error setting up audio input params: \(error)")
    }
}

这里我们使用AVMutableAudioMixInputParameters配置音频轨道,设置音量、时间和音高算法,并将其应用于AVMutableComposition。请注意,您需要确保设置的音频参数与您的音频资源匹配,以避免静音问题。

相关内容

热门资讯

重大通报“禅游辅助器”原本有开... 重大通报“禅游辅助器”原本有开挂辅助插件(今日头条);重大通报“禅游辅助器”原本有开挂辅助插件(今日...
透视游戏!wepoker好友房... 透视游戏!wepoker好友房开挂-分享开挂透视辅助软件(有挂总结)1、下载好wepoker好友房开...
专业讨论“wepoker国外版... 专业讨论“wepoker国外版透视”总是有开挂辅助器(有挂实锤);大家肯定在之前wepoker国外版...
透视肯定!hhpoker可以控... 透视肯定!hhpoker可以控制牌-详情开挂透视辅助工具(有挂教学)1、点击下载安装,hhpoker...
分享一款“战神辅助器下载”素来... 分享一款“战神辅助器下载”素来有开挂辅助安装(有挂秘籍);是一款可以让一直输的玩家,快速成为一个“必...
透视ai代打!wepoker挂... 透视ai代打!wepoker挂-总结开挂透视辅助app(有挂秘笈)1、下载好wepoker挂辅助软件...
查到实测“wepoker免费脚... 查到实测“wepoker免费脚本”真是有开挂辅助助手(有挂助手);AI辅助机器人普及解说快速成为一个...
透视计算!wepoker代打辅... 透视计算!wepoker代打辅助机器人-揭幕开挂透视辅助app(真是有挂)wepoker代打辅助机器...
新手必备“hhpoker有后台... 新手必备“hhpoker有后台操作”都是有开挂辅助工具(有挂详情);hhpoker有后台操作中的10...
透视模拟器!哈糖大菠萝可以开挂... 透视模拟器!哈糖大菠萝可以开挂-揭露开挂透视辅助技巧(有挂讲解)1、超多福利:超高返利,海量正版游戏...