利用ffmepg提取視頻幀實際上是利用C#調用ffmepg命令行進行處理對應的視頻,然后輸出出視頻幀
GetPicFromVideo(@"視頻文件路徑", "705x576", "1"); static public string GetPicFromVideo(string VideoName, string WidthAndHeight, string CutTimeFrame) { string ffmpeg = @"E:\ffmpeg\bin\ffmpeg.exe";//ffmpeg執行文件的路徑 string PicName = VideoName + ".jpg";//視頻圖片的名字,絕對路徑 System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.Arguments = " -i " + VideoName //視頻路徑 + " -r 1" //提取圖片的頻率 + " -y -frames 1 -f image2 -ss " + CutTimeFrame //設置開始獲取幀的視頻時間 + " -t 513 -s " + WidthAndHeight //設置圖片的分辨率 + @" 路徑\%d.jpg"; //輸出的圖片文件名,路徑前必須有空格 try { System.Diagnostics.Process.Start(startInfo); Thread.Sleep(5000);//線程掛起,等待ffmpeg截圖完畢 } catch (Exception) { return ""; }
//返回視頻圖片完整路徑 if (System.IO.File.Exists(PicName)) return PicName; return ""; }