ffmpeg used in window with .net

来源:互联网 发布:python找不到工作 编辑:程序博客网 时间:2024/05/20 13:41
public static bool Encode(string sourceFilePath, string outputFilePath, out long fileSize,out decimal playTime)
        {
            fileSize = 0;
            playTime = 0M;
            try
            {
                ProcessStartInfo startInfo = new ProcessStartInfo(Ffmpeg_Path);
                startInfo.UseShellExecute = false;
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.Arguments = " -i " + sourceFilePath + " -ab 32k -ar 22050 -b 350k -r 15 -qmin 6 -qmax 20 -s 320x240 -y " + outputFilePath;
                //------------------------------------------------------//
                //System.Diagnostics.Process.Start(startInfo);          //
                //此方法无法等待进程完成,所以更新为下面的方式执行。   //
                //------------------------------------------------------//
                System.Diagnostics.Process encodeProcess = new Process();
                encodeProcess.StartInfo = startInfo;
                encodeProcess.Start();
                //encodeProcess.WaitForExit();
                //增加时间限制,取消无限期等待完成。[Sunny Zhao 2006-11-1]
                if (encodeProcess.WaitForExit(3000000) == false)
                {
                    if (encodeProcess.Ha***ited == false)
                    {
                        encodeProcess.Kill();
                        encodeProcess.WaitForExit();
                    }
                }
                encodeProcess.Dispose();
                return Flvmdi(outputFilePath,out fileSize,out playTime);
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }  
原创粉丝点击