如何将WAV文件转换为M4A?
答
此文章:From iPod Library to PCM Samples in Far Fewer Steps Than Were Previously Necessary介绍了如何从用户ipod库加载文件并将其作为线性pcm(wav)文件写入文件系统。
我相信,你将需要对代码的改变来加载从文件系统中的文件,而不是将是描述NSURL其中资产是:
-(IBAction) convertTapped: (id) sender {
// set up an AVAssetReader to read from the iPod Library
NSURL *assetURL = [[NSURL alloc] initFileURLWithPath:@"your_m4a.m4a"];
AVURLAsset *songAsset =
[AVURLAsset URLAssetWithURL:assetURL options:nil];
NSError *assetError = nil;
AVAssetReader *assetReader =
[[AVAssetReader assetReaderWithAsset:songAsset
error:&assetError]
retain];
if (assetError) {
NSLog (@"error: %@", assetError);
return;
}
如果您打算在相反的方向,则需要改变输出端的格式:
NSDictionary *outputSettings =[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
[NSNumber numberWithInt:2], AVNumberOfChannelsKey,
[NSData dataWithBytes:&channelLayout length:sizeof(AudioChannelLayout)],
AVChannelLayoutKey,
[NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey,
nil];
我不知道确切的设置可能会包含在这里M4A,但这应该让你更接近。
另一种选择是加载ffmpeg库并在那里做所有的转换,但是这看起来与你想要的不同。
什么是channelLayout在这里? – 2013-01-01 15:28:37