【发布时间】:2018-10-23 12:22:11
【问题描述】:
我相信我的“FFmpeg”进程陷入了无限循环,或者它正在等待某些东西,我不知道那是什么。它不会通过WaitForExit 方法。
FFmpeg:
-ss 0 -i output.mp4 -t 10 -an -y test.mp4
C#代码:
using (Process process = new Process())
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.FileName = FileName; // ffmpeg.exe
process.StartInfo.Arguments = Arguments; //-ss 0 -i output.mp4 -t 10 -an -y test.mp4
process.Start();
process.WaitForExit(); // stops here and waits
return process.StandardOutput.ReadToEnd();
}
编辑:
将-loglevel quiet 添加到我的ffmpeg 查询使我的问题消失了。为什么?如何在不添加 -loglevel quiet 的情况下获得相同的结果?
【问题讨论】:
-
您是否尝试在终端中使用此参数调用“ffmpeg.exe”以查看可执行文件是否真的退出?
-
@Leonardo Menezes 做到了。在
cmd中工作正常,但是当我在Process中使用它时,它会停止并等待。 -
尝试将文件名设置为您的 powershell,例如:“%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe”并将参数设置为“-ExecutionPolicy Bypass -Command”ffmpeg.exe -ss 0 -i output.mp4 -t 10 -an -y test.mp4" " 看看它的表现如何。
-
@Leonardo Menezes 得到:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll Additional information: Access is denied -
好的,现在我们有两个选择:您的 c# 代码无权访问 powershell 或您的 powershell 无权访问 ffmpeg.exe。也许这个问题与您的原始问题有关,该错误可能是您永无止境的过程的原因。我建议进行一些调试,尝试为您的 Visual Studio 授予管理员权限。