使用(ffmpeg)来执行C#.NET项目中 [英] Use (ffmpeg) executable inside C#.NET project

查看:1311
本文介绍了使用(ffmpeg)来执行C#.NET项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写在ffmpeg的C#.NET自定义包装。我下载了多个版本,但它似乎像我将不得不使用一个与.exe文件。

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?

感谢您在您的帮助。

推荐答案

好吧,我想通了。对于任何人都希望写一个ffmpeg的.NET包装。下载共享版本。的bin文件夹(与可执行文件)的内容添加到您的项目。如果这样做右击你的解决方案 - >添加新项...

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.

您可以拥有的ffmpeg,ffprobe等。在JSON或XML输出。所以你可以解析输出,做任何

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.

这篇关于使用(ffmpeg)来执行C#.NET项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆