//转FLV
public static string VideoConvertFlv(string FromName, string WidthAndHeight, string ExportName)
{
string ffmpeg = HttpContext.Current.Server.MapPath("~/FLV/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;
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = ffmpeg;
p.StartInfo.Arguments = Command;
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/FLV/");
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;
}
//同时生成PIC
public static void GetImageFromVideo(string FromName, string imgName,string toolDir)
{
try
{
Process p = new Process();//建立外部调用线程
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.FileName = toolDir + @"\ffmpeg.exe";// HttpContext.Current.Server.MapPath(@"tool/ffmpeg.exe") ;//要调用外部程序的绝对路径
p.StartInfo.Arguments = @" -i " + FromName + " -y -f image2 -t 0.001 -s 150x150 " + imgName;//参数(这里就是FFMPEG的参数了)
p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN)
p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,FFMPEG的所有输出信息,都为错误输出流,用StandardOutput是捕获不到任何消息的...
p.StartInfo.CreateNoWindow = false;//不创建进程窗口
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();//启动线程
p.WaitForExit();//等待完成
p.StandardError.ReadToEnd();//开始同步读取
p.Close();//关闭进程
p.Dispose();//释放资源
}
catch (Exception err)
{
}
finally
{
}
}
string toolDir = @"D:\works\tool\";
try
{
//.flv|.wmv
System.IO.FileInfo fi = new System.IO.FileInfo(@"D:\works\.....avi");
if (fi.Exists)
{
string saveFlv = fi.FullName.Replace(fi.Extension, ".flv");
string saveImage = fi.FullName.Replace(fi.Extension, ".jpg");
VideoHelper.VideoConvertFlv(fi.FullName, saveFlv, "300x300", toolDir);
VideoHelper.GetImageFromVideo(saveFlv, saveImage, toolDir);
}
}
catch(Exception ex)
{
}