using System.Diagnostics;
string ffmpegPath = Configure.ffmpegPath(); //ffmpeg.exe文件所在位置
string mencoderPath = Configure.mencoderPath(); //mencoder.exe文件所在位置
string orginalFile = strBaseLocation + @"old/" + fileName; //转换前文件所在全路径
string targetFile = strBaseLocation + itemID + ".flv"; //转换后文件所在全路径
string argu = "";
if(fileName.ToUpper().EndsWith(".FLV")) //不同文件类型使用不同转换参数
argu = "-i /"" + orginalFile + "/" -ab 56 -ar 22050 -b 500 -r 15 -s 500x350 /"" + targetFile + "/"";
else if (fileName.ToUpper().EndsWith(".WMV"))
argu = @"-ffourcc FLV1 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -of lavf -oac mp3lame -lameopts aq=9:cbr:br=64:vol=2 -ovc lavc -lavcopts vcodec=flv:vbitrate=300:acodec=mp3:abitrate=56 -vf scale=320:290,expand=320:290:::1,crop=320:290:0:0 -ofps 18 -srate 22050 " + orginalFile + " -o " + targetFile;
else if (fileName.ToUpper().EndsWith(".AVI"))
argu = "-i " + orginalFile + " -f flv -vcodec flv -ab 56 -ar 22050 -b 100 -r 15 -s 500x350 -qscale 7 " + targetFile;
//根据不同类型的文件进行不同的转换
if (!fileName.ToUpper().EndsWith(".FLV"))
{
if (fileName.ToUpper().EndsWith(".WMV")) //利用mencoder.exe将wmv文件转换成flv文件
{
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(mencoderPath, argu);
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
System.Diagnostics.Process.Start(startInfo);
}
if (fileName.ToUpper().EndsWith(".AVI")) //利用ffmpeg.exe将avi文件转换成flv文件
{
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(ffmpegPath, argu);
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
System.Diagnostics.Process.Start(startInfo); //隐藏dos转换页面
}
}
else
{
System.IO.File.Copy(orginalFile, targetFile);
}
if (System.IO.File.Exists(targetFile) && (new System.IO.FileInfo(targetFile)).Length > 10000)
{
return "成功";
}
else
{
return "失败";
}