6

I am developing an application in which I need to extract the audio from a video. The audio needs to be extracted in .wav format but I do not have a problem with the video format. Any format will do, as long as I can extract the audio in a wav file.

Currently I am using Windows Media Player COM control in a windows form to play the videos, but any other embedded player will do as well.

Any suggestions on how to do this? Thanks

Nikos Steiakakis
  • 5,605
  • 7
  • 44
  • 54

4 Answers4

3

If you want to do this with C#, take a look at NAudio library. It can analyze the audio format (like FFMpeg) and also provide the audio stream. Here's one example.

Snippet from the sample:

using NAudio.Wave;
using System.IO;

...

// contentAsByteArray consists of video bytes
MemoryStream contentAsMemoryStream = new MemoryStream(contentAsByteArray);

using (WaveStream pcmStream =
    WaveFormatConversionStream.CreatePcmStream(
        new StreamMediaFoundationReader(contentAsMemoryStream)))
{
    WaveStream blockAlignReductionStream = new BlockAlignReductionStream(pcmStream);

    // Do something with the wave stream
}
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/19283625) – Mark Rotteveel Mar 30 '18 at 15:20
  • @MarkRotteveel You are absolutely right. I will try to do as you advised in the future. Here the answer would be quite lengthy given the fairly broad topic and frankly I don't know where to start. NAudio library is essential to my solution. – Tomi Paananen Mar 31 '18 at 09:43
  • Added a snippet – Tomi Paananen Mar 31 '18 at 10:03
  • Hey thanks! I asked that question 9 years ago and I used the solution provided in the accepted answer I think. Your solution seems quite good as well, unfortunately I cannot really test it any more. :) – Nikos Steiakakis Mar 31 '18 at 12:21
  • 1
    @NikosSteiakakis I had to solve this problem last week and that's how I found your question. Since the topic is still relevant and lacked a satisfying answer (for my use-case) I decided to provide mine :) – Tomi Paananen Mar 31 '18 at 13:05
2

Probably easiest to use ffmpeg for this kinda thing...

Chris
  • 39,719
  • 45
  • 189
  • 235
  • Thanks! I was thinking something more in a .dll form, but an executable will do the trick if I don't find anything more suitable. – Nikos Steiakakis Jun 19 '09 at 04:52
  • There's no shame in shelling out to an exe! ;) Yes, i know where you're coming from. Depends how professional you want it to be. – Chris Jun 19 '09 at 04:59
2

Here is a link on how to extract audio using GraphEdit, GraphEdit is an front end UI for the DirectShow API so everything it can do you can do with API.
You can use the DirectShow.NET liberty which wraps the DirectShow API for the managed world.

Shay Erlichmen
  • 31,691
  • 7
  • 68
  • 87
0

Very easy with FFMPEG! I routinely do this to grab audio out of downloaded youtube videos, convert music downlaods to WAV for editing, etc etc. It should work for any file extension:

ffmpeg -i source-of-any-file-extension.avi -vn -ar 44100 -ac 2 -ab 768000 -f wav target-filename.wav

ClioCJS
  • 64
  • 3
  • 11