CMSampleBuffer's audio format changes when coming from the background

Hi,

I'm capturing Audio and Video using AVFoundation's AVCaptureSession using the AVCaptureVideoDataOutputSampleBufferDelegate & AVCaptureAudioDataOutputSampleBufferDelegate to collect CMSampleBuffers and write them to file using AVAssetWriter.

The issues I'm facing is that while recording if the user goes to the background and returns, the CMSampleBuffer's AudioFormat changes from:

this

  •   FormatList Array: {
      	Index: 0 
      	ChannelLayoutTag: 0x640001 
      	ASBD: {
      	mSampleRate: 48000.000000 
      	mFormatID: 'lpcm' 
      	mFormatFlags: 0xc 
      	mBytesPerPacket: 2 
      	mFramesPerPacket: 1 
      	mBytesPerFrame: 2 
      	mChannelsPerFrame: 1 
      	mBitsPerChannel: 16 	}} 
    

to this:

  •   FormatList Array: {
      	Index: 0 
      	ChannelLayoutTag: 0x640001 
      	ASBD: {
      	mSampleRate: 48000.000000 
      	mFormatID: 'lpcm' 
      	mFormatFlags: 0xc 
      	mBytesPerPacket: 8 
      	mFramesPerPacket: 1 
      	mBytesPerFrame: 8 
      	mChannelsPerFrame: 4 
      	mBitsPerChannel: 16 	}} 
    

This obviously creates an issue with the AudioInput in the AVAssetWriter and fails the writing

Does anyone have an idea what going on?

As to the CaptureSession setup:

  • Inputs:

Front / back camera & internal microphone

  • outputs:

AVCaptureVideoDataOutput & AVCaptureAudioDataOutput

I am changing the active format in the videoInput's device when I start the session

Thanks, Yoav

Anyone?

I am seeing the same problematic 4 channel format on iPhone 14 when I set up Audio session in videoChat mode. Can someone from @Apple please comment on how to force default 1 channel / frame format

CMSampleBuffer's audio format changes when coming from the background
 
 
Q