iOS postprocessing - overlay timestamp to video and export

1.1k Views Asked by At

I am working on an application where video and time/GPS/accelerometer data is simultaneously recorded to separate files.

I can play the video and have my overlay appear perfectly in realtime, but I cannot simply export this.

I am wanting to post-process the video and overlay the time,coordinates and on the video. There are other shapes that will be overlayed which change size/position on each frame.

I have tried using AVMutableComposition and adding CALayers with limited results- This works to an extent but I cannot synchronise the timestamp with the video. I could use a CAKeyframeAnimation with values+keyTimes, but the amount of values I need to work with is excessive.

My current approach is to render a separate video consisting of CGImages created using the data. This works well but I will need to use a ChromaKey to have transparency in the overlay. I have read that there will likely be quality issues after doing this.

Is there a simpler approach that I should be looking at?

I understand that render speed will not be fantastic, however I do not wish to require a separate 'PC' application to render the video.

2

There are 2 best solutions below

0
On

Use AVAssetReader for recorded video. Get the CMSampleBufferRef, get it timestamp, draw time on sample buffer, write buffer to AVAssetWriterInputPixelBufferAdaptor. Similar approach for video being recorded.

0
On

Use the AVVideoCompositing protocol https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVVideoCompositing_Protocol/index.html

This will allow you to get frame by frame call backs with the pixel buffers to do what you want.

With this protocol you will be able to take one frame and overlay whoever you would like. Take a look at This sample - https://developer.apple.com/library/ios/samplecode/AVCustomEdit/Introduction/Intro.html to see how to handle frame by frame modifications. If you take advantage of the AVVideoCompositing protocol you can set a custom video compositor and a video composition on your AVPlayerItem and AVExportSession to render/export what you want.