Ofer Gozlan
Ofer Gozlan

Reputation: 1143

ffmpeg is not recognized

The following code gives me an error in the CMD window (Visual studio 2013 - c# project): 'ffmpeg' is not recognized as an internal or external command

Process p = new Process();
        ProcessStartInfo info = new ProcessStartInfo();
        info.FileName = "cmd.exe";
        info.RedirectStandardInput = true;
        info.UseShellExecute = false;

        p.StartInfo = info;
        p.Start();

        using (StreamWriter sw = p.StandardInput)
        {
            if (sw.BaseStream.CanWrite)
            {
                sw.WriteLine("ffmpeg -i test.mp4 test.mp3");
                //    sw.WriteLine("mypassword");
                //    sw.WriteLine("use mydb;");
            }
        }

This error happens only when i run the command "ffmpeg -i test.mp4 test.mp3" from the code. the other way works - running the command straight from CMD.. any suggestions to make it work from the code?

Upvotes: 0

Views: 4505

Answers (1)

keyboardP
keyboardP

Reputation: 69372

Use the WorkingDirectory property to set where the ffmpeg executable file is.

info.WorkingDirectory = @"C:\myFFMPEGDir";

At the moment, it's trying to look into the same directory as your process for ffmpeg. It sounds like ffmpeg is not there so you need to set the path.

Alternatively, you can write the entire path in the command.

sw.WriteLine("C:\\myFFMPEGDir\\ffmpeg.exe -i test.mp4 test.mp3");

Upvotes: 2

Related Questions