1
我有一個22kHz的波形文件,想要一個22kHz的m4a文件。帶預設AVAssetExportPresetAppleM4A的AVAssetExportSession會自動將我的wav轉換爲44kHZ。我嘗試了不同的預設,並且無法創建ExportSession,但沒有成功。如何使用AVAssetExportSession將22kHz的wav文件導出到m4a?
有沒有辦法設置AVAssetExportSession的自定義導出屬性,還是我需要一個完全不同的方法,如How to convert WAV file to M4A?中所述的方法?
這裏是代碼我到目前爲止,如果你想要一個44kHz的文件,它的偉大工程:
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;
}
}
}];
將是巨大的,如果我只是錯過了一些東西。
由於提前, 大教堂