Question

I have a 22kHz wave file and want a 22kHz m4a file. AVAssetExportSession with the preset AVAssetExportPresetAppleM4A automatically converts my wav to 44kHZ. I've tried different presets and nil to create the ExportSession, but without success.

Is there a way to set custom export properties of an AVAssetExportSession or do I need a completely different approach like the one stated in How to convert WAV file to M4A??

here is the code I have so far, which works great if you want a 44kHz file:

AVURLAsset *wavAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:wavPath] options:optionsDict];

AVMutableComposition *mutableComposition = [AVMutableComposition composition];
[mutableComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, wavAsset.duration)
  ofAsset:wavAsset atTime:kCMTimeZero error:&error];

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
  initWithAsset:[mutableComposition copy] presetName:AVAssetExportPresetAppleM4A];
exportSession.outputURL = [NSURL fileURLWithPath:m4aPath];
exportSession.outputFileType = AVFileTypeAppleM4A;

[exportSession exportAsynchronouslyWithCompletionHandler:^{
  switch (exportSession.status) {
    case AVAssetExportSessionStatusCompleted: {
      [exportSession release];
      completionHandler(nil);
      break;
    }
    case AVAssetExportSessionStatusFailed: {
      NSLog(@"There was an error while exporting the file: %@", exportSession.error);
      completionHandler(exportSession.error);
      break;
    }
    // ... handle some other cases...
    default: {
      break;
    }
  }
}];

Would be great if I just missed something.

Thanks in advance, Dom

Was it helpful?

Solution

I've had some luck with the TPAACAudioConverter available here. It uses the ExtendedAudioFile API in the AudioToolbox Framework.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top