一:打开管理NuGet程序包进行安装NReco.VideoConverter.dll
二:实践
/// <summary>
/// amr转化为mp3
/// </summary>
/// <param name="model"></param>
public void AmrConvertMp3(PmsProjectFilesModel model)
{
if (model.FileType == 2)
{
var filePath = Config.FilePath + "\" + model.FilePath;
var newFilePath = Config.FilePath + "\" + model.FilePath.Replace(".amr", ".mp3");
//万企链传amr,需转化为mp3
if (".amr".Equals(model.FileExt, StringComparison.OrdinalIgnoreCase))
{
//转MP3
if (File.Exists(filePath) && !File.Exists(newFilePath))
{
CommonMethod.FormatConversion(filePath, "amr", newFilePath, "mp3");
}
}
}
}
/// <summary>
/// 格式转化
/// </summary>
/// <param name="inputFile">源文件路径</param>
/// <param name="inputFormat">源文件格式</param>
/// <param name="outFile">转化后文件路径</param>
/// <param name="outFormat">转化后文件格式</param>
public static void FormatConversion(string inputFile, string inputFormat, string outFile, string outFormat, int audioSampleRate = 44100)
{
try
{
new FFMpegConverter().ConvertMedia(inputFile, inputFormat, outFile, outFormat, new ConvertSettings { AudioSampleRate = audioSampleRate });
}
catch (Exception ex)
{
throw ex;
// ignored
}
}