我正在开发一个记录多个文件的 iPhone 应用程序,然后我将这些文件合并到一个文件中,最后我将该文件上传到服务器上。我经历过,如果我制作一个 7 mint 的文件,它的大小是 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];
}
`