[英]C# app - running FFMpeg from the command line is not working
I'm trying to run FFMpeg from the Command Line in C#. 我正在尝试从C#的命令行运行FFMpeg。 Previously I was running it from "CMD.exe" and it was working, but that requires a local installation of ffmpeg with configuring my System environmental variables. 以前,我是从“ CMD.exe”运行它的,但是它正常工作,但是这需要在本地安装ffmpeg,并配置系统环境变量。 So I wanted to run it directly from "ffmpeg.exe". 因此,我想直接从“ ffmpeg.exe”运行它。 I'm using the following code (all the paths are correct), and nothing happens: 我正在使用以下代码(所有路径都是正确的),但没有任何反应:
string programToRun = "C:\\Users\\dkahn\\Documents\\PlaybackTool\\PlaybackTool\\Desktop\\Source\\Player\\Player\\ffmpeg\\ffmpeg.exe";
string directoryName = "C:\\Users\\dkahn\\Documents\\PlaybackTool\\PlaybackTool\\Desktop\\Source\\Player\\test\\test1-1.mp4";
string command = "@ffmpeg -i test1-1.mp4 -r 1 -s 180x101 test1-1\\output_%04d.png";
Process cmd = new Process();
cmd.StartInfo.FileName = programToRun;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.WorkingDirectory = directoryName;
cmd.Start();
cmd.StandardInput.WriteLine(command);
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
Does anybody have any insight? 有人有见识吗?
This is how I resolved this issue. 这就是我解决此问题的方法。
var startInfo = new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "ffmpeg.exe");
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.WorkingDirectory = path + "\\";
startInfo.Arguments = "-ss " + _startTime + " -i " + info.FullName + " -t " + _duration + " -map 0 -c copy -c:a copy " + "sample" + GetExtension(info);//-acodec
var processn = Process.Start(startInfo);
processn.EnableRaisingEvents = true;
processn.WaitForExit();
where path is your directory and info is your file to process. 其中path是您的目录,info是您要处理的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.