c# Process Arguments and Missing Output

515 views Asked by At

I'm using an FFMPEG Process to gather some information on a file:

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();
}

This seems to works fine. Now I want to get just the FrameRate, and thanks to other posts, I've found that ffprobe can be used to do just that:

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();
}

This does not seem to work at all. The process starts, but does not return what I expect to be returned.

If I run the command manually, I do the following in 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

Note: -show_entries stream = r_frame_rate does not work, only -show_entries stream=r_frame_rate without the spaces.


I'm not sure how to properly go about doing this with a Process.

1

There are 1 answers

0
mychen On

I tried your argument and got the output through StandardOutput property. Please just change your code to below and try it again.

StreamReader reader = process.StandardOutput;