protected void Button1_Click(object sender, EventArgs e) { string strfrom = "avi/ab.avi"; string strnew = "flv/ab.flv"; string widthandheight = "480x360"; VideoConvertFlv(strfrom, strnew, widthandheight); Response.Write("ok"); } /// <summary> /// 视频(avi,mov等等格式)转换为flv格式视频 /// </summary> /// <param name="FromName">被转换的视频文件</param> /// <param name="ExportName">转换flv后的文件名</param> /// <param name="WidthAndHeight">视频大小的尺寸</param> /// <returns></returns> public string VideoConvertFlv(string FromName, string ExportName, string WidthAndHeight) { string ffmpeg = Server.MapPath("ffmpeg/ffmpeg.exe"); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.Arguments = " -i " + Server.MapPath(FromName) + " -ab 56 -ar 22050 -b 500 -r 15 -s " + WidthAndHeight + " " + Server.MapPath(ExportName); try { System.Diagnostics.Process.Start(startInfo); GetPicFromVideo(ExportName, "240*180", "1"); return ExportName; } catch (Exception err) { return err.Message; } } /// <summary> /// 从视频画面中截取一帧画面为图片 /// </summary> /// <param name="VideoName">videoFile文件</param> /// <param name="WidthAndHeight">图片的尺寸如:240*180</param> /// <param name="CutTimeFrame">开始截取的时间如:"1"</</param> /// <returns></returns> public string GetPicFromVideo(string VideoName, string WidthAndHeight, string CutTimeFrame) { string ffmpeg = Server.MapPath("ffmpeg/ffmpeg.exe"); string PicName = Server.MapPath(Guid.NewGuid().ToString().Replace("-", "") + ".jpg"); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.Arguments = " -i " + Server.MapPath(VideoName) + " -y -f image2 -ss " + CutTimeFrame + " -t 0.001 -s " + WidthAndHeight + " " + PicName; try { System.Diagnostics.Process.Start(startInfo); return PicName; } catch (Exception err) { return err.Message; } }
C#转换flv代码
最新推荐文章于 2019-09-06 21:13:53 发布