Hi,
I 'm using c#.net(3.0),I want to extract audio from an AVI file(Audio/Video file *.avi) in wav format(*.wav) could anyone please tell how to do this using C#.net.

please don't suggest this link-http://www.codeproject.com/KB/audio-video/avifilewrapper.aspx
(as the example given is not working on all *.avi files).


thank you

You may use the MCI - Media Control Interface API.

The problem with the *.avi extension, is that its not definite. It could be compressed with any codec. and not even large software companies grantee 100% playability on video files. avi is tipically an mpeg-4 video format file, but could be many other codecs, ajpg which is a jpeg video format, it could be huffyuv, or bmp or any of the first set of wind-98 included codecs. or it could be DIVXmp47 which will require divxmp47 codec installed to play. you never know what codec you need for the video or the audio in an avi file, its often two completely different unrelated codecs. Its most likely that the trouble you had with the first example was a codec issue, just because WMP will play a file doesn't mean the codec is properly registerd or doesn't require wrapping to be used with managed code.

Video codecs is a deep rabit whole, so the next question really is, do you want to try and find out what went wrong with the example you found, which could be a inconsistency on your system due to codecs, or do you want to start custom building codec graph wrappers in managed code, because its unsupported directly? so I guess its the blue or the red pill eh? Either way, play to pull out a copy of graph edit anyway. Just to be on the safe side. you can see all the codecs installed on the system. build a graph that works with the videos you were having trouble with, you can use graph edit to actually extract the audio, or you can just find out what you need to do to actually build a codec graph to do it through interlop.

The problem with the *.avi extension, is that its not definite. It could be compressed with any codec. and not even large software companies grantee 100% playability on video files. avi is tipically an mpeg-4 video format file, but could be many other codecs, ajpg which is a jpeg video format, it could be huffyuv, or bmp or any of the first set of wind-98 included codecs. or it could be DIVXmp47 which will require divxmp47 codec installed to play. you never know what codec you need for the video or the audio in an avi file, its often two completely different unrelated codecs. Its most likely that the trouble you had with the first example was a codec issue, just because WMP will play a file doesn't mean the codec is properly registerd or doesn't require wrapping to be used with managed code.

Video codecs is a deep rabit whole, so the next question really is, do you want to try and find out what went wrong with the example you found, which could be a inconsistency on your system due to codecs, or do you want to start custom building codec graph wrappers in managed code, because its unsupported directly? so I guess its the blue or the red pill eh? Either way, play to pull out a copy of graph edit anyway. Just to be on the safe side. you can see all the codecs installed on the system. build a graph that works with the videos you were having trouble with, you can use graph edit to actually extract the audio, or you can just find out what you need to do to actually build a codec graph to do it through interlop.

thanks for your reply.
it is difficult to start from the scrach so could you help me in understanding what went wrong in the given example

I tested the example on some stubborn avi files I have, some of which that use an open source version of aac3 audio and divix for video, they worked fine. I downloaded some random avi files from piratesbay. music videos and stuffs, they all worked fine. I can't seem to recreate any issues with that example, the only problem I found is that sometimes the frame count is missjudged and leads to an object didn't return and instance of an object error, but that's at the end, and all file creation seems to be fine.

There may be a issue with codecs on your computer that cause the problem, there is a free program called GSpot, that will analize a video and tell you if you have the proper codecs installed. I recommend you find and download that program to make sure its a software problem and not something to do with the video files themselfs which could be corrupted, or codec issues.

because as i said. No issues myself with the codeproject example you used.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.