2

i am trying to run an ffmpeg command using c# and CMD.

I am creating and then executing a .bat file to do this. The .bat seems to create correctly, but when executed within c# it does not run correctly - It cannot find the image names. However when i exit the debugger and run the .bat the debugger created manually it works fine.

The images have just been created by the debugger, could this have something to do with it?

 string command1=  "ffmpeg -r 1/5 -i " + projectPrefix + "image-%%02d.bmp -i music.mp3 -qscale:v 2 -shortest -codec:a copy " + projectPrefix + "output.flv \n ffmpeg -i "+projectPrefix+"output.flv -vcodec wmv1 -acodec adpcm_ima_wav " + projectPrefix + ".wmv";

      // Write the string to a file.
     System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Scott\desktop\"+projectPrefix+".bat");
     file.WriteLine(command1);

     file.Close();
     Thread.Sleep(10000);

     System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:\Users\Scott\desktop\" + projectPrefix + ".bat");
     psi.RedirectStandardOutput = true;
     psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
     psi.UseShellExecute = false;
     System.Diagnostics.Process listFiles;
     listFiles = System.Diagnostics.Process.Start(psi);
     System.IO.StreamReader myOutput = listFiles.StandardOutput;
     listFiles.WaitForExit(2000);
     if (listFiles.HasExited)
     {
         string output = myOutput.ReadToEnd();

     }

Thanks

1 Answer 1

2

Initialize a StartInfo for your process and pass your parameters accordingly:

Process ffmpeg = new Process();

ffmpeg.StartInfo.FileName = path + "//" + "ffmpeg.exe";
ffmpeg.StartInfo.Arguments = " -f image -i frame.jpg -vcodec mpeg4 -b 1200k test.avi";
ffmpeg.Start();

A very similar case is described here: process.start() arguments

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.