Re: Recovering MPEG-4 and/or lossless audio files
Re: Recovering MPEG-4 and/or lossless audio files
- Subject: Re: Recovering MPEG-4 and/or lossless audio files
- From: Jake Carter <email@hidden>
- Date: Fri, 24 May 2013 10:17:39 -0700
Chris,
We've been working on the same issue. Here's how we solved it.
If you record aac into an adts file it will be compressed and recoverable if the app crashes because the adts container will write out metadata as it's recording.
Next you have to get the aac packets into a format that other computers can read, like an m4a file. For this we used AVAssetExportSession and used the passthrough preset. This way it takes the aac data as-is and just passes it into an m4a container.
One downside of doing it this way is that we need to make sure to have double the hard drive space as the current recording because we're essentially going to copy the file at the end of the recording (to move it to the m4a container). This probably isn't as big deal on the desktop as it can be on an iOS device.
We used AVAudioRecorder to do our recording with the following settings:
NSDictionary *settings = @{AVFormatIDKey: @(kAudioFormatMPEG4AAC), AVSampleRateKey: @44100, AVNumberOfChannelsKey: @1, AVEncoderAudioQualityKey: @(AVAudioQualityMedium)};
self.audioRecorder = [[[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:@"/tmp/src.adts"] settings:settings error:&error] autorelease];
[self.audioRecorder record];
Here's some sample code we used to convert the adts to m4a:
AVURLAsset *sourceAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:@"/tmp/src.adts"] options:nil];
self.exportSession = [AVAssetExportSession exportSessionWithAsset:sourceAsset presetName:AVAssetExportPresetPassthrough];
self.exportSession.outputFileType = AVFileTypeAppleM4A;
self.exportSession.outputURL = [NSURL fileURLWithPath:@"/tmp/dest.m4a"];
[self.exportSession exportAsynchronouslyWithCompletionHandler:^{
// Check exportSession.status and exportSession.error here.
}];
Hopefully this helps. Let me know if you have any questions.
Jake Carter
> On Sat, May 11, 2013 at 4:58 AM, Christopher Liscio <email@hidden> wrote:
> Hey list,
>
> It happens once in a blue moon, but I get gut-wrenching emails from customers explaining that they were in the middle of recording some important audio in TapeDeck (http://tapedeckapp.com), when their system crashes on them.
>
> The crashes aren't always my fault, but it's definitely my problem to try and figure out!
>
> When examining the busted MPEG-4 audio files, it would appear that the entire header is zeroed out while recording. I suspect it is written out during ExtAudioFileDispose(), which obviously isn't called until the recording is stopped successfully.
>
> Given that my MPEG-4 encoding parameters are known, and that I used a constant bit rate, is there any way of recovering the audio data contained in the file?
>
> Also, is there anything I can do during recording in order to "flush" the header to the file periodically and minimize the risk of this occurring in the future?
>
> Thanks,
>
> Chris Liscio
> http://supermegaultragroovy.com
> Learn _your_ music with Capo: http://capoapp.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden