mr_*_*ond 2 c# audio ffmpeg pipe .net-core
我需要将 ffmpeg 输出读取为管道。有一个代码示例:
public static void PipeTest()
{
Process proc = new Process();
proc.StartInfo.FileName = Path.Combine(WorkingFolder, "ffmpeg");
proc.StartInfo.Arguments = String.Format("$ ffmpeg -i input.mp3 pipe:1");
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
FileStream baseStream = proc.StandardOutput.BaseStream as FileStream;
byte[] audioData;
int lastRead = 0;
using (MemoryStream ms = new MemoryStream())
{
byte[] buffer = new byte[5000];
do
{
lastRead = baseStream.Read(buffer, 0, buffer.Length);
ms.Write(buffer, 0, lastRead);
} while (lastRead > 0);
audioData = ms.ToArray();
}
using(FileStream s = new FileStream(Path.Combine(WorkingFolder, "pipe_output_01.mp3"), FileMode.Create))
{
s.Write(audioData, 0, audioData.Length);
}
}
Run Code Online (Sandbox Code Playgroud)
它是来自 ffmpeg 的日志,读取第一个文件:
输入 #0,mp3,来自“norm.mp3”:元数据:编码器:Lavf58.17.103 持续时间:00:01:36.22,开始:0.023021,比特率:128 kb/s 流 #0:0:音频:mp3,48000 Hz , 立体声, fltp, 128 kb/s 元数据: 编码器: Lavc58.27
然后管道:
[NULL @ 0x7fd58a001e00] 无法为 '$' $ 找到合适的输出格式:无效参数
如果我运行“-i input.mp3 pipe:1”,日志是:
无法为“pipe:1”pipe:1 找到合适的输出格式:参数无效
如何设置正确的输出?ffmpeg 应该如何知道输出格式是什么?
每当您在 ffmpeg 中使用管道输出时,您都需要该-f fmt参数来避免您看到的错误。
您可以通过键入 来获取可能的格式列表ffmpeg -formats。
例如,如果您想要一个 wav 文件,请添加-f wav.
在您的示例中,参数应该是:
-i input.mp3 -f wav pipe:1
您可以将 wav 替换为 flac 或您喜欢的任何其他音频格式。
在我看来好像有一个错字"$ ffmpeg -i input.mp3 pipe:1"。如果您只想ffmpeg使用诸如此类的选项进行调用-i,请省略该$字符。只是。您已经在 中传递了主程序名称"ffmpeg -i input.mp3 pipe:1"。StartInfo.FileName。所以你可能也应该把它排除在外。尝试"-i input.mp3 pipe:1"像你一样Arguments。
| 归档时间: |
|
| 查看次数: |
14635 次 |
| 最近记录: |