2012-05-03 146 views
0

以下代码显示错误为“StandardOut尚未重定向或进程尚未启动。”这段代码有什么问题?它需要任何更改?它总是通过捕捉异常来清除进程。ffmpeg c#asp.net视频转换错误

static void ExecuteAsync() 
      { 
       if (File.Exists("Videos/output.flv")) 
       try 
       { 
        File.Delete("Videos/output.flv"); 
       } 
       catch 
       { 
        return; 
       } 

      try 
      { 
       process = new Process(); 
       ProcessStartInfo info = new ProcessStartInfo(@"e:\ffmpeg\bin\ffmpeg.exe", "-i cars1.flv -same_quant intermediate1.mpg"); 
       info.CreateNoWindow = false; 
       info.UseShellExecute = false; 
       info.RedirectStandardError = true; 
       info.RedirectStandardOutput = true; 
       process.StartInfo = info; 
       process.EnableRaisingEvents = true; 
       process.ErrorDataReceived += new DataReceivedEventHandler(process_ErrorDataReceived); 
       process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived); 
       process.Exited += new EventHandler(process_Exited); 
       process.Start(); 
       process.BeginOutputReadLine(); 
       process.BeginErrorReadLine(); 
      } 
      catch (Exception ex) 
      { 
       if (process != null) process.Dispose(); 
      } 
     } 
     static int lineCount = 0; 
     static void process_ErrorDataReceived(object sender, DataReceivedEventArgs e) 
     { 
      Console.WriteLine("Input line: {0} ({1:m:s:fff})", lineCount++, DateTime.Now); 
      Console.WriteLine(e.Data); 
      Console.WriteLine(); 
     } 

     static void process_OutputDataReceived(object sender, DataReceivedEventArgs e) 
     { 
      Console.WriteLine("Output Data Received."); 
     } 

     static void process_Exited(object sender, EventArgs e) 
     { 
      process.Dispose(); 
      Console.WriteLine("Bye bye!"); 
     } 
    } 

回答

1

设为false:

info.RedirectStandardOutput = false; 

文件说:

要使用StandardOutput,你必须设置 的ProcessStartInfo .. :: UseShellExecute为false,并且必须设置。 ProcessStartInfo .. ::。RedirectStandardOutput为true。否则, 从StandardOutput流读取会引发异常

+0

我设置像你告诉。我删除了未定义的函数process.BeginOutputReadLine(); process.BeginErrorReadLine();现在它不会显示任何错误。但我无法找到任何转换后的文件作为输出:( –

+0

,如果它是大文件将需要一段时间..运行任务管理器,看看ffmpeg是否正在运行。 – Zaki

+0

没有老兄。它不会显示任何进程作为ffmpeg在任务管理器执行时。 –