Convert AAC to WAV

落爺英雄遲暮 提交于 2019-12-09 13:44:09

问题


I'm already using the Media Foundation APIs (thanks to MFManagedEncode, http://blogs.msdn.com/b/mf/archive/2010/02/18/mfmanagedencode.aspx) to convert wav to aac. I haven't fully got my head around how this works, but it does work- thankfully.

Now I'm finding it difficult transcoding the other way, even though there is a MF codec for it (AAC Decoder). I can't find examples of how to use this and I'm finding the MSDN documentation for it cryptic to say the least; anyone had an luck with it?

A C# wrapper for would be ideal.

TIA.


回答1:


I have been succesfuly using NAudio for any audio processing and abstraction. It is available as a NuGet. It has wrapper encoders for Media Foundation (and others).

Here is a sample for encoding to AAC and back to WAV using NAudio:

using System;
using NAudio.Wave;

namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {
            // convert source audio to AAC
            // create media foundation reader to read the source (can be any supported format, mp3, wav, ...)
            using (MediaFoundationReader reader = new MediaFoundationReader(@"d:\source.mp3"))
            {
                MediaFoundationEncoder.EncodeToAac(reader, @"D:\test.mp4");
            }

            // convert "back" to WAV
            // create media foundation reader to read the AAC encoded file
            using (MediaFoundationReader reader = new MediaFoundationReader(@"D:\test.mp4"))
            // resample the file to PCM with same sample rate, channels and bits per sample
            using (ResamplerDmoStream resampledReader = new ResamplerDmoStream(reader, 
                new WaveFormat(reader.WaveFormat.SampleRate, reader.WaveFormat.BitsPerSample, reader.WaveFormat.Channels)))
            // create WAVe file
            using (WaveFileWriter waveWriter = new WaveFileWriter(@"d:\test.wav", resampledReader.WaveFormat))
            {
                // copy samples
                resampledReader.CopyTo(waveWriter);
            }
        }
    }
}


来源:https://stackoverflow.com/questions/13486747/convert-aac-to-wav

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!