c# - 如何使用 C# 将 ffmpeg cmd 执行到命令行?
问题描述
我在尝试在 Visual Studio 19 上获取表单应用程序以在命令行上执行 cmd 以将视频从 mp4 转换为 avi 时遇到问题。我为此使用ffmpeg,但每次编译它都不会拾取任何东西。
我已经通过命令行运行了参数,它可以很好地转换视频。据我所知,路径是正确的,所以我不确定为什么编译器不会拾取任何文件。
private void Button1_Click(object sender, EventArgs e)
{
string cmdString = "c:\ffmpeg\bin";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "ffmpeg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = cmdString + $"-i shatner.mp4 shatner.avi";
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
}
}
我得到的错误:“系统找不到指定的文件”
此外,我会在 Process.Start 周围放置一个 try catch 块,但这并不重要,因为它仍在抛出异常。
解决方案
您的文件名和参数指定不正确。请看下文。
private void button1_Click(object sender, EventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "c:\\ffmpeg\\bin\\ffmpeg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-i shatner.mp4 shatner.avi";
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
using (Process exeProcess = Process.Start(startInfo))
{
string error = exeProcess.StandardError.ReadToEnd();
string output = exeProcess.StandardError.ReadToEnd();
exeProcess.WaitForExit();
MessageBox.Show("ERROR:" + error);
MessageBox.Show("OUTPUT:" + error);
}
}
推荐阅读
- r-markdown - 在 noweb 或 Rmarkdown 等 Literate Programming 工具中,代码块的执行顺序是如何确定的?
- python - 如何在python中杀死一个子进程
- html - 阴影与盒子阴影?
- javascript - Jquery 单击不适用于自定义光标(鼠标后的 div)
- html - 溢出隐藏在弹性孩子的孩子身上
- javascript - 黑客是否可以从 iframe 外部检查保存到“window”的 javascript 对象?
- repast-simphony - Repast:如何根据多个条件获取特定的代理集?
- rest - 我可以使用 REST 进行除 CRUD 之外的任何其他操作,例如 BI 功能吗?
- javascript - Android youtube 播放器无法正常工作
- ios - 在自定义 UITableViewCell 中有多个按钮