有客户提出需求,问可否不预先进行视频转换,在上传的时候,系统自动进行转换。今天有时间,特GOOGLE了一把,结果出现的大多都是FFMPEG,于是就自己测试了一把,搜索好多资料都是介绍FFMPEG参数,即在命令行或LINUX下进行操作的。有些是介绍在ASP或ASP.NET下操作的,但一直不能直接运行,经过一段时间的探索,终于找到问题,现将代码即注意点记下来,为以后系统更改做准备。
1、将附件中的压缩文件全部解压,全部放到WEB根目录下(其中包括FFMPEG.EXE和其他的DLL文件)
2、在页面中添加一个BUTTON,ONClick事件内容如下:(代码如下)

Code
1 string ffmpeg = HttpContext.Current.Server.MapPath("~/ffmpeg/ffmpeg.exe");
2 string FromName = HttpContext.Current.Server.MapPath("~/testvodie/test.avi");
3 string ExportName = HttpContext.Current.Server.MapPath("~/testflv/test.flv");
4 string Command = " -i \"" + FromName + "\" -y -ab 32 -ar 22050 -b 800000 -s 480*360 \"" + ExportName + "\"";
5 System.Diagnostics.Process p = new System.Diagnostics.Process();
6 p.StartInfo.FileName = ffmpeg;
7 p.StartInfo.Arguments = Command;
8 p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/ffmpeg/");
9 p.StartInfo.UseShellExecute = false;
10 p.StartInfo.RedirectStandardInput = true;
11 p.StartInfo.RedirectStandardOutput = true;
12 p.StartInfo.RedirectStandardError = true;
13 p.StartInfo.CreateNoWindow = false;
14 try
15 {
16 p.Start();
17 }
18 catch (Exception ex)
19 {
20 Response.Write(ex.Message);
21 }
22 p.BeginErrorReadLine();
23 p.WaitForExit();
24 p.Close();
25 p.Dispose();
26
3、注意:上段代码中的红色一定要写,否则就会出现“找不到文件”的异常,也这是好多资料中遗漏的地方。导致无法运行。
不多说了。自己试试吧。
第一次发带附件的,不知道在哪里上传,先加个外面的吧。
附件下载