【问题标题】:How to convert WAV file to M4A?如何将 WAV 文件转换为 M4A?
【发布时间】:2011-06-17 00:50:06
【问题描述】:

有什么方法可以将我录制的 .WAV 文件在 iOS 中转换为 .M4A 文件?

而且我还必须将 .M4A 文件转换为 .WAV 文件。

我尝试使用音频队列服务,但我做不到。

【问题讨论】:

    标签: ios audio wav m4a


    【解决方案1】:

    这篇文章: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 lib 并在其中进行所有转换,但这似乎与您想要的不同。

    【讨论】:

    • 这里的channelLayout是什么?
    • 根据链接的帖子:AudioChannelLayout channelLayout; memset(&channelLayout, 0, sizeof(AudioChannelLayout)); channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
    【解决方案2】:

    TPAACAudioConverter 工作正常

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-23
      • 2019-01-07
      • 2022-10-23
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-28
      • 1970-01-01
      相关资源
      最近更新 更多