(轉載請刪除括號里的內容)
一、常用視頻格式分辨率
- 640x480p
- 720p格式,分辨率為1280×720p / 60Hz,行頻為45kHz
- 1080p格式,分辨率為1920×1080逐行掃描,專業格式
二、FFmpeg部分參數說明:
//參數說明 /* * -i filename(input) 源文件目錄 * -y 輸出新文件,是否強制覆蓋已有文件 * -c 指定編碼器 * -fs limit_size(outinput) 設置文件大小的限制,以字節表示的。沒有進一步的字節塊被寫入后,超過極限。輸出文件的大小略大於所請求的文件大小。 * -s 視頻比例 4:3 320x240/640x480/800x600 16:9 1280x720 ,默認值 'wxh',和原視頻大小相同 * -vframes number(output) 將視頻幀的數量設置為輸出。別名:-frames:v * -dframes number (output) 將數據幀的數量設置為輸出.別名:-frames:d * -frames[:stream_specifier] framecount (output,per-stream) 停止寫入流之后幀數幀。 * -bsf[:stream_specifier] bitstream_filters (output,per-stream) 指定輸出文件流格式, 例如輸出h264編碼的MP4文件:ffmpeg -i h264.mp4 -c:v copy -bsf:v h264_mp4toannexb -an out.h264 * -r 29.97 楨速率(可以改,確認非標准楨率會導致音畫不同步,所以只能設定為15或者29.97) * */
三、使用實例代碼:
public class Demo2 { public static string ffmpegtool = @"F:\SolutionSet\ABCSolution\VideoSolution\Demo1\bin\Debug\ffmpeg.exe"; //public static string ffmpegtool = @"F:\ABCSolution\ffmpeg-20160808-ce2217b-win64-static\bin\ffplay.exe"; public static string playFile = @"F:\SolutionSet\ABCSolution\VideoSolution\VideoSolution\Content\Video\my3.mp4"; public static string imgFile = @"F:\SolutionSet\ABCSolution\VideoSolution\VideoSolution\Content\Video\my3.gif"; public static string sourceFile = @"F:\SolutionSet\ABCSolution\VideoSolution\VideoSolution\Content\Video\COOLUI.mp4"; //public static string sourceFile = @"F:\ABCSolution\VideoSolution\VideoSolution\Content\Video\theme.mp4"; public void ConvertVideo() { Process p = new Process();//建立外部調用線程 p.StartInfo.FileName = ffmpegtool;//要調用外部程序的絕對路徑 //參數(這里就是FFMPEG的參數了) //p.StartInfo.Arguments = @"-i "+sourceFile+ " -ab 56 -b a -ar 44100 -b 500 -r 29.97 -s 1280x720 -y " + playFile+""; // p.StartInfo.Arguments = "-y -i \""+sourceFile+"\" -b v -s 800x600 -r 29.97 -b 1500 -acodec aac -ac 2 -ar 24000 -ab 128 -vol 200 -f psp \""+playFile+"\" "; //string strArg = "-i " + sourceFile + " -y -s 640x480 " + playFile + " "; string strArg = "-i " + sourceFile + " -y -s 1280x720 " + playFile + " "; //獲取圖片 //截取圖片jpg //string strArg = "-i " + sourceFile + " -y -f image2 -t 1 " + imgFile; //string strArg = "-i " + sourceFile + " -y -s 1280x720 -f image2 -t 1 " + imgFile; //視頻截取 //string strArg = " -i " + sourceFile + " -y -ss 0:20 -frames 100 " + playFile; //轉化gif動畫 //string strArg = "-i " + sourceFile + " -y -s 1280x720 -f gif -vframes 30 " + imgFile; //string strArg = " -i " + sourceFile + " -y -f gif -vframes 50 " + imgFile; // string strArg = " -i " + sourceFile + " -y -f gif -ss 0:20 -dframes 10 -frames 50 " + imgFile; //顯示基本信息 //string strArg = "-i " + sourceFile + " -n OUTPUT"; //播放視頻 //string strArg = "-stats -i " + sourceFile + " "; p.StartInfo.Arguments = strArg; p.StartInfo.UseShellExecute = false;//不使用操作系統外殼程序啟動線程(一定為FALSE,詳細的請看MSDN) p.StartInfo.RedirectStandardError = true;//把外部程序錯誤輸出寫到StandardError流中(這個一定要注意,FFMPEG的所有輸出信息,都為錯誤輸出流,用StandardOutput是捕獲不到任何消息的...這是我耗費了2個多月得出來的經驗...mencoder就是用standardOutput來捕獲的) p.StartInfo.CreateNoWindow = false;//不創建進程窗口 p.ErrorDataReceived += new DataReceivedEventHandler(Output);//外部程序(這里是FFMPEG)輸出流時候產生的事件,這里是把流的處理過程轉移到下面的方法中,詳細請查閱MSDN p.Start();//啟動線程 p.BeginErrorReadLine();//開始異步讀取 p.WaitForExit();//阻塞等待進程結束 p.Close();//關閉進程 p.Dispose();//釋放資源 } private void Output(object sendProcess, DataReceivedEventArgs output) { if (!String.IsNullOrEmpty(output.Data)) { //處理方法... Console.WriteLine(output.Data); ////去獲取時長 //string partitio1 = @"Duration: \d{2}:\d{2}:\d{2}.\d{2}"; //if (RegexHelper.IsMatch(partitio1, output.Data)) //{ // string partition = @"(?<=Duration: )\d{2}:\d{2}:\d{2}.\d{2}"; // string timespan = RegexHelper.Matchs(output.Data, partition).FirstOrDefault(); // TimeSpan span; // if (TimeSpan.TryParse(timespan, out span)) // { // Console.WriteLine(span.TotalMilliseconds); // } //} ////獲取時刻 //string partitio2 = @"time=\d{2}:\d{2}:\d{2}.\d{2}"; //if (RegexHelper.IsMatch(partitio2, output.Data)) //{ // string partition = @"(?<=time=)\d{2}:\d{2}:\d{2}.\d{2}"; // string timespan = RegexHelper.Matchs(output.Data, partition).FirstOrDefault(); // TimeSpan span; // if (TimeSpan.TryParse(timespan, out span)) // { // Console.WriteLine(span.TotalMilliseconds); // } //} } } }
更多參考:
---------------------
作者:天馬3798
來源:CNBLOGS
原文:https://www.cnblogs.com/tianma3798/p/6285602.html
版權聲明:本文為作者原創文章,轉載請附上博文鏈接!
內容解析By:CSDN,CNBLOG博客文章一鍵轉載插件