I record video (.mp4 file) using AVAssetWriter
with CMSampleBuffer
data (from video, audio inputs).
While recording I want to process frames, I'm converting CMSampleBuffer
to CIImage
and processing it.
but how to update CMSampleBuffer
with my new processed image buffer from CIImage
?
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
if output == videoOutput {
let imageBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!
let ciimage: CIImage = CIImage(cvPixelBuffer: imageBuffer)
... // my code to process CIImage (for example add augmented reality)
// but how to convert it back to CMSampleBuffer?
// because AVAssetWriterInput to encode video/audio in file needs CMSampleBuffer
...
}
...
}