我已经在使用Media Foundation API(感谢MFManagedEncode,http://blogs.msdn.com/b/mf/archive/2010/02/18/mfmanagedencode.aspx)将wav转换为aac。我还没有完全弄清楚它是如何工作的,但它确实起作用了--谢天谢地。
现在我发现很难通过另一种方式进行代码转换,即使有一个MF编解码器(AAC解码器)。我找不到如何使用它的示例,而且我发现它的MSDN文档至少可以说是晦涩难懂的;有人幸运地使用过它吗?
的C#包装器将是理想的。
蒂娅。
发布于 2015-01-13 18:37:55
我已经成功地使用NAudio进行任何音频处理和抽象。它以NuGet的形式提供。它有用于Media Foundation (和其他)的包装器编码器。
下面是一个使用NAudio编码到AAC和返回WAV的示例:
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
复制相似问题