Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to catch devices using ffmpeg.exe. i used Process class and related ffmpeg command but no success

What I have tried:

i used following code but the output is nothing!! i think it happens because the process exited as soon as process.start() executed. how can i do that?

C#
static void Main(string[] args)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.CreateNoWindow = false;
        startInfo.UseShellExecute = false;
        startInfo.FileName = "ffmpeg.exe";
        startInfo.Arguments = "-list_devices true -f dshow -i dummy";
        startInfo.RedirectStandardOutput = false;


        try
        {
            using (Process process = Process.Start(startInfo))
            {
                while (!process.StandardOutput.EndOfStream)
                {
                    string line = process.StandardOutput.ReadLine();
                    Console.WriteLine(line);
                }

                process.WaitForExit();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        Console.ReadKey();
    }
}
Posted
Updated 26-Oct-17 2:58am

You want to "capture" the output? This should answer your question: Capturing console output from a .NET application (C#) - Stack Overflow[^]
 
Share this answer
 
Comments
hsafavi 26-Oct-17 9:09am    
no it doesn't work. process.StandardOutput.ReadToEnd() result is a empty string. i think because process exited
Graeme_Grant 26-Oct-17 9:22am    
Did you try using it the way they describe? The solution was accepted, so it should work. startInfo.RedirectStandardOutput, according to the linked solution, indicated that it needs to be set to true, not false.
hsafavi 26-Oct-17 9:51am    
I did but no success
Graeme_Grant 26-Oct-17 9:56am    
There is more than one answer on that link provided... Did you look at the solution beneath it? Solution by ShitalShah[^]
hsafavi 27-Oct-17 9:57am    
no success again
I had the same issue. I was redirecting the standard output, but FFmpeg outputs text messages to the standard error.
C#
static void Main(string[] args)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.CreateNoWindow = false;
        startInfo.UseShellExecute = false;
        startInfo.FileName = "ffmpeg.exe";
        startInfo.Arguments = "-hide_banner -list_devices true -f dshow -i dummy";
        startInfo.RedirectStandardError = true;

        try
        {
            using (Process process = Process.Start(startInfo))
            {
                while (!process.StandardError.EndOfStream)
                {
                    string line = process.StandardError.ReadLine();
                    Console.WriteLine(line);
                }

                process.WaitForExit();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        Console.ReadKey();
    }
}

Tip: use -hide_banner in ffmpeg argument and your next step will be easier :-)

I hope it helps someone.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900