问候,
我试图找到一个免费的 .NET 库或一个命令行可执行文件,它可以让我将 M4A 文件转换为 MP3 或 WMA 文件。请帮忙 :)。
找到了!
http://pieter.wigleven.com/it/archives/3
可能还有其他解决方案,但这对于我正在寻找的东西来说是黄金。
PS 我写了一个 .NET DLL来处理这个幕后。这是非常糟糕的代码,但它完成了工作。
如果您知道正确的工具,这很简单:
ffmpeg -i infile.m4a tmp.wav
lame tmp.wav outfile.mp3
这是一个批处理版本(抱歉,仅限 Linux/Mac):
#!/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
对于 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
}
有趣的。
您提供的链接指向命令行实用程序。
如果您真的想以编程方式执行此操作,您可能会对我在Rarewares找到的 DLL 版本感兴趣。不确定 API 描述是否附带... :-)
string fileName = @"e:\Down\test.wmv";
DsConvert.ToWma(fileName, fileName + ".wma", DsConvert.WmaProfile.Stereo128);