`
dimple
  • 浏览: 94412 次
  • 性别: Icon_minigender_1
  • 来自: 辽宁
社区版块
存档分类
最新评论

C#视频格式转换

阅读更多

  public void RunMencoder(String menValue){
           

  Control.CheckForIllegalCrossThreadCalls = false; //取消线程安全保护模式!注意的是这里不设置为false的话会(流输出事件的处理)产生异常.

   Process p = new Process();//建立外部调用线程
   p.StartInfo.FileName = ".\\mplayer\\mencoder.exe";//要调用外部程序的相对路径
   p.StartInfo.Arguments = menValue;//参数(这里就是MENCODER的参数了)
   p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN)
   p.StartInfo.RedirectStandardOutput = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,FFMPEG的所有输出信息,都为错误输出流,用StandardOutput是捕获不到任何消息的...这是我耗费了2个多月得出来的经验...mencoder就是用standardOutput来捕获的)我这里用的是mencoder
   p.StartInfo.CreateNoWindow = true;//不创建进程窗口
   p.OutputDataReceived += new DataReceivedEventHandler(this.Output);//外部程序(这里是mencoder)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
   p.Start();//启动线程
   p.BeginOutputReadLine();//开始异步读取
   p.WaitForExit();//阻塞等待进程结束
   p.Close();//关闭进程
   p.Dispose();//释放资源
     label7.Text = "处理成功!";

  }
        private void Output(object sendProcess, DataReceivedEventArgs output)
        {
            if (!String.IsNullOrEmpty(output.Data))
            {
               //这里是对流输出产生的事件的处理.
                textBox5.AppendText(output.Data + Environment.NewLine);
                this.textBox5.Refresh();
            }
        }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics