我正在使用 FFMPEG Process
收集有关文件的一些信息:
private void GatherFrames()
{
Process process = new Process();
process.StartInfo.FileName = "ffmpeg";
process.StartInfo.Arguments = "-i \"" + filePath + "\"";
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
if (!process.Start())
{
Console.WriteLine("Error starting");
return;
}
StreamReader reader = process.StandardError;
string line;
while ((line = reader.ReadLine()) != null)
{
outputRichTextBox.AppendText(line + "\n");
}
process.Close();
}
这似乎工作正常。现在我只想得到
FrameRate
, 和 thanks to other posts , 我发现 ffprobe
可以用来做到这一点:public void GetFrameRate()
{
Process process = new Process();
process.StartInfo.FileName = "ffprobe";
process.StartInfo.Arguments = "-v 0 -of compact=p=0 -select_streams 0 -show_entries stream = r_frame_rate \"" + filePath + "\"";
Console.WriteLine(process.StartInfo.Arguments);
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = false;
Console.WriteLine(process.StartInfo);
if (!process.Start())
{
Console.WriteLine("Error starting");
return;
}
StreamReader reader = process.StandardError;
string line;
while ((line = reader.ReadLine()) != null)
{
Console.WriteLine(line);
}
process.Close();
}
这似乎根本不起作用。该过程开始,但没有返回我期望返回的内容。
如果我手动运行命令,我会在
cmd.exe
中执行以下操作:> e:
> cd "FILE_PATH"
> ffprobe -v 0 -of compact=p=0 -select_streams 0 -show_entries stream=r_frame_rate "FILE_NAME.mp4"
r_frame_rate=60/1
注:
-show_entries stream = r_frame_rate
不起作用,只有 -show_entries stream=r_frame_rate
没有空格。我不确定如何使用
Process
正确执行此操作.
最佳答案
我尝试了您的论点并通过 StandardOutput
获得了输出属性(property)。
请只需将您的代码更改为下面,然后再试一次。
StreamReader reader = process.StandardOutput;
关于c# 处理参数和缺少输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46144371/