我希望使用C#中的IMFSourceReader解码并重新采样音频文件。
例如:
我想解码(MP3到WAV)并重新采样以下音频文件的比特率(64Kbps到192Kbps) -
MyAudioFile - 48KHz - 64Kbps.MP3
到 -
MyAudioFile - 48KHz - 192Kbps.WAV
我正在尝试通过指定部分媒体设置将MP3解码为WAV,如下面的代码所示,但它没有重新采样已解码的WAV文件:
var fileStream = ((MediaFoundationReaderRTSettings) settings).Stream;
var byteStream = MediaFoundationApi.CreateByteStream(fileStream);
var reader =
MediaFoundationApi.CreateSourceReaderFromByteStream(byteStream);
reader.SetStreamSelection(
MediaFoundationInterop.MF_SOURCE_READER_ALL_STREAMS, false);
reader.SetStreamSelection(
MediaFoundationInterop.MF_SOURCE_READER_FIRST_AUDIO_STREAM, true);
//Create a partial media type indicating that we want uncompressed PCM audio
var partialMediaType = new MediaType();
partialMediaType.MajorType = MediaTypes.MFMediaType_Audio;
partialMediaType.SubType = settings.RequestFloatOutput ?
AudioSubtypes.MFAudioFormat_Float : AudioSubtypes.MFAudioFormat_PCM;
partialMediaType.SampleRate = 48000;
partialMediaType.BitsPerSample = 16;
partialMediaType.ChannelCount = 2;
// set the media type
// can return MF_E_INVALIDMEDIATYPE if not supported
reader.SetCurrentMediaType(
MediaFoundationInterop.MF_SOURCE_READER_FIRST_AUDIO_STREAM, IntPtr.Zero,
partialMediaType.MediaFoundationObject);
return reader;
通过一些例子感谢如何解决这个问题。谢谢!