4

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.

Gonzalioz
  • 612
  • 2
  • 6
  • 17
  • Hey, yes, I am aware of that ffmpeg-csharp wrapper. But I want to write my own custom wrapper. – Gonzalioz Oct 27 '14 at 08:57
  • 6
    You should probably download the Dev version of the build instead, and then create a low-level wrapper in C++/CLI, which will provide managed API for your code written in C#. – galenus Oct 27 '14 at 09:31

1 Answers1

10

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.

Gonzalioz
  • 612
  • 2
  • 6
  • 17
  • 3
    That's not exactly what you'd call a wrapper, that's a program that starts the ffmpeg executable. See @galenus's comment to the question. – Rotem Oct 27 '14 at 14:15
  • Well, not yet. It is going to act as a C#.NET wrapping of FFMPEG right? Implementing multiple functions etc.. I think you can apply that terminology here. – Gonzalioz Oct 27 '14 at 14:26