我正在尝试在用户提交表单时转换视频。它似乎可以正常转换,但是当我尝试对其进行任何操作时,该文件“正在被另一个进程使用”。看起来 ffmpeg.exe 永远不会退出。我的代码在下面,我应该做些什么不同的事情来允许进程释放文件?如果我手动运行它,它退出正常。
internal class ConversionUtility : Utility
{
public void Convert(string videoFileName)
{
var video = new VideoFile(videoFileName);
if (!video.infoGathered)
GetVideoInfo(video);
var Params = string.Format("-y -i \"{0}\" -coder ac -me_method full -me_range 16 -subq 5 -sc_threshold 40 -vcodec libx264 -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -g 250 -r 20 \"{1}\"", video.Path, Path.ChangeExtension(videoFileName,".mp4"));
//var Params = string.Format("-y -i \"{0}\" -acodec libfaac -ar 44100 -ab 96k -coder ac -me_method full -me_range 16 -subq 5 -sc_threshold 40 -vcodec …Run Code Online (Sandbox Code Playgroud) 如何在C#代码中检查进程是否执行成功?下面是我用来检查的代码。检查p.ExitCode = 0是否成功执行就足够了吗?如果是这样,那么如果我收到任何错误(即),如何获取错误的描述ExitCode <> 0?
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", "/c " + command);
psi.RedirectStandardOutput = false;
psi.RedirectStandardError = false;
psi.UseShellExecute = true;
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process p = new Process();
p.StartInfo = psi;
p.Start();
p.WaitForExit();
MessageBox.Show("Error Code:" + p.ExitCode);
Run Code Online (Sandbox Code Playgroud)