2010-10-07 78 views
1

我有下面的方法來編碼上傳到網站與ffmpeg的視頻。它適用於8-9 MB的視頻,但如果視頻尺寸大於8-9 MB,它會掛起網站。唯一的方法來恢復它是重新啓動iis。asp.net ffmpeg視頻編碼掛起

當我觀察過程中,我可以看到ffmpeg編碼視頻並退出。結果視頻就好了。一旦ffmpeg存在,問題就會開始。

應用程序運行在WIN2003 86 web服務器IIS6

任何人有使用的ffmpeg從asp.net web應用程序編碼大型文件的經驗?

public EncodedVideo EncodeVideo(VideoFile input, string encodingCommand, string outputFile) 
    { 
     EncodedVideo encoded = new EncodedVideo(); 
     Params = string.Format("-i \"{0}\" {1} \"{2}\"", input.Path, encodingCommand, outputFile); 
     //string output = RunProcess(Params); 
     string output = RunProcessLargeFile(Params); 
     encoded.EncodingLog = output; 
     encoded.EncodedVideoPath = outputFile; 

     if (File.Exists(outputFile)) 
     { 
      encoded.Success = true; 
     } 
     else 
     { 
      encoded.Success = false; 
     } 
     //System.Web.HttpContext.Current.Response.Write(Params); 
     return encoded; 

    } 

private string RunProcessLargeFile(string Parameters) 
    { 
     /* The below will be the right solution .... 
     * The while loop which reads the stream is very improtant 
     * for FFMPEG as .NET does not provide more memory to FFMPEG. 
     * When converting large files, FFMPEG's out put stream gets filled... 
     * And waits for .NET to allocate memory resources but is never done. 
     * In order to utilize less memory, we are clearing the buffer periodically. 
     **/ 

     ProcessStartInfo oInfo = new ProcessStartInfo(this.FFmpegPath, Parameters); 
     oInfo.WorkingDirectory = Path.GetDirectoryName(this.FFmpegPath); 
     oInfo.UseShellExecute = false; 
     oInfo.CreateNoWindow = true; 
     oInfo.RedirectStandardOutput = true; 
     oInfo.RedirectStandardError = true; 
     Process proc = System.Diagnostics.Process.Start(oInfo); 
     StreamReader srOutput = proc.StandardError; 
     System.Text.StringBuilder output = new System.Text.StringBuilder(); 

     StreamReader objStreamReader = proc.StandardError; 
     System.Text.StringBuilder sbOutPut = new StringBuilder(); 

     while (!proc.WaitForExit(1000)) 
     { 
      sbOutPut.Append(objStreamReader.ReadToEnd().ToString()); 
     } 

     if (proc.ExitCode == 0) 
     { 
      proc.Close(); 
      if (objStreamReader != null) 
      { 
       objStreamReader.Close(); 
      } 
     } 
     else 
     { 
      proc.Close(); 
      if (objStreamReader != null) objStreamReader.Close(); 
     } 

     return sbOutPut.ToString(); 
    } 

回答

0

我不是一個asp.net的人,我用PHP和在php.ini工作這是一個配置文件,我可以設置兆字節的最高金額,我能夠上傳。也許如果你檢查配置文件來查看有關上傳的任何信息並將其設置爲最大值。

+1

這與上傳無關 – nLL 2010-10-13 16:36:59

2

聞起來就像一個典型的死鎖。

您在proc.StandardError.ReadToEnd方法之前調用proc.WaitForExit並且它似乎導致死鎖。

MSDN參考:可導致

死鎖狀態,如果 父進程StandardOutput.ReadToEnd前調用WaitForExit 和 子進程寫入足夠多的文本 填補了重定向數據流。父進程 將無限期地等待 以使子進程退出。 子進程將無限期等待 ,父進程將從完整的 StandardOutput流中讀取。

所以免去您while週期:

string output = objStreamReader.ReadToEnd(); 
proc.WaitForExit(); 

應該解決您的問題。