ruanjx / VideoLab

High-performance and flexible video editing and effects framework, based on AVFoundation and Metal.
MIT License
845 stars 176 forks source link

How to mute asset audio and add custom audio? #12

Open Coder-ACJHP opened 2 years ago

Coder-ACJHP commented 2 years ago

Hi @ruanjx ,

First of all thank you for your effort, this is awesome framework that make work with AVFoundation easier.

Secondly I have a question about muting original audio of AVAsset and add custom audio to RenderComposition? I already tried to mute videoLayer with audioConfiguration like this

var audioConfiguration = AudioConfiguration()
let volumeRampTimeRange = source.selectedTimeRange
let volumeRamp1 = VolumeRamp(startVolume: 0.0, endVolume: 0.0, timeRange: volumeRampTimeRange)
audioConfiguration.volumeRamps = [volumeRamp1]
videoLayer.audioConfiguration = audioConfiguration

and then added new renderLayer for custom audio (mp3 file) named audioLayer and passed it to render composition like this

let composition = RenderComposition()
composition.layers = [videoLayer, audioLayer]

videoLayer sound plays 1 second and then its being muted, audioLayer audio works well but no video on composition entirely it becomes black screen. Actually I couldn't see how to manage audio files in your documentation. Any helps will be appreciated .

Coder-ACJHP commented 2 years ago

Update I fixed black screen issue when I add audio layer with adjusting selectedTimeRange but still original audio of video asset playing for 1 second at start even it's muted with audioConfiguration