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 :).
How Do I convert M4A to MP3 using Windows media player? Open your M4A file with Windows Media Player. Click on the Organize button at the top left, select Options. Select the Rip Music tab and click the Change button to specify the location you want to rip music to and choose MP3 as the format.
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.
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
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With