0

I have an AVAssetWriter and I do set audio compression settings dictionary using canApply(outputSettings: audioCompressionSettings, forMediaType: .audio) API.

One of the fields in the compression settings is setting an audio sample rate using AVSampleRateKey. My question is if the sample rate I set in this key is different from sample rate of audio sample buffers that are appended, can this cause audio to drift away from video? Is setting arbitrary sample rate in asset writer settings not recommended?

Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131

1 Answers1

1

If the sample rate of the sample buffers and the AVAssetWriterInput's outputSettings differ, then the sample buffers will be rate converted.

I have not observed AV sync problems due to Apple sample rate conversion APIs.
They seem to do the right thing.

Are you seeing a problem?

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159
  • I am seeing AV drift (or rather, some users of my app are seeing AV drift with external microphones attached). I have two AVCaptureSessions, one for video and another for audio and use CMClock conversion APIs to do AV sync. I contacted DTS for the potential sources and they say sample rate conversion *could* be a problem! But they do not confirm it. – Deepak Sharma Dec 07 '22 at 09:12
  • External microphone as in a usb audio interface? You can't use just one capture session? Multiple ones tend to make me nervous... You should probably add the multiple capture sessions, external mics and what you do with the clocks to your questions. It's much more complicated than the question lets on. – Rhythmic Fistman Dec 07 '22 at 10:41
  • External mic could be USB or Bluetooth. The reason for using two capture sessions is that if I use single AVCaptureSession, I can not support switching cameras while recording -- AVCaptureAudioDataOutput stalls when user switches cameras. I was earlier using Remote RIO for audio input but it showed it's own problems. DTS suggested to use two capture sessions and it works in principle, but on the field it is showing issues that I can not reproduce. I warned DTS that this is an *unconventional* approach bound to have its own problems but they denied! – Deepak Sharma Dec 10 '22 at 06:03