左右间

行走在左右之间

博客园 首页 新随笔 联系 订阅 管理
转自yanwuxyz的专栏,http://blog.csdn.net/yanwuxyz/archive/2007/09/07/1776572.aspx

private void ConvertVideo(string inputPath, string outputPath)
{
    //转化处理,采用异步调用
    Control.CheckForIllegalCrossThreadCalls = false; //取消线程安全保护模式!注意的是这里不设置为false的话会(流输出事件的处理)产生异常.

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

posted on 2007-11-28 15:41  左右间  阅读(2167)  评论(0编辑  收藏  举报