【问题标题】:Change bitrate of MP3 using .Net Core Azure Functions使用 .Net Core Azure Functions 更改 MP3 的比特率
【发布时间】:2020-12-11 05:26:24
【问题描述】:

我正在尝试使用 NAudio / NLayer.NAudioSupport 创建一个 Azure 函数,我可以在其中传入一个 URL(例如https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_1MG.mp3),读取字节,并返回以 128Kbps 转换的 mp3 文件。但是,我目前收到一个异常说明:

System.Private.CoreLib:执行函数时出现异常:ReduceMp3Bitrate。 NAudio.Lame:不支持的编码格式MpegLayer3(参数format)。

这是我当前的代码(第 5 行出现异常):

const string linkUrl = @"https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_1MG.mp3";
var audioFile = new HttpClient().GetByteArrayAsync(linkUrl);
await using var ms = new MemoryStream(await audioFile);
var audioReader = new Mp3FileReader(ms);
await using var audioWriter = new LameMP3FileWriter(@"C:\temp\test.mp3", audioReader.Mp3WaveFormat, LAMEPreset.ABR_128);
await audioReader.CopyToAsync(audioWriter);

我认为问题出在audioReader.Mp3WaveFormat,但我不确定为什么会出现问题,因为它正在返回MpegLayer3

我还尝试在 Windows 上运行的 .Net Framework 4.7 控制台应用程序上运行它(将 Azure Functions 排除在外),但仍然无法正常工作。

【问题讨论】:

    标签: c# azure azure-functions mp3 naudio


    【解决方案1】:

    将 audioReader.Mp3WaveFormat 更改为 audioReader.WaveFormat(在第 5 行)。

    说明:如https://github.com/naudio/NAudio/blob/master/NAudio/Wave/WaveStreams/Mp3FileReader.cs#L28 中所述,Mp3WaveFormat 不是 Mp3FileReader 流的输出格式。这存在于 WaveFormat 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-14
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      相关资源
      最近更新 更多