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