#region 从视频画面中截取一帧画面为图片
/// <summary>
/// 从视频画面中截取一帧画面为图片
/// </summary>
/// <param name="VideoName">视频文件,绝对路径</param>
/// <param name="WidthAndHeight">图片的尺寸如:240*180</param>
/// <param name="CutTimeFrame">开始截取的时间如:"1"</param>
/// <returns></returns>
public string GetPicFromVideo(string VideoName, string WidthAndHeight, string CutTimeFrame)
{
string ffmpeg = Server.MapPath("/") + "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
+ " -y -f image2 -ss " + CutTimeFrame
+ " -t 0.001 -s " + WidthAndHeight
+ " " + PicName; //設定程式執行參數
try
{
System.Diagnostics.Process.Start(startInfo);
Thread.Sleep();//线程挂起,等待ffmpeg截图完毕
}
catch (Exception)
{
return "";
} //返回视频图片完整路径
if (System.IO.File.Exists(PicName))
return PicName;
return "";
}
#endregion