一、下載ffmpeg.exe。app
二、將ffmpeg.exe放在某個目錄下 eg:D:\\開發工具\\ffmpeg\\ffmpeg.exe。ide
三、app.config配置一個key=Vrffmpeg,value="D:\\開發工具\\ffmpeg\\ffmpeg.exe"。工具
四、調用下面代碼便可。開發工具
public static compressVideo(string filePath){code
string file_name = filePath;
//ffmpeg.exe -s 176*144 -i test.yuv -vcodec mpeg4 -qscale 0.1~255 test.mp4
string command_line = " -s 176*144 -i " + file_name + " -vcodec mpeg4 -qscale 0.1~255 " + file_name.Replace(".avi", "") + ".mp4";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.WorkingDirectory = ConfigurationManager.AppSettings["VrBodyDataPath"];
proc.StartInfo.UseShellExecute = false; //use false if you want to hide the window
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = ConfigurationManager.AppSettings["Vrffmpeg"];
proc.StartInfo.Arguments = command_line;
proc.Start();
proc.WaitForExit();
proc.Close();視頻
//附加,根據實際狀況開發
// 刪除原始avi文件
FileInfo file = new FileInfo(filePath);
if (file.Exists)
{
try
{
file.Delete(); //刪除單個文件
}
catch (Exception e)
{
// Common.writeLog("刪除視頻文件「" + file_name + "」出錯!" + e.Message);
}
}string
}it