using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web;
using XHCity_Pub.BLL;dom
namespace XHCity_Pub
{
public class videoThumbs
{
public videoThumbs()
{
}ide
#region
/// <summary>
/// 獲取視頻文件的完整目錄
/// </summary>
/// <param name="fileName">要獲取截圖的視頻文件據對路徑</param>
/// <returns>返回保存圖片文件的絕對路徑</returns>
public static string CatchImg(string fileName)
{
LogBLL bll = new LogBLL();
fileName = fileName.Replace("\\/", "\\");
string sizeOfImg = "300x170";
string ffmpeg = PathHelperAsp.BaseDirectory + "ffmpeg/ffmpeg.exe";
string flv_img = fileName + "_Thumbs.jpg";
int sMax = 15;
try
{
bll.Log("跟蹤日誌", "進入截圖函數", "開始執行截圖", ffmpeg + " ;" + fileName);
System.Diagnostics.ProcessStartInfo ImgstartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
ImgstartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;函數
FormatConverter videoHelp = new FormatConverter();
string length = videoHelp.GetVideoDuration(ffmpeg, fileName);
if(length.IsNotNullOrEmpty())
{
sMax = ConvertTimeToSecond(length);
}
int ss = RandomHelper.Number(2, sMax, true);
ImgstartInfo.Arguments = " -i " + fileName + " -y -f image2 -ss " + ss + " -vframes 1 -s " + sizeOfImg + " " + flv_img;
bll.Log("跟蹤日誌", "截圖進行中", "參數爲", ImgstartInfo.Arguments);
System.Diagnostics.Process.Start(ImgstartInfo);
}
catch (Exception ex)
{
bll.Log("錯誤日誌", "視頻截圖出錯", ex.ToString(), ex.ToString());
throw new Exception("獲取視頻文件截圖報錯:ffmpeg.exe:{0},fileName:{1},flv_Img:{2}".FormatWith(ffmpeg, fileName, flv_img), ex);
}
return flv_img;
}spa
/// <summary>
/// 將時間格式(00:00:00)轉換爲秒
/// </summary>
/// <param name="time"> 時間格式字符串</param>
/// <returns> 秒數</returns>
public static int ConvertTimeToSecond(string time)
{
string[] str = time.Split(':');
int h = 0;
int m = 0;
int s = 0;
if (!int.TryParse(str[0], out h))
{
}
if (!int.TryParse(str[1], out m))
{
}
if (!int.TryParse(str[2], out s))
{
}
h = h * 3600;
m = m * 60;
s = h + m + s;
return s;
}
#endregion
}日誌
}
orm