1. 程式人生 > 實用技巧 >ffmpeg視訊轉碼

ffmpeg視訊轉碼

   
string path = AppDomain.CurrentDomain.BaseDirectory;
List<VideoModel> list = new List<VideoModel>();
List<VideoResultModel> VideoResultList = new List<VideoResultModel>();
string FFIP = ConfigurationManager.AppSettings["FFIP"].ToString();
string FFport = ConfigurationManager.AppSettings["FFport"].ToString();
private string Test1(VideoModel model) { try { Process p = new Process(); p.StartInfo.FileName = path + "ffmpeg.exe"; p.StartInfo.UseShellExecute = false; //string srcFileName = ""; //string destFileName = ""; //srcFileName = "D:\\" + "1.dav"; //destFileName = "D:\\" + "2.mp4"; p.StartInfo.Arguments = "-i " + model.OldVideo + " -y -vcodec h264 -b 500000 " + model.NewVideo; //執行引數 p.StartInfo.UseShellExecute = false; ////不使用系統外殼程式啟動程序 p.StartInfo.CreateNoWindow = true; //不顯示dos程式視窗 p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true;//把外部程式錯誤輸出寫到StandardError流中 // p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived); // p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived); p.StartInfo.UseShellExecute = false; p.Start(); // p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.BeginErrorReadLine();//開始非同步讀取 p.WaitForExit();//阻塞等待程序結束 p.Close();//關閉程序 p.Dispose();//釋放資源 return ""; } catch (Exception ex) { RBILogs.WriteLog("error", ex.ToString()); return ex.ToString(); } }