How do I draw text in CIImage?
How to draw CIImage
(or maybe in CVPixelBuffer
, but it seems to me that adding text in CIImage
) is easier)? not UIImage
I am recording video (.mp4 file) using AVAssetWriter
and CMSampleBuffer
(from video, audio inputs). While recording, I want to add text to video frames, I am already converting CMSampleBuffer
to CIImage
, now I need to somehow add text to CIImage
and convert back to CVPixelBuffer
. I haven't really found any simple examples in Swift of adding (drawing) text to CIImage
or adding anything else (like lines, rectangles, not just text).
/// encode video buffer
func appendVideoSampleBuffer(_ sampleBuffer: CMSampleBuffer) {
// before encoding video frames into a file I would like process it
// 1. convert CMSampleBuffer to ciImage
let cvPixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!
let ciimage : CIImage = CIImage(cvPixelBuffer: cvPixelBuffer)
// 2. do something with CIImage
// 3. convert CIImage back to CMSampleBuffer
let sampleBufferWithText == ...
appendSampleBuffer(sampleBufferWithText, ofMediaType: AVMediaType.video.rawValue)
}
/// encode audio buffer
func appendAudioSampleBuffer(_ sampleBuffer: CMSampleBuffer) {
appendSampleBuffer(sampleBuffer, ofMediaType: AVMediaType.audio.rawValue)
}
source to share
No one has answered this question yet
See similar questions:
or similar: