日期:2014-05-17  浏览次数:20480 次

生成视频缩略图
网上搜了下,用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("~/"), "