How to make your own Augmented Reality Audio-Video Recorder

Sample code for creating an augmented reality AV camera.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 12/16/2021 at 20:37
Last Updated on 12/23/2023 at 04:37
Fireworks

Download an AR camera starter project

Problem

As listed in this tutorial, theres a serious issue recording ARKit video with any existing package — especially Apple’s ReplayKit that breaks at any given moment with no solutions as how to fix it.

In that tutorial, I listed a way to capture AR Frames as UIImages and convert them into video but explained that I had yet to crack Audio — as the existing recorder is very taxing on the system and needs a clean solution that will not break the system.

Solution

Things I tried

  • AVAudioRecorder — Crashes the system in tandem with recording video.
  • AVAudioEngine — Crashes the system in tandem with recording video.

What Worked

Creating a AVCaptureSession with the iPhone microphone as the sole input and its raw data as the sole output.

As the audio CMSampleBuffer comes in with its own ‘time’, the final touch is to correct the time of the recording to match the time of the video frame.

This is then appended onto AVAssetWriter — all of this is covered in Audio Recording Functionality.

Practice

Please refer to this tutorial to explain how video works and once you have covered that one — change the following pieces of code.

New Variables

New didUpdateAtTime

Please note that the system crashes at 30 FPS (currently at 24FPS on line 7).

New Recording Functionality

New Asset Writer

Audio Recording Functionality

That's a wrap

Please email us any questions that you may have using the contact form.

SubscribeInquireView All PostsView All Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe