在我用wpf编写的代码中,我在ffmpeg中运行一些过滤器,如果我在终端(powershell或cmd提示符)中运行该命令,它将一行一行地告诉我发生了什么。
我从C代码调用这个过程,它工作得很好。我的代码存在的问题是,实际上我无法从运行的进程中获得任何输出。
我尝试了StackOverflow对ffmpeg过程的一些回答。我在代码中看到2个机会。我可以通过计时器方法修复它,或者第二次挂接事件以输出接收到的数据。
我尝试了OutputDataReceived事件,但我的代码始终无法正常工作。我尝试了计时器方法,但它仍然没有击中我的代码。请检查下面的代码
_process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = ffmpeg,
Arguments = arguments,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
},
EnableRaisingEvents = true
};
_process.OutputDataReceived += Proc_OutputDataReceived;
_process.Exited += (a, b) =>
{
System.Threading.Tasks.Task.Run(() =>
{
System.Threading.Tasks.Task.Delay(5000);
System.IO.File.Delete(newName);
});
//System.IO.File.Delete()
};
_process.Start();
_timer = new Timer();
_timer.Interval = 500;
_timer.Start();
_timer.Tick += Timer_Tick;
}
private void Timer_Tick(object sender, EventArgs e)
{
while (_process.StandardOutput.EndOfStream)
{
string line = _process.StandardOutput.ReadLine();
}
// Check the process.
}