Skip to content

Instantly share code, notes, and snippets.

@jdelStrother
Created February 20, 2014 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdelStrother/9120406 to your computer and use it in GitHub Desktop.
Save jdelStrother/9120406 to your computer and use it in GitHub Desktop.
NSArray* inputURLs = @[[NSURL fileURLWithPath:@"/Users/jon/Desktop/welcome.caf"], [NSURL fileURLWithPath:@"/Users/jon/Desktop/welcome.caf"]];
NSError* error=nil;
AVMutableComposition* composition = [AVMutableComposition composition];
for(NSURL* url in inputURLs) {
AVMutableCompositionTrack* track = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
AVURLAsset* asset = [AVURLAsset assetWithURL:url];
NSArray* assetTracks = [asset tracksWithMediaType:AVMediaTypeAudio];
AVAssetTrack* assetTrack = assetTracks[0];
[track insertTimeRange:assetTrack.timeRange ofTrack:assetTrack atTime:composition.duration error:&error];
}
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetPassthrough];
exporter.outputURL = [NSURL fileURLWithPath:@"/Users/jon/Desktop/output.caf"];
exporter.outputFileType = AVFileTypeCoreAudioFormat;
[exporter exportAsynchronouslyWithCompletionHandler:^{
NSLog(@"Finished! %@ %@", exporter, exporter.error);
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment