I'm trying to compress input from AVCaptureSession and save it to an .mp4 file. I've managed to convert and save video without issues but am having trouble with audio.
I've reached a point where I'm able to convert audio samples to AAC and I can save the converted CMSampleBuffer to .mp4 but when I play it back on the iPhone, the audio sounds distorted. Click here to download a sample file.
I'm passing the following format to the converter:
AudioStreamBasicDescription(mSampleRate: 44_100,
mFormatID: kAudioFormatMPEG4AAC,
mFormatFlags: UInt32(MPEG4ObjectID.AAC_LC.rawValue),
mBytesPerPacket: 0,
mFramesPerPacket: 1024,
mBytesPerFrame: 0,
mChannelsPerFrame: 2,
mBitsPerChannel: 0,
mReserved: 0)
I'm not sure if this is an issue with audio conversion or with writing the file. Here's a link to a sample project with just the audio stream conversion and writing: https://github.com/gaperlinski/AudioConversion (follow the instructions in README.MD to reproduce the issue)
Is there anything obvious I'm doing wrong that causes the audio to sound like that?