exe未能完成在处理大文件

exe未能完成在处理大文件

本文介绍了通过Windows服务运行ffmpeg.exe未能完成在处理大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的 ffmpeg.exe到视频文件转换为FLV格式。为此目的,我使用的 Windows服务在后台运行转换过程。虽然试图转换大文件(我经历过,当文件大小为> 14MB)通过的 Windows服务它被卡在该启动过程中的行(即的Process.Start();

但是,当我试图直接从命令执行ffmpeg.exe提示它与出任何问题的工作。

我的 code 窗口服务是为如下:

 私人主题的WorkerThread;
保护覆盖无效的OnStart(字串[] args)
{

   的WorkerThread =新主题(新的ThreadStart(StartHandlingVideo));
   WorkerThread.Start();
}

保护覆盖无效的onStop()
{
   WorkerThread.Abort();
}

私人无效StartHandlingVideo()
{
   FilArgs =的String.Format( - 我{0} -ar 22050 -qscale 1 {1},inputFile,请OUTPUTFILE);
   流程PROC;
   PROC =新工艺();

   尝试
   {

     proc.StartInfo.FileName = SPATH +\\ \\的ffmpeg ffmpeg.exe;
     proc.StartInfo.Arguments = FilArgs;
     proc.StartInfo.UseShellExecute = FALSE;
     proc.StartInfo.CreateNoWindow = FALSE;
     proc.StartInfo.RedirectStandardOutput =真;
     proc.StartInfo.RedirectStandardError = TRUE;

     eventLog1.WriteEntry(要开始的皈依过程);

     proc.Start();

     字符串StdOutVideo = proc.StandardOutput.ReadToEnd();
     字符串StdErrVideo = proc.StandardError.ReadToEnd();

     eventLog1.WriteEntry(皈依成功);
     eventLog1.WriteEntry(StdErrVideo);
 }
 赶上(例外前)
 {
     eventLog1.WriteEntry(皈依失败);
     eventLog1.WriteEntry(ex.ToString());
 }
 最后
 {
     proc.WaitForExit();
     proc.Close();
 }
 

如何才能摆脱这种局面。

解决方案

看来你陷入死锁,因为你执行的同步读来既重定向数据流的结束。

MSDN 参考:

  //不执行同步读来既年底
 //重定向数据流。
 //字符串输出= p.StandardOutput.ReadToEnd();
 //字符串错误= p.StandardError.ReadToEnd();
 // p.WaitForExit();
 //在液流中的至少一种使用异步读取操作。
 p.BeginOutputReadLine();
 字符串错误= p.StandardError.ReadToEnd();
 p.WaitForExit();
 

I am using ffmpeg.exe to convert video files to flv format. For that purpose i use a windows service to run the conversion process in background. While trying to convert large files(i experienced it when the file size is >14MB) through windows service it gets stuck at the line which starts the process(ie, process.start();).

But when i tried to execute ffmpeg.exe directly from command prompt it worked with out any problems.

My code in windows service is as follows:

private Thread WorkerThread;
protected override void OnStart(string[] args)
{

   WorkerThread = new Thread(new ThreadStart(StartHandlingVideo));
   WorkerThread.Start();
}

protected override void OnStop()
{
   WorkerThread.Abort();
}

private void StartHandlingVideo()
{
   FilArgs = string.Format("-i {0} -ar 22050 -qscale 1 {1}", InputFile, OutputFile);
   Process proc;
   proc = new Process();

   try
   {

     proc.StartInfo.FileName = spath + "\\ffmpeg\\ffmpeg.exe";
     proc.StartInfo.Arguments = FilArgs;
     proc.StartInfo.UseShellExecute = false;
     proc.StartInfo.CreateNoWindow = false;
     proc.StartInfo.RedirectStandardOutput = true;
     proc.StartInfo.RedirectStandardError = true;

     eventLog1.WriteEntry("Going to start process of convertion");

     proc.Start();

     string StdOutVideo = proc.StandardOutput.ReadToEnd();
     string StdErrVideo = proc.StandardError.ReadToEnd();

     eventLog1.WriteEntry("Convertion Successful");
     eventLog1.WriteEntry(StdErrVideo);
 }
 catch (Exception ex)
 {
     eventLog1.WriteEntry("Convertion Failed");
     eventLog1.WriteEntry(ex.ToString());
 }
 finally
 {
     proc.WaitForExit();
     proc.Close();
 }

How can I get rid of this situation.

解决方案

It seems you caught a deadlock because you performed a synchronous read to the end of both redirected streams.

A reference from MSDN:

 // Do not perform a synchronous read to the end of both
 // redirected streams.
 // string output = p.StandardOutput.ReadToEnd();
 // string error = p.StandardError.ReadToEnd();
 // p.WaitForExit();
 // Use asynchronous read operations on at least one of the streams.
 p.BeginOutputReadLine();
 string error = p.StandardError.ReadToEnd();
 p.WaitForExit();

这篇关于通过Windows服务运行ffmpeg.exe未能完成在处理大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 14:55