2012-05-03 114 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在任務管理器執行時。 –