ffmpeg.exe与mencoder.exe实例转换操作

来源:互联网 发布:html css js 教程视频 编辑:程序博客网 时间:2024/05/17 08:53

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 -s500x350 /"" + targetFile + "/"";

else if (fileName.ToUpper().EndsWith(".WMV"))


               argu = @"-ffourcc FLV1 -lavfoptsi_certify_that_my_video_stream_does_not_use_b_frames -of lavf -oacmp3lame -lameopts aq=9:cbr:br=64:vol=2 -ovc lavc -lavcoptsvcodec=flv:vbitrate=300:acodec=mp3:abitrate=56 -vfscale=320:290,expand=320:290:::1,crop=320:290:0:0 -ofps 18 -srate22050 " + 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 = newSystem.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 = newSystem.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)&& (newSystem.IO.FileInfo(targetFile)).Length >10000)
{
      return "成功";

}
else

{

     return "失败";

}

0 0