tags:

views:

1871

answers:

5

What is the best solution for converting WAV files to WMA (and vice versa) in C#? I have actually implemented this once already using the Windows Media Encoder SDK, but having to distribute Windows Media Encoder with my application is cumbersome to say the least. The Windows Media Format SDK has large sections of the API marked as deprecated. It looks like there might be some DirectX Media Objects (DMOs) I could use from the Windows SDK, but there would be an awful lot of interop to write.

I am wondering if there perhaps is a good managed wrapper for an unmanaged library that can perform the conversions. It would need a license that allows it to be distributed as part of a closed source commercial application.

+1  A: 

I haven't tried it personally (so not sure if it's the 'best' solution), but http://www.codeproject.com/KB/audio-video/WmaCompressor.aspx looks like it should meet your requirements...

mdb
yes, I think this is the most promising solution available at the moment. The same author has also done a C# port of the Windows Media Format SDK. My only concern is that it is very unclear whether the code can be used in a commercial project.
Mark Heath
+1  A: 

You can take a look at the BASS library. It has add-ons, such as BASSWMA and BASSEnc for doing encoding/decoding. All its API's are accessible from .NET using the BASS.Net wrapper.

Both BASS and BASS.Net could be licensed for commercial use, with a reasonable fee (€100 each).

Magnus Johansson
+1  A: 

If you're comfortable writing a bit of C++/CLI then you don't need much code to create a wrapper around DirectShow to do this. This can then be called directly from a C# assembly with no need to mess about with interop. Doing it with DirectShow is much easier than using WMF directly because you don't have to do any file parsing or I/O - it's all done for you. For reference, I have code in a commercial app that can encode/decode WMA to/from WAV files in less than 100 lines of C++, all wrapped up in a friendly .Net class. Judicious use of smart pointers helps if you go down this route...

Stu Mackellar
A: 

You might look at www.mitov.com. There are some libraries there that may help. You'll need to buy a copy to ship in a commercial product, I believe, but I think it's a reasonable price.

GuyWithDogs
+1  A: 

First of all, look at this:

http://windowsmedianet.sourceforge.net/

Then, search for IWMWritter - and various ways of initializing it. You will supply raw PCM data, and it will write out wma file.

Tag my answer please for more info on this.

Daniel Mošmondor