Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

c# - Extract wav file from video file

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...