Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Here is the code I am using:
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 14-Dec-12 7:53am
grave23335
Edited 14-Dec-12 8:46am
v2
Comments
Sergey Alexandrovich Kryukov at 14-Dec-12 14:19pm
   
Why, why you guys stick this pointless "CMD.EXE"?! --SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
 
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
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can run your executable's right away using .Net classes no need of any other utilities.
 
here is an eg:
/// <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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I tried using the ffmpeg.exe earlier but it did not work. I forgot to try after I got the command line working....
 
Thanks
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 545
1 OriginalGriff 498
2 sanket saxena 330
3 Abhinav S 280
4 thatraja 275
0 Sergey Alexandrovich Kryukov 8,372
1 OriginalGriff 4,830
2 Peter Leow 3,784
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 14 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid