This project has moved and is read-only. For the latest updates, please go here.

Convert mp4 to WAV stream

Aug 23, 2016 at 10:21 AM
Edited Aug 23, 2016 at 10:42 AM
I have an MP4 audio file to which I have a public URL (audio file contains voice message that was recorded by Facebook Messenger mobile application). I am trying to convert this mp4 file (Codec: MPEG AAC Audio, Channels: Stereo, Sample rate: 16000) to WAV stream (running on Windows 10 Home) using this code:
using (MediaFoundationReader reader = new MediaFoundationReader(url))
    ResamplerDmoStream resampledReader;
    using (resampledReader = new ResamplerDmoStream(reader,
                        new WaveFormat(16000, 16, 1)))
        //save to file just to verify that conversion was done OK
The following is the implementation of voiceToFile method
private static void voiceToFile(Stream audio)
    byte[] b;

    using (BinaryReader br = new BinaryReader(audio))
        b = br.ReadBytes((int)audio.Length);
     File.WriteAllBytes("c:\\fbaudio_" + Guid.NewGuid().ToString() + ".wav", b);
The WAV file created cannot be played by any player. Please advise what could be the reason for this.
Aug 24, 2016 at 12:07 AM
I´d try a different Resampler, perhaps your DMO can´t resample that Waveformat.

Or you don´t have MediaFoundation installed.

And you should use the Read method to fill into a buffer instead of reading all at once. I don´t know, if then the Audio is Resampled correctly or at all.