C# 调用外部ffmpeg.exe,稳定运行一段时间以后,突然出现无法转换的情况,有ErrorDataReceived运行日志,但是没有转换后的mp4视频

C# 调用外部ffmpeg.exe转换avi成mp4
代码如下:

 Process p = new Process();
                        try
                        {
                            p.StartInfo.FileName = Application.StartupPath + "\\" + "ffmpeg.exe";
                            p.StartInfo.UseShellExecute = false;
                            p.StartInfo.Arguments = "-i " + item.FilePath + " -y -vcodec h264 -threads 6 -crf 25 " + VideoName + videoAfterFormat + "\"";   //执行参数
                            p.StartInfo.CreateNoWindow = true;  //不显示dos程序窗口
                            p.StartInfo.RedirectStandardInput = true;
                            p.StartInfo.RedirectStandardOutput = true;
                            p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中
                            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                            p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
                            p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);

                            DateTime beginTime = DateTime.Now;
                            p.Start();
                            p.BeginErrorReadLine();   // 开始异步读取                         
                            p.WaitForExit();//阻塞等待进程结束
                        }
                        catch (Exception ex)
                        {
                            Common.Common.WriteMsgError("MpegFormatVideo :Process!视频主键:" + item.WetVId + " 详情:" + ex.Message);
                        }
                        finally
                        {
                            p.Close();//关闭进程
                            p.Dispose();//释放资源
                        }

  private static void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    Common.WriteMsgError("MpegFormatVideo :p_ErrorDataReceived--信息:" + e.Data);
                }
            }
            catch (Exception ex)
            {
                Common.WriteMsgError("p_ErrorDataReceived!异常:" + ex.Data);
            }
        }

        private static void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
              Common.WriteMsg("MpegFormatVideo :视频转换完成!文件:" + e.);
        }

几天或者十几天后就会出现不再转换的情况,没有报错。有p_OutputDataReceived的日志,日志里面正确的和目前不转的日志,ffmpeg的运行轨迹几乎是一样的,但是现在就是不出现mp4文件。

奇怪的是:
1.主程序没有卡死。
2.子线程也依然在运行程序没有出现假死,后续的新视频依然每次都在执行,并且有ffmpeg的执行日志输出。
3.出现问题的时候任务管理器也没有ffmpeg.exe的残留。
4.所有后续的新视频文件就无法正常转换,有执行日志过程,没有生成mp4。
5.重启下主程序,就又好了。
6.windows系统日志也没有任何有关的信息。

哪位兄弟有没有类似的情况,可以帮忙解答。

1 ffmepg.exe 运行的异常是否会向上抛出给到你的托管代码,如何实现这一步是关系,才能对症下药?
2 根据你的情况分析,ffmepg.exe 运行过程必定存在了异常,但是没办法捕获到日志记录。try..catch 只能捕捉到托管代码的异常。
3 可以尝试在运行ffmepg.exe的方法上面加上,捕获非托管代码的修饰符,看看能不能抓取到异常日志。