我正在使用 C# 创建 Windows 窗体应用程序来管理 FFMPEG 的 cmd 参数,此外,我正在使用 FileWatcher,我的应用程序只要在单击“开始观看”按钮后运行就会观察文件夹中是否有任何新文件,它的将打开 CMD.exe 并且参数将使用 FFMPEG 转换此视频文件。它可以工作,但问题是我的 C# 应用程序将命令发送到 cmd,仅此而已,但我想处理其他任务,例如 FFMPEG 是否完成任务删除原始文件?我如何在我的应用程序中确定 CMD 命令已完成,然后开始下一个任务。这是我的鳕鱼
命名空间 WindowsFormsApplication1
{
公共(public)部分类Form1:表格
{
公共(public)表格1()
{
初始化组件();
}
private void button1_Click(object sender, EventArgs e)
{
FileSystemWatcher watcher = new System.IO.FileSystemWatcher();
watcher.Path = @"MY PATH";
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Filter = "*.*";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
}
private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
{
}
private void OnChanged(object source, FileSystemEventArgs e)
{
DirectoryInfo d = new DirectoryInfo(InPath .Text );
FileInfo[] Files = d.GetFiles("*.*");
string str = "";
foreach (FileInfo file in Files)
{
str = str + file.Name;
}
var strout = Path.GetFileNameWithoutExtension(str);
string strCmdText;
strCmdText = @"/C ffmpeg.exe -i X.mp4 -Vcodec X Xout.mp4"; /// this is just argument example
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
最佳答案
这就是我用来启动一个进程然后等待它完成的结果
Process ffmpegProcess = new Process();
ffmpegProcess.StartInfo.FileName = "ffmpeg.exe";
ffmpegProcess.StartInfo.CreateNoWindow = true;
ffmpegProcess.StartInfo.Arguments = "-i X.mp4 - Vcodec X Xout.mp4";
ffmpegProcess.Start();
ffmpegProcess.WaitForExit();
if (ffmpegProcess.ExitCode != 0)
{
}
关于c# - C# 中 Cmd 命令中的 FFmpeg 完成后的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44836861/