c# 处理参数和缺少输出

标签 c# process ffmpeg ffprobe

我正在使用 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/

相关文章:

c# - 将 FileInfo 数组转换为字符串数组 C#

c# - 从 MSBuild 命令行或项目文件将/highentropyva- 传递给 CSC 编译器

C# - 使用最小化的记事本打开文本文件?

php exec 命令在 ubuntu 上使用 ffmpeg 和 x264 工具将视频编码为 h.264 mp4 文件

FFmpeg 无法在过滤器支持的格式之间进行转换

c# - 为什么 DataContext 无法继承构造为附加属性的对象?

c# - 如何使用 C# 更改打印机的端口名称

C#进程线程无法写入输出

c# - window CE。如何按名称杀死进程?

python - 如何将实时视频帧从 ffmpeg 传输到 PIL?