[英]How do I set ffmpeg pipe output?
I need to read ffmpeg output as pipe.我需要将 ffmpeg 输出读取为管道。 There is a code example:有一个代码示例:
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);
}
}
It's log from ffmpeg, the first file is readed:它是来自 ffmpeg 的日志,读取第一个文件:
Input #0, mp3, from 'norm.mp3': Metadata: encoder : Lavf58.17.103 Duration: 00:01:36.22, start: 0.023021, bitrate: 128 kb/s Stream #0:0: Audio: mp3, 48000 Hz, stereo, fltp, 128 kb/s Metadata: encoder : Lavc58.27输入 #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
Then pipe:然后管道:
[NULL @ 0x7fd58a001e00] Unable to find a suitable output format for '$' $: Invalid argument [NULL @ 0x7fd58a001e00] 无法为 '$' $ 找到合适的输出格式:无效参数
If I run "-i input.mp3 pipe:1", the log is:如果我运行“-i input.mp3 pipe:1”,日志是:
Unable to find a suitable output format for 'pipe:1' pipe:1: Invalid argument无法为“pipe:1”pipe:1 找到合适的输出格式:参数无效
How do I set correct output?如何设置正确的输出? And how should ffmpeg know what the output format is at all? ffmpeg 应该如何知道输出格式是什么?
Whenever you use a pipe out in ffmpeg, you need the -f fmt
parameter to avoid the error you are seeing.每当您在 ffmpeg 中使用管道输出时,您都需要-f fmt
参数来避免您看到的错误。
You can get a list of possible formats by typing ffmpeg -formats
.您可以通过键入ffmpeg -formats
来获取可能的格式列表。
If you want a wav file for instance, add -f wav
.例如,如果您想要一个 wav 文件,请添加-f wav
。
In your example, arguments should be:在您的示例中,参数应该是:
-i input.mp3 -f wav pipe:1
You can replace wav with flac or any other audio format you like.您可以将 wav 替换为 flac 或您喜欢的任何其他音频格式。
Looks to me like there's a typo in "$ ffmpeg -i input.mp3 pipe:1"
.在我看来, "$ ffmpeg -i input.mp3 pipe:1"
有一个错字。 If you just want to invoke ffmpeg
with options like -i
and so on, leave out the $
character.如果您只想使用-i
等选项调用ffmpeg
,请省略$
字符。
Just
"ffmpeg -i input.mp3 pipe:1"
.
只是
. . You already pass the main program name in "ffmpeg -i input.mp3 pipe:1"
。
StartInfo.FileName
.您已经在StartInfo.FileName
传递了主程序名称。 So you should probably leave that out too.所以你也应该把它排除在外。 Try just "-i input.mp3 pipe:1"
as your Arguments
.尝试将"-i input.mp3 pipe:1"
作为您的Arguments
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.