Click here to Skip to main content
12,887,625 members (34,521 online)
Rate this:
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;
    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.

Posted 14-Dec-12 7:53am
Updated 14-Dec-12 8:46am
Sergey Alexandrovich Kryukov 14-Dec-12 14:19pm
Why, why you guys stick this pointless "CMD.EXE"?!
Rate this: bad
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;
       // Start the process with the info we specified.
       // Call WaitForExit and then the using statement will close.
       using (Process exeProcess = Process.Start(startInfo))
       // Log error.

From :[^]
Rate this: bad
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:

   "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.

Rate this: bad
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....


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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 14 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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