gpt4 book ai didi

c# - 使用 C# 和 ffmpeg 将 wma 流转换为 mp3 流

转载 作者:太空宇宙 更新时间:2023-11-03 13:57:13 40 4
gpt4 key购买 nike

是否可以将 wma 流实时转换为 mp3 流?

我试过做这样的事情但没有任何运气:



WebRequest request = WebRequest.Create(wmaUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
int block = 32768;
byte[] buffer = new byte[block];

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.ErrorDialog = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = "c:\\ffmpeg.exe";
p.StartInfo.Arguments = "-i - -y -vn -acodec libspeex -ac 1 -ar 16000 -f mp3 ";

StringBuilder output = new StringBuilder();

p.OutputDataReceived += (sender, e) =>
{
if (e.Data != null)
{
output.AppendLine(e.Data);
//eventually replace this with response.write code for a web request
}
};

p.Start();
StreamWriter ffmpegInput = p.StandardInput;

p.BeginOutputReadLine();

using (Stream dataStream = response.GetResponseStream())
{
int read = dataStream.Read(buffer, 0, block);

while (read > 0)
{
ffmpegInput.Write(buffer);
ffmpegInput.Flush();
read = dataStream.Read(buffer, 0, block);
}
}

ffmpegInput.Close();

var getErrors = p.StandardError.ReadToEnd();

只是想知道我正在尝试做的事情是否可行(将 wma 的字节 block 转换为 mp3 的字节 block )。开放任何其他可能的 C# 解决方案(如果存在)。

谢谢

最佳答案

您似乎想将 WMA 文件作为输入并创建 MP3 文件作为输出。此外,看起来您想通过标准输入/标准输出来执行此操作。我刚刚从命令行对此进行了测试,它似乎有效:

ffmpeg -i - -f mp3 - < in.wma > out.mp3

如果这是您的目标,那么您的命令行存在一些问题:

p.StartInfo.FileName = "c:\\ffmpeg.exe";
p.StartInfo.Arguments = "-i - -y -vn -acodec libspeex -ac 1 -ar 16000 -f mp3 ";

“-f mp3”指定 MP3 比特流容器,但“-acodec libspeex”指定 Speex 音频。我很确定你不想要这个。忽略该选项,FFmpeg 将只使用 MP3 音频作为 MP3 容器。另外,您确定要重新采样到 16000 Hz,单声道吗?因为这就是“-ac 1 -ar 16000”选项的作用。

最后一个问题:您没有提供目标。如果您想将标准输出指定为目标,您可能需要“-f mp3 -”。

关于c# - 使用 C# 和 ffmpeg 将 wma 流转换为 mp3 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11767089/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com