1、下载ffmpeg.exe。
2、将ffmpeg.exe放在某个目录下 eg:D:\\开发工具\\ffmpeg\\ffmpeg.exe。
3、app.config配置一个key=Vrffmpeg,value="D:\\开发工具\\ffmpeg\\ffmpeg.exe"。
4、调用下面代码即可。
public static compressVideo(string filePath){
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); } }}