1

I am having an issuing trying to get a form app on visual studio 19 to execute a cmd on command line for converting a video from mp4 to avi. I am using ffmpeg for this but everytime I compile it wont pick anything up.

I have ran the argument through command line and it converts the video just fine. The path as far as I am aware is correct so I am not sure why the compiler wont pick up on any files.

private void Button1_Click(object sender, EventArgs e)
    {
        string cmdString =  "c:\ffmpeg\bin";
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.CreateNoWindow = false;
        startInfo.UseShellExecute = false;
        startInfo.FileName = "ffmpeg.exe";
        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
        startInfo.Arguments =  cmdString + $"-i shatner.mp4 shatner.avi";


        using (Process exeProcess = Process.Start(startInfo))
        {
            exeProcess.WaitForExit();
        }
    }
}

}

The error I am getting: "The system cannot find the specified file"

Also I would have put a try catch block around the Process.Start but it doesnt matter since it is still throwing the exception.

2
  • Check the current directory. Commented Jun 20, 2019 at 20:11
  • 4
    Your Arguments don't make sense with cmdString. Commented Jun 20, 2019 at 20:12

1 Answer 1

2

Your fileName and arguments are specified incorrectly. Please see below.

private void button1_Click(object sender, EventArgs e)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.CreateNoWindow = false;
            startInfo.UseShellExecute = false;
            startInfo.FileName = "c:\\ffmpeg\\bin\\ffmpeg.exe";
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.Arguments = "-i shatner.mp4 shatner.avi";

            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;       


            using (Process exeProcess = Process.Start(startInfo))
            {
                string error = exeProcess.StandardError.ReadToEnd();
                string output = exeProcess.StandardError.ReadToEnd();
                exeProcess.WaitForExit();

                MessageBox.Show("ERROR:" + error);
                MessageBox.Show("OUTPUT:" + error);
            }
        }
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the feedback. I have tried that also. It gives me a different outcome but not the one I expect. I simply click on the form button and nothing happens. Would you happen to know why it would do that?
It should work. May be you are running into some exception. Try the edited code to see what is happening. This should give you the output or error you are running into.
Again thanks for the help, I finally got it to work. I was running a form application but in order for it to keep the command prompt open and run the application, I had to change the output type in project manager to console application. That seemed to do the trick as it is work fine now. Thanks again!

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.