网上搜了下,用CatchImg这个方法可以在上传视频时生成缩略图,我这届把ffmpeg.exe还有几个dll放到根目录下,但是没有生成图片,怎么回事呢
public string CatchImg(string vFileName)
{
try
{
string ffmpeg = "ffmpeg.exe";
ffmpeg =HttpContext.Current.Server.MapPath(ffmpeg);
if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(vFileName)))
{
return "";
}
string flv_img_p = System.IO.Path.ChangeExtension(vFileName, ".jpg");
string FlvImgSize = "140x110";
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.Arguments = " -i " + vFileName + " -y -f image2 -t 0.1 -s " + FlvImgSize + " " + flv_img_p;
try
{
System.Diagnostics.Process.Start(startInfo);
}
catch
{
return "";
}
System.Threading.Thread.Sleep(4000);
if (System.IO.File.Exists(flv_img_p))
{
return flv_img_p.Replace(HttpContext.Current.Server.MapPath("~/"), ""); ;
}
return "";
}
catch
{
return "";
}
}
public string CatchImg(string vFileName)
{
try
{
string ffmpeg = "ffmpeg.exe";
ffmpeg =HttpContext.Current.Server.MapPath(ffmpeg);
if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(vFileName)))
{
return "";
}
string flv_img_p = System.IO.Path.ChangeExtension(vFileName, ".jpg");
string FlvImgSize = "140x110";
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.Arguments = " -i " + vFileName + " -y -f image2 -t 0.1 -s " + FlvImgSize + " " + flv_img_p;
try
{
System.Diagnostics.Process.Start(startInfo);
}
catch
{
return "";
}
System.Threading.Thread.Sleep(4000);
if (System.IO.File.Exists(flv_img_p))
{
return flv_img_p.Replace(HttpContext.Current.Server.MapPath("~/"), ""); ;
}
return "";
}
catch
{
return "";
}
}
{
return flv_img_p.Replace(HttpContext.Current.Server.MapPath("~/"), ""); ;
}有问题
{
return flv_img_p.Replace(HttpContext.Current.Server.MapPath("~/"), ""); ;
}
也不行的
string arg =" -itsoffset -"+offset+" -i " + videoPath +" -vcodec mjpeg -vframes 1 -an -y -f rawvideo -s 480x360 " +vrootPath +lpname;
其中 offset 要生成图片的视频的秒数,videopath是视频路径,vrootPath是图片保存根目录,lpname是图片文件名,我生成缩略图大小是固定的,所以将图片分辨率写死为480x360。详细参数信息请参考ffmpeg文档=======================
http://www.webdiyer.com