近來公司項目要求實現全景相機的視頻截取,但是截取的視頻需求轉碼上傳。經過研究采用ffmpeg轉碼,奉上一個詳細介紹的博文:
主要是轉碼的操作過程,能夠實現了從相機獲取的MP4轉換成普通播放器播放的MP4格式;
1 //轉碼方法 2 private void Test1() 3 { 4 5 Process p = new Process(); 6 7 8 p.StartInfo.FileName = path +"ffmpeg.exe"; 9 10 p.StartInfo.UseShellExecute = false; 11 string srcFileName = ""; 12 string destFileName = ""; 13 srcFileName = path + "InitVideo1.mp4"; 14 15 destFileName = path + "InitVideo.mp4"; 16 17 p.StartInfo.Arguments = "-i " + srcFileName + " -y -vcodec h264 -b 500000 " + destFileName; //執行參數 18 19 p.StartInfo.UseShellExecute = false; ////不使用系統外殼程序啟動進程 20 p.StartInfo.CreateNoWindow = true; //不顯示dos程序窗口 21 22 p.StartInfo.RedirectStandardInput = true; 23 24 p.StartInfo.RedirectStandardOutput = true; 25 26 p.StartInfo.RedirectStandardError = true;//把外部程序錯誤輸出寫到StandardError流中 27 28 p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived); 29 30 p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived); 31 32 p.StartInfo.UseShellExecute = false; 33 34 p.Start(); 35 36 p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 37 38 p.BeginErrorReadLine();//開始異步讀取 39 40 41 42 p.WaitForExit();//阻塞等待進程結束 43 44 p.Close();//關閉進程 45 46 p.Dispose();//釋放資源 47 }
附測試Demo程序:

