我正在开发一个记录多个文件的iPhone应用程序,然后我将这些文件合并到一个文件中,最后我将该文件上传到服务器上。 我经历过,如果我制作7个薄荷记录的单个文件,其大小为0.85 MB但是如果我制作两个3.5分钟的文件然后将它们合并为单个文件,其大小为9.75 MB,这是非常大的并且花费太长时间上传时间。 请建议我处理这个问题。 提前致谢 `
AVMutableComposition* composition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack* audioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
// kCMPersistentTrackID_Invalid, kCMMediaType_Audio,
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath_ = [searchPaths objectAtIndex: 0];
// RecorderFilePaths contain the path of recorded files
if ([recordedFilePaths count]>0)
{
NSError* error = nil;
AVURLAsset* masterAsset= nil;
CMTime time = kCMTimeZero;
NSURL *tempUrl =[recordedFilePaths objectAtIndex:1];
time = CMTimeAdd(time, [masterAsset duration]);
AVURLAsset *Asset = [AVURLAsset URLAssetWithURL:tempUrl options:nil];
CMTimeRange timeRange = CMTimeRangeMake(kCMTimeZero, Asset.duration);
NSArray *ar = [Asset tracksWithMediaType:AVMediaTypeAudio];
[audioTrack insertTimeRange:timeRange ofTrack:[ar objectAtIndex:0] atTime:kCMTimeZero error:&error];
//kAudioFormatMPEG4AAC, AVMediaTypeAudio
tempUrl = [recordedFilePaths objectAtIndex:0];
masterAsset = [AVURLAsset URLAssetWithURL:tempUrl options:nil];
timeRange = CMTimeRangeMake(kCMTimeZero, masterAsset.duration);
NSArray *tracktypes = [masterAsset tracksWithMediaType:AVMediaTypeAudio];
[audioTrack insertTimeRange:timeRange ofTrack:[tracktypes objectAtIndex:0] atTime:kCMTimeZero error:&error];
if (error)
{
NSLog(@"%@",error);
return;
}
AVAssetExportSession* exportSession = [AVAssetExportSession
exportSessionWithAsset:composition
presetName:AVAssetExportPresetAppleM4A];
// AVAssetExportPresetPassthrough,,AVAssetExportPresetLowQuality
if (nil == exportSession)
{
return;
}
NSString *urlSt = [documentPath_ stringByAppendingPathComponent:[self dateString]];
NSURL* combined = [[NSURL alloc] initFileURLWithPath:urlSt];
exportSession.outputURL = combined;
exportSession.outputFileType = AVFileTypeAppleM4A;
// AVFileTypeAIFF , AVFileTypeAIFC, AVFileTypeAIFC,
[exportSession exportAsynchronouslyWithCompletionHandler:^(void){
dispatch_async(dispatch_get_main_queue(), ^{
switch (exportSession.status)
{
case AVAssetExportSessionStatusFailed:
NSLog(@"Failed");
break;
case AVAssetExportSessionStatusCompleted:
NSLog(@"Completed");
break;
case AVAssetExportSessionStatusWaiting:
break;
default:
break;
}
});
}];
[recordedFilePaths addObject:combined];
}
`