[英]How do I set ffmpeg pipe output?
我需要将 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);
}
}
它是来自 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"
有一个错字。 如果您只想使用-i
等选项调用ffmpeg
,请省略$
字符。
只是
. 您已经在"ffmpeg -i input.mp3 pipe:1"
。
StartInfo.FileName
传递了主程序名称。 所以你也应该把它排除在外。 尝试将"-i input.mp3 pipe:1"
作为您的Arguments
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.