Search code examples
videoswift3avfoundationavassetwriter

Edit video : Add real time text, layer, image,... to video


I'm having trouble adding labels to display the current time on the video, but I do not know where to start. I found an example of an apple edit video: https://developer.apple.com/library/content/samplecode/ReaderWriter/Introduction/Intro.html.

I'm trying to add AVAssetWriterInputPixelBufferAdaptor in AVAssetWriterInput, but I crashed when calling function: append (_ pixelBuffer: CVPixelBuffer, withPresentationTime presentationTime: CMTime) -> Bool

What I want to know is how can I paint up a similar time as a video https://www.youtube.com/watch?v=9mmrBDA1baY

Update:

I was a bit confused about append PixelBuffer with an adapter, but it was just a matter of connecting the frames back to the video. At Apple's instance, every thing was handled with CMSampleBuffer in "sampleBufferProcessor" The next thing to do is to process CVPixelBuffer how to add a layer or text to the current time (automatically change in real time) This is what I found when watching WWDC 2014 Help me in the right direction enter image description here


Solution

  • If you just want to add overlays on video, you can use AVVideoCompositionCoreAnimationTool. Add animation of text change on CATextLayer and export it.