目前我需要将MP4视频转换为WebM和Ogg格式。为了将MP4转换为WebM,我使用了“ffmpeg.exe”。我正在运行以下代码来将视频MP4转换为WebM。
[DllImport("User32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
public void mciConvertWavMP3(string fileName, bool waitFlag)
{
string savepath = Server.MapPath(fileName);
string destpath = Server.MapPath(fileName);
string pworkingDir = Server.MapPath("~/ffmpeg/");
// string outfile = "-b:a 16 --resample 24 -m j " + savepath + " " + savepath.Replace(".wav", ".mp3") + ""; //--- lame code
// string outfile = "-b 192k -i " + savepath + " " + destpath.Replace(".mp4", ".webm");
// string outfile = "ffmpeg -i " + savepath + " -acodec libvorbis -ac 2 -ab 96k -ar 44100 -b 345k -s 640x360 " + Server.MapPath("output-file.webm");
string outfile = "ffmpeg -i \"test7.mp4\" -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis \"" + Server.MapPath("output-file.webm") + "\"";
// string outfile = "ffmpeg -i \""+fileName+"\" -codec:v libvpx -quality good -cpu-used 0 -b:v 600k -qmin 10 -qmax 42 -maxrate 500k -bufsize 1000k -threads 2 -vf scale=-1:480 -an -pass 1 -f webm /dev/null";
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = pworkingDir+"ffmpeg.exe";
psi.Arguments = outfile;
psi.UseShellExecute = true;
psi.CreateNoWindow = false;
System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
Thread.Sleep(1000);// utput.webm
if (waitFlag)
{
p.WaitForExit();
// wait for exit of called application
}
}
我将我的项目文件夹放在D:/盘中。
当我在命令提示符下运行时,一切正常。但是当我运行这段代码时,它就不正常了。
我得到的正式错误如下:
"无法找到合适的'ffmpeg'输出格式"等类似的错误。所以请有人帮忙解决这个问题。
谢谢和问候