日期:2014-05-17 浏览次数:21054 次
public string gvCommand = "-y -i " + @"E:\Basic\test.avi" + " -vcodec h263 -b 30000 -r 6 -s qcif -acodec libopencore_amrnb -ac 1 -ar 8000 -ab 10.2k -f 3gp " + @"D:\test.3gp";
public string gvFilepath = @"E:\Basic\test.avi";
        public void ConvertVideo()
        {
            Process p = new Process();//建立外部调用线程
            p.StartInfo.FileName = @"..\..\Basic\ffmpeg.exe";//要调用外部程序的绝对路径
        (成功)p.StartInfo.Arguments = gvCommand ;
        (成功)p.StartInfo.Arguments = "-y -i " + gvFilepath + " -vcodec h263 -b 30000 -r 6 -s qcif -acodec libopencore_amrnb -ac 1 -ar 8000 -ab 10.2k -f 3gp " + @"D:\test.3gp"; ;//参数(这里就是FFMPEG的参数了)
            p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN)
            p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,FFMPEG的所有输出信息,都为错误输出流,用StandardOutput是捕获不到任何消息的...这是我耗费了2个多月得出来的经验...mencoder就是用standardOutput来捕获的)
            p.StartInfo.CreateNoWindow = false;//不创建进程窗口
            p.ErrorDataReceived += new DataReceivedEventHandler(Output);//外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
            p.Start();//启动线程
            p.BeginErrorReadLine();//开始异步读取
            p.WaitForExit();//阻塞等待进程结束
            p.Close();//关闭进程
            p.Dispose();//释放资源
        }
        public void mGetDataSetFilepath()
        {
            foreach (DataRow i in gvVideolist.Tables["VideoList"].Rows)
            {
                gvFilepath = i["文件路径"].ToString();
                gvCommand = "-y -i " + gvFilepath + " -vcodec h263 -b 30000 -r 6 -s qcif -acodec libopencore_amrnb -ac 1 -ar 8000 -ab 10.2k -f 3gp " + @"D:\test.3gp";
                this.ConvertVideo();
            }
        }