如何在AVPlayer上添加AVAudioUnitEQ效果
我正在尝试在 AVPlayer
上添加均衡器效果。视频播放时主要需要音频声音的混响和频段变化。
class ViewController: UIViewController {
let engine = AVAudioEngine()
let reverb = AVAudioUnitReverb()
var sourceFile: AVAudioFile!
var format: AVAudioFormat!
override func viewDidLoad() {
super.viewDidLoad()
setupAudioEngine()
}
func setupAudioEngine() {
do {
let sourceFileURL = Bundle.main.url(forResource: "videosong", withExtension: "mp4")!
sourceFile = try AVAudioFile(forReading: sourceFileURL)
format = sourceFile.processingFormat
} catch {
fatalError("could not open source audio file, \(error)")
}
let player = AVAudioPlayerNode()
engine.attach(player)
engine.attach(reverb)
// set desired reverb parameters
reverb.loadFactoryPreset(.mediumHall)
reverb.wetDryMix = 70
// make connections
engine.connect(player, to: reverb, format: format)
engine.connect(reverb, to: engine.mainMixerNode, format: format)
// schedule source file
player.scheduleFile(sourceFile, at: nil)
do {
try engine.start()
player.play()
} catch {
fatalError("could not start engine, \(error)")
}
// SaveFile()
}
}
我正在使用 mp4
格式的视频文件。我需要在视频播放上实现混响效果。
我们如何使用 AVPlayer
作为输入节点还有其他方式吗?请帮助我。
I am trying achive to add equalizer effects on AVPlayer
. Basically need reverb and frequency band change of audio sound on Video Playback.
class ViewController: UIViewController {
let engine = AVAudioEngine()
let reverb = AVAudioUnitReverb()
var sourceFile: AVAudioFile!
var format: AVAudioFormat!
override func viewDidLoad() {
super.viewDidLoad()
setupAudioEngine()
}
func setupAudioEngine() {
do {
let sourceFileURL = Bundle.main.url(forResource: "videosong", withExtension: "mp4")!
sourceFile = try AVAudioFile(forReading: sourceFileURL)
format = sourceFile.processingFormat
} catch {
fatalError("could not open source audio file, \(error)")
}
let player = AVAudioPlayerNode()
engine.attach(player)
engine.attach(reverb)
// set desired reverb parameters
reverb.loadFactoryPreset(.mediumHall)
reverb.wetDryMix = 70
// make connections
engine.connect(player, to: reverb, format: format)
engine.connect(reverb, to: engine.mainMixerNode, format: format)
// schedule source file
player.scheduleFile(sourceFile, at: nil)
do {
try engine.start()
player.play()
} catch {
fatalError("could not start engine, \(error)")
}
// SaveFile()
}
}
I am using Video file in mp4
format. and i need to achieve reverb effect on video playback.
How we can use AVPlayer
as input node are any other way ? Please Help me in this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论