I\'m recording video and audio using AVCaptureVideoDataOutput
and AVCaptureAudioDataOutput
and in the captureOutput:didOutputSampleBuffer:fromCon
Swift version of Bannings's answer.
let combinedFilter = CIFilter(name: "CISourceOverCompositing")!
combinedFilter.setValue(maskImage.oriented(.left), forKey: "inputImage")
combinedFilter.setValue(inputImage, forKey: "inputBackgroundImage")
let outputImage = combinedFilter.outputImage!
let tmpcontext = CIContext(options: nil)
tmpcontext.render(outputImage, to: pixelBuffer, bounds: outputImage.extent, colorSpace: CGColorSpaceCreateDeviceRGB())