音频视频压缩ffmpeg

一、下载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

相关文章
相关标签/搜索