Question

Greetings,

I'm trying to find either a free .NET library or a command-line executable that lets me convert M4A files to either MP3s or WMA files. Please help :).

Was it helpful?

Solution

Found it!

http://pieter.wigleven.com/it/archives/3

There may be other solutions, but this is gold for what I was looking for.

P.S. I've written a .NET DLL which handles this behind-the-scenes. It's pretty terrible code, but it gets the job done.

OTHER TIPS

This is simple if you know the right tools:

ffmpeg -i infile.m4a tmp.wav
lame tmp.wav outfile.mp3

Here a batch version (sorry Linux/Mac only):

#!/bin/bash

n=0
maxjobs=3

for i in *.m4a ; do
    ffmpeg -i "$i" "$TMP/${i%m4a}wav"
    (lame "$TMP/${i%m4a}wav" "${i%m4a}mp3" ; rm "$TMP/${i%m4a}wav") &

    # limit jobs
    if (( $(($((++n)) % $maxjobs)) == 0 )) ; then
        wait
    fi

done

Interesting.
The link you give points to a command line utility.
If you really want to do that programmatically, you might be interested by the DLL version I found at Rarewares. Not sure if API description comes with it... :-)

from How to convert media file to WMA file

string fileName = @"e:\Down\test.wmv";
DsConvert.ToWma(fileName, fileName + ".wma", DsConvert.WmaProfile.Stereo128);

For UWP

public class ConvertToMp3Manager
{
    public PrepareTranscodeResult PrepareTranscode = null;
    public MediaTranscoder TransCoder = null;
    public StorageFile SourceAudio { get; set; }
    public StorageFile DestinationAudio { get; set; }
    public AudioFormat AudioFormat { get; set; }
    public AudioEncodingQuality AudioQuality { get; set; }
    private MediaEncodingProfile profile = null;
    public  ConvertToMp3Manager(StorageFile sourceAudio, StorageFile destinationAudio, AudioFormat AudioType = AudioFormat.MP3, AudioEncodingQuality audioEncodingQuality = AudioEncodingQuality.High)
    {
        if (sourceAudio == null || destinationAudio == null)
            throw new ArgumentNullException("sourceAudio and destinationAudio cannot be null");
        switch (AudioType)
        {
            case AudioFormat.AAC:
            case AudioFormat.M4A:
                profile = MediaEncodingProfile.CreateM4a(audioEncodingQuality);
                break;
            case AudioFormat.MP3:
                profile = MediaEncodingProfile.CreateMp3(audioEncodingQuality);
                break;
            case AudioFormat.WMA:
                profile = MediaEncodingProfile.CreateWma(audioEncodingQuality);
                break;
        }
        this.SourceAudio = sourceAudio;
        this.DestinationAudio = destinationAudio;
        this.AudioFormat = AudioType;
        this.AudioQuality = audioEncodingQuality;
        this.TransCoder = new MediaTranscoder();
    }
    /// <summary>
    /// Return true if audio can be transcoded
    /// </summary>
    /// <returns></returns>
    public async Task<bool> ConvertAudioAsync()
    {
        PrepareTranscode = await this.TransCoder.PrepareFileTranscodeAsync(this.SourceAudio, this.DestinationAudio, profile);
        if (PrepareTranscode.CanTranscode)
        {
            var transcodeOp = PrepareTranscode.TranscodeAsync();
            return true;
        }
        else
            return false;
    }
    public static async Task<bool> ConvertAudioAsync(StorageFile sourceAudio, StorageFile destinationAudio, AudioFormat AudioType = AudioFormat.MP3, AudioEncodingQuality audioEncodingQuality = AudioEncodingQuality.High)
    {
        ConvertToMp3Manager convertToMp3Manager = new ConvertToMp3Manager(sourceAudio, destinationAudio, AudioType, audioEncodingQuality);
        var success = await convertToMp3Manager.ConvertAudioAsync();
        return success;
    }
}
public enum AudioFormat
{
    MP3,
    AAC,
    M4A,
    WMA
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top