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. **/ // System.Diagnostics.Debugger.Launch(); 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; System.Text.StringBuilder sbOutPut = new System.Text.StringBuilder(); try { using (Process proc = System.Diagnostics.Process.Start(oInfo)) { using (StreamReader srOutput = proc.StandardError) { System.Text.StringBuilder output = new System.Text.StringBuilder(); using (StreamReader objStreamReader = proc.StandardError) { //System.Text.StringBuilder sbOutPut = new System.Text.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(); } } } } catch (Exception ex) { return ex.Message.ToString(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)