0
我正在构建一个应用程序,它结合了几个视频,将它们合并为一个视频并将自定义音频记录放入视频中。这一切都完美无瑕。现在我想淡出我的音频。另一方面,这不起作用,我不知道为什么。 这是我的代码:AVAssetExportSession,AVMutableComposition w/AudioMix淡出不起作用
let duration = composition.duration
let durationInSeconds = CMTimeGetSeconds(duration) * 10
let composition = AVMutableComposition()
let item = AVPlayerItem(asset: composition)
let params = AVMutableAudioMixInputParameters(track: composition.tracks.first! as AVAssetTrack)
let lastSecond = CMTimeRangeMake(CMTimeMakeWithSeconds(durationInSeconds-10, 10), CMTimeMakeWithSeconds(1, 1))
params.setVolumeRamp(fromStartVolume: 1, toEndVolume: 0, timeRange: lastSecond)
let mix = AVMutableAudioMix()
mix.inputParameters = [params]
item.audioMix = mix
// Put the track under the video
do {
try audioTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, current), of: backgroundAudio.tracks(withMediaType: AVMediaTypeAudio)[0], at: kCMTimeZero)
} catch _ {
print("Failed to load Audio track")
}
guard let exporter = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetHighestQuality) else { return }
exporter.audioMix = mix
exporter.outputURL = URL(fileURLWithPath: finalVideoPath)
exporter.outputFileType = AVFileTypeMPEG4
exporter.shouldOptimizeForNetworkUse = true
而且这个代码块后,继续至视频本身呈现的另一种方法。 有人可以解释为什么这不起作用,以及如何解决这个问题?
在此先感谢!