public string ChangeFileVir(string fileName,String imgFile,string Timespan)
{
string ffmpeg = Server.MapPath("~/Test/ffmpeg.exe");
if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(fileName)))
{
return "";
}
string flv_img = System.IO.Path.ChangeExtension(Server.MapPath(imgFile), ".jpg");
string FlvImgSize = "240*180";
System.Diagnostics.ProcessStartInfo ImgstartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
ImgstartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
ImgstartInfo.Arguments = " -i " + fileName + " -y -f image2 -ss "+Timespan+" -t 0.999 -s " + FlvImgSize + " " + flv_img;
try
{
System.Diagnostics.Process.Start(ImgstartInfo);
}
catch
{
return "";
}
System.Threading.Thread.Sleep(8000); //因为保存的原因,延时一定的时间后再查询图片是否存在,时间可设
if (System.IO.File.Exists(flv_img))
{
return imgFile;
}
return "";
}
本文介绍了一个使用FFmpeg工具从视频文件中截取指定时间点图片的方法,并提供了具体的.NET实现代码。该方法首先检查FFmpeg及视频文件的存在状态,然后通过ProcessStartInfo启动FFmpeg进程并设置参数,完成图片的截取。

被折叠的 条评论
为什么被折叠?



