I'm trying to save captured video & audio through a camera and mic on an iOS device using AVAssetWriter. I finished developing a basic function like a user can record both image(video) and audio using CMSampleBuffer, and now I'm trying to make the mute function available. I guess while isMuted
is true, I need to append empty (or silent?) CMSampleBuffer
to assetWriterAudioInput
, but is that right approach? If not could you point me in the right direction? Also, in createSilenceBuffer
function, how can I create empty/slient CMSampleBuffer?
var isMuted: Bool = false
var assetWriterAudioInput: AVAssetWriterInput?
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
if output == videoOutput {
guard assetWriterVideoInput?.isReadyForMoreMediaData == true else { return }
assetWriterVideoInput?.append(sampleBuffer)
} else if output == audioOutput {
if issued {
let silenceBuffer = createSilenceBuffer(from sampleBuffer)
assetWriterAudioInput?.append(silenceBuffer)
} else {
assetWriterAudioInput?.append(sampleBuffer)
}
}
}
func createSilenceBuffer(from sampleBuffer: CMSampleBuffer) -> CMSampleBuffer {
// return new CMSampleBuffer without audio??
}