Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Here is the code I am using:
C#
private string ConvertVideoFiles(string strCommandLineSwitches)
{
    Process prcExecuteFFMPEG = new Process();
    prcExecuteFFMPEG.StartInfo.FileName = @"c:\windows\system32\cmd.exe ";
    //prcExecuteFFMPEG.StartInfo.WorkingDirectory = @"C:\";
    prcExecuteFFMPEG.StartInfo.Arguments = strCommandLineSwitches;
    prcExecuteFFMPEG.StartInfo.UseShellExecute = false;
    prcExecuteFFMPEG.StartInfo.RedirectStandardOutput = true;
    prcExecuteFFMPEG.Start();
    prcExecuteFFMPEG.WaitForExit();
    string strOutput = prcExecuteFFMPEG.StandardOutput.ReadToEnd();
}

I am using System.Diagnositic at the top.

I send in the following command which I know works via the command prompts. (I got this from the text visualizer while running the program
/k "C:\Program Files\ffmpeg\bin\ffmpeg.exe" -b:10000k -r25 -an  -i concat:"C:\Video conversion\Original\Cam06[21_48_59-22_29_19].avi|C:\Video conversion\Original\Cam06[22_29_19-23_36_00].avi" "C:\Video conversion\test.avi"

Any ideas why it is not working.

I changed the arguments to /c dir *.* and I got the output back and it worked as expected but my upper code is not working.

Thanks
Posted
Updated 14-Dec-12 8:46am
v2
Comments
Sergey Alexandrovich Kryukov 14-Dec-12 14:19pm    
Why, why you guys stick this pointless "CMD.EXE"?!
--SA

You can run your executable's right away using .Net classes no need of any other utilities.

here is an eg:
C#
/// <summary>
/// Launch the legacy application with some options set.
/// </summary>
static void LaunchCommandLineApp()
{
   // For the example
   const string ex1 = "C:\\";
   const string ex2 = "C:\\Dir";

   // Use ProcessStartInfo class
   ProcessStartInfo startInfo = new ProcessStartInfo();
   startInfo.CreateNoWindow = false;
   startInfo.UseShellExecute = false;
   startInfo.FileName = "dcm2jpg.exe";
   startInfo.WindowStyle = ProcessWindowStyle.Hidden;
   startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;

   try
   {
       // Start the process with the info we specified.
       // Call WaitForExit and then the using statement will close.
       using (Process exeProcess = Process.Start(startInfo))
       {
       exeProcess.WaitForExit();
       }
   }
   catch
   {
       // Log error.
   }
}

From : http://stackoverflow.com/questions/9679375/run-an-exe-from-c-sharp-code[^]
 
Share this answer
 
First and foremost: no need for "CMD /k"! Why "CMD.EXE", not "PowerShell.EXE" or something like that? Those are just application, exactly as any other application, nothing "special" or "system" about it. You could write anything like that by yourself.

No, you need to execute ffmpeg itself and nothing else:

C#
System.Diagnostics.Process.Start(
   "ffmpeg.exe", // calculate proper path
   @"-b:10000k -r25 -an -i concat:""C:\Video conversion\Original\Cam06[21_48_59-22_29_19].avi|C:\Video conversion\Original\Cam06[22_29_19-23_36_00].avi"" ""C:\Video conversion\test.avi""");


(I'm not sure your ffmpeg syntax is correct though. Check it manually first.)

And of course, there is no cases when hard-coded path names can be useful. All path names should be calculated during runtime based on user-supplied data, configuration data, environment, etc.

—SA
 
Share this answer
 
v2
I tried using the ffmpeg.exe earlier but it did not work. I forgot to try after I got the command line working....

Thanks
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900