Use (ffmpeg) executable inside C#.NET project

2019-04-16 04:47发布

I am trying to write a custom wrapper in c#.NET for ffmpeg. I downloaded multiple versions, but it seems like I am going to have to use the one with .exe files.

ffmpeg.exe
ffplay.exe
ffprobe.exe

However, I'm unable to reference these executables by going to add reference -> browse etc..

So what I'm trying to do now is just to add them as a file. And then run commands on them just like you would using the command line.

Is that possible? Or maybe someone has a better idea?

Thank you in advance for the help.

1条回答
The star\"
2楼-- · 2019-04-16 05:17

Ok, I figured it out. For anyone else looking to write a .NET wrapper for ffmpeg. Download the 'shared' version. Add the contents of the 'bin' folder (with the executables) to your project. Just by doing right click your solution -> add new item...

Then you can use the executable as follows.

You can have ffmpeg, ffprobe etc.. output in json or xml. So you can parse the output and do whatever.

ProcessStartInfo startInfo = new ProcessStartInfo();

        startInfo.CreateNoWindow = false;
        startInfo.UseShellExecute = false;
        startInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ffmpeg\\ffmpeg.exe");
        startInfo.Arguments = "-f dshow -i video=\"Front Camera\"";
        startInfo.RedirectStandardOutput = true;
        //startInfo.RedirectStandardError = true;

        Console.WriteLine(string.Format(
            "Executing \"{0}\" with arguments \"{1}\".\r\n", 
            startInfo.FileName, 
            startInfo.Arguments));

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

Happy coding.

查看更多
登录 后发表回答