在.NET中启动时进程停止(ffmpeg)

Rhy*_*sey 6 .net c# ffmpeg process

我试图ffmpeg作为.NET中的进程(C#)启动,但在某些情况下,根据参数(具体来说,如果我省略视频参数以创建音频文件),它就会停滞不前.它启动,输出一些行,但然后停止(使用0%CPU).当父.NET进程被终止时,它会继续,如果我让它继续,ffmpeg则正确生成文件.我认为这可能是由于使用Peek()查看流,所以我只是将其简化为以下内容,其行为相同:

_process = new Process
{
    StartInfo =
    {
        UseShellExecute = false,
        RedirectStandardOutput = false,
        RedirectStandardError = true,
        FileName = "c:\\ffmpeg.exe",
        Arguments = string.Format(
    "-i {0} {1} {2} {3} -y {4}", inputPath, videoArgs, audioArgs, options, outputPath)
    }
};
_process.Start();
_process.WaitForExit();
Run Code Online (Sandbox Code Playgroud)

ffmpeg在停止之前它输出有关输入视频/音频流的信息.通过命令提示符执行命令按预期方式工作.

有谁知道是什么问题?

编辑:

只是添加,我尝试UseShellExecute = true(和RedirectStandardError = false),这是有效的.但是,我仍然需要阅读输出,所以这对我没有帮助.

Ton*_*son 6

在RedirectStandardError上读取此 MSDN

显然这有点繁琐,如果输出或错误流缓冲区被填满,可能会死锁.坐在那里等你看看它的内容......