0

I try to get output from ffmpeg process but cant get output. In another processes and commands it works correctly but output returns immideately when start!

        using (var process = new Process())
        {
            process.StartInfo = new ProcessStartInfo()
            {
                FileName = LinkHelper.IPFS_PATH,
                Arguments = cmd,
                UseShellExecute = false,
                CreateNoWindow = true,
                RedirectStandardOutput = true
            };

            process.ErrorDataReceived += FfmpegErrorRecieved;
            process.Start();

            using (StreamReader reader = process.StandardOutput)
            {
                string output = await reader.ReadToEndAsync();
                Console.WriteLine(output);
            }               
            process.WaitForExit();
        }

Before output handle!

Update: As szatmary said ffmpeg use output error instead standard output, so when you initialize process.StandartInfo don't forget initialize property "RedirectStandardError" to TRUE!

Here is correct code:

private async Task DetectFFmpegCamerasAsync()
    {
        var cmd = "-list_devices true -f dshow -i dummy";
        using (var process = new Process())
        {
            process.StartInfo = new ProcessStartInfo()
            {
                FileName = LinkHelper.FFMPEG_PATH,
                Arguments = cmd,
                UseShellExecute = false,
                CreateNoWindow = true,
                RedirectStandardError = true
            };

            process.Start();

            using (StreamReader reader = process.StandardError)
            {
                string output = await reader.ReadToEndAsync();
                Console.WriteLine($"Camera detection output: \n {output}");
            }               
            process.WaitForExit();
        }
    }

2 Answers 2

2

ffmpeg writes its output to stderr and not stdout.
Therefore you must read from standard error instead of standard out.

So use the following lines instead:

using (StreamReader reader = process.StandardError)
{
    string output = await reader.ReadToEndAsync();
    Console.WriteLine(output);
}               
Sign up to request clarification or add additional context in comments.

2 Comments

Agree to disagree. I believe the user is smart enough to use this information to fix the issue.
Agreed. But then your answer would have been missing the appropriate code sample to show this difference. So I edited your answer. I hope that you agree with the edit.
0

After

process.Start();

Add

process.BeginOutputReadLine();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.