各位帮忙看下我用的是ffmpeg.exe插件做的FLV视频转换。现在视频是可以上传到服务器。但是我想从已上传到服务器的视频中截取一张图片怎么做啊???最后一个方法是截图片的。各位帮着看一下有什么问题。在线等protected void Button1_Click(object sender, EventArgs e)
{
string strFile="";
if (IsPostBack)
{
if (FileUpload1.HasFile)
{
strFile = FileUpload1.PostedFile.FileName;
string videoname = Guid.NewGuid().ToString();
string imgnanme=Guid.NewGuid().ToString();
string type = strFile.Substring(strFile.LastIndexOf("."));
string path = Server.MapPath("Teacher_video/"); FileUpload1.SaveAs("" + path + "" + videoname + ".flv");
strFile = "" + path + "" + videoname + ".flv";
VideoConvertFlv(strFile, "480*360", "" + videoname + ".flv"); strFile = HttpContext.Current.Server.MapPath("~/js/imgnanme.jpg");
VideoConvertImg(strFile, "480*360", "" + imgnanme + ".jpg");
}
}
}
public static string VideoConvertFlv(string FromName, string WidthAndHeight, string ExportName)
{
string ffmpeg = HttpContext.Current.Server.MapPath("~/Users/js/ffmpeg.exe");
string Command = " -i " + FromName + " -y -ab 56 -ar 22050 -b 500 -r 15 -s " + WidthAndHeight + " " + ExportName; //Flv格式
//string Command = "E:\\FFmpeg\\ffmpeg.exe -i E:\\ClibDemo\\VideoPath\\admin\\a.wmv -y -ab 56 -ar 22050 -b 500 -r 15 -s 320*240 "+ ExportName;
Process p = new Process();
p.StartInfo.FileName = ffmpeg;
p.StartInfo.Arguments = Command;
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Users/js/");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
//开始执行
p.Start();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
//p.StandardInput.WriteLine(Command);
//p.StandardInput.WriteLine("Exit ");
return ExportName;
} public static string VideoConvertImg(string FromName, string WidthAndHeight, string ExportName)
{
string ffmpeg = HttpContext.Current.Server.MapPath("~/Users/js/ffmpeg.exe");
string Command = ffmpeg + " -i " + FromName + " -y -f image2 -t 0.001 -s " +WidthAndHeight + " " + ExportName;
//获取静态图
//string Command = "E:\\FFmpeg\\ffmpeg.exe -i E:\\ClibDemo\\VideoPath\\admin\\a.wmv -y -f image2 -t 0.001 -s 300*200 " + ExportName;
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
//p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath(bs.GetVideoImagePath());
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Users/js/");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
//开始执行
p.Start();
//p.StandardInput.WriteLine(Command);
//p.StandardInput.WriteLine("Exit");
return ExportName;
}
{
string strFile="";
if (IsPostBack)
{
if (FileUpload1.HasFile)
{
strFile = FileUpload1.PostedFile.FileName;
string videoname = Guid.NewGuid().ToString();
string imgnanme=Guid.NewGuid().ToString();
string type = strFile.Substring(strFile.LastIndexOf("."));
string path = Server.MapPath("Teacher_video/"); FileUpload1.SaveAs("" + path + "" + videoname + ".flv");
strFile = "" + path + "" + videoname + ".flv";
VideoConvertFlv(strFile, "480*360", "" + videoname + ".flv"); strFile = HttpContext.Current.Server.MapPath("~/js/imgnanme.jpg");
VideoConvertImg(strFile, "480*360", "" + imgnanme + ".jpg");
}
}
}
public static string VideoConvertFlv(string FromName, string WidthAndHeight, string ExportName)
{
string ffmpeg = HttpContext.Current.Server.MapPath("~/Users/js/ffmpeg.exe");
string Command = " -i " + FromName + " -y -ab 56 -ar 22050 -b 500 -r 15 -s " + WidthAndHeight + " " + ExportName; //Flv格式
//string Command = "E:\\FFmpeg\\ffmpeg.exe -i E:\\ClibDemo\\VideoPath\\admin\\a.wmv -y -ab 56 -ar 22050 -b 500 -r 15 -s 320*240 "+ ExportName;
Process p = new Process();
p.StartInfo.FileName = ffmpeg;
p.StartInfo.Arguments = Command;
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Users/js/");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
//开始执行
p.Start();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
//p.StandardInput.WriteLine(Command);
//p.StandardInput.WriteLine("Exit ");
return ExportName;
} public static string VideoConvertImg(string FromName, string WidthAndHeight, string ExportName)
{
string ffmpeg = HttpContext.Current.Server.MapPath("~/Users/js/ffmpeg.exe");
string Command = ffmpeg + " -i " + FromName + " -y -f image2 -t 0.001 -s " +WidthAndHeight + " " + ExportName;
//获取静态图
//string Command = "E:\\FFmpeg\\ffmpeg.exe -i E:\\ClibDemo\\VideoPath\\admin\\a.wmv -y -f image2 -t 0.001 -s 300*200 " + ExportName;
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
//p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath(bs.GetVideoImagePath());
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Users/js/");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
//开始执行
p.Start();
//p.StandardInput.WriteLine(Command);
//p.StandardInput.WriteLine("Exit");
return ExportName;
}
/// 抓取视频文件的图片
/// </summary>
/// <param name="fileName">视频文件名称</param>
/// <param name="imgfile">图片文件名称</param>
/// <returns></returns>
public string CatchImg(string fileName, string imgfile)
{
string ffmpeg = Server.MapPath(PublicMethod.ffmpegtool);//ffmpeg路径
string flv_img = imgfile + ".jpg";
string FlvImgSize = PublicMethod.sizeOfImg;//图片长宽,如:240x180 System.Diagnostics.ProcessStartInfo ImgstartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
ImgstartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; ImgstartInfo.Arguments = " -i " + fileName + " -y -f image2 -ss 2 -vframes 1 -s " + FlvImgSize + " " + flv_img;
try
{
//System.Threading.Thread.Sleep(1000);
Process p_img = new Process();
p_img.StartInfo = ImgstartInfo;
p_img.Start();
p_img.Close();
}
catch
{
return "";
}
//
if (System.IO.File.Exists(flv_img))
{
return flv_img;
}
return "";
}