I'm recording audio on an iPhone, using an AVAudioRecorder
with the following settings:
NSMutableDictionary *recordSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSNumber numberWithInt:12800], AVEncoderBitRateKey,
[NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
[NSNumber numberWithInt: AVAudioQualityHigh], AVEncoderAudioQualityKey,
nil];
(I can be flexible on most of these settings, but I have to use MPEG4 AAC.)
I save the audio to a file.
The user needs to be able to come back at a later date and continue recording to the same file. There doesn't seem to be an option to do this directly with AVAudioRecorder
, so instead I'm recording to a new file and concatenating them.
At the moment I'm appending the files using an AVMutableComposition
and an AVMutableCompositionTrack
as here, but it's really slow for longer recordings so this isn't really feasible.
I'm thinking it would be much quicker if I could strip the header from the second file, append the audio data to the first file, then alter the header of the combined file to reflect the new duration. As I know both files were created with exactly the same settings, I figure the other details in the headers should be identical.
Unfortunately I can't find any information about what format the headers are in, or if it's possible to combine files in this way.
So my questions are:
- What is the format of the MPEG-4 AAC file header, when created on an iPhone?
- Can I combine two audio files by messing with the headers like this?
- Is there a better way of appending two MPEG-4 AAC audio files almost instantaneously?