Click here to Skip to main content
14,244,068 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all,
i am using ffmpeg converter to convert my .wmv files to mp4 using c#. everything works fine but when we upload a large file let's say around 1 GB it took almost 3-4 hours. is there any way we can reduce this time to let's say around 1 hour. i am using below code to convert .wmv file to .mp4 file.

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();
           }

       }
Posted
Updated 20-Nov-14 19:13pm
v2
Comments
Mehdi Gholam 21-Nov-14 4:10am
   
Try using a converter that supports GPU utilization.
BillWoodruff 21-Nov-14 4:52am
   
You might get some good feedback on your code here, but for issues involving ffmpeg why not use a forum specific to that software library:

https://www.ffmpeg.org/contact.html#Forums

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100