Пример #1
0
        public static string RunX264Command(FileConfig fileConfig, string avsPath)
        {
            VedioConfig      vedioConfig = fileConfig.VedioConfig;
            ProcessStartInfo processinfo = new ProcessStartInfo();

            processinfo.FileName = Path.Combine(Application.StartupPath, "tools\\avs4x264mod.exe");
            //processinfo.FileName = Environment.GetEnvironmentVariable("ComSpec");

            string x264Line = Resource1.x264Line;
            string x264exe  = "";

            if (vedioConfig.depth == 10)
            {
                x264exe = Path.Combine(Application.StartupPath, "tools\\x264_64_tMod-10bit-all.exe");
            }
            else
            {
                x264exe = Path.Combine(Application.StartupPath, "tools\\x264_64_tMod-8bit-all.exe");
            }
            x264Line = x264Line.Replace("$x264execute$", x264exe);
            x264Line = x264Line.Replace("$depth$", vedioConfig.depth.ToString());
            x264Line = x264Line.Replace("$preset$", vedioConfig.preset);
            if (string.IsNullOrEmpty(vedioConfig.tune))
            {
                x264Line = x264Line.Replace("$tune$", "");
            }
            else
            {
                x264Line = x264Line.Replace("$tune$", "--tune " + vedioConfig.tune);
            }
            x264Line = x264Line.Replace("$crf$", vedioConfig.crf.ToString());

            string outputpath = string.Empty;

            if (fileConfig.AudioConfig.Enabled)
            {//临时输出
                outputpath = Path.GetTempFileName() + ".mp4";
            }
            else
            {
                outputpath = fileConfig.OutputFile + ".mp4";
            }
            x264Line = x264Line.Replace("$outputfile$", outputpath);
            x264Line = x264Line.Replace("$intputavs$", avsPath);
            x264Line = x264Line.Replace("$userargs$", vedioConfig.UserArgs);
            x264Line = x264Line.Replace("$colormatrix$", vedioConfig.ColorMatrix.x264);
            processinfo.Arguments = x264Line;
            //processinfo.Arguments = "/c \"" + Path.Combine(Application.StartupPath, "tools\\avs4x264mod.exe") + "\" " + x264Line;
            //processinfo.UseShellExecute = false;    //输出信息重定向
            //processinfo.CreateNoWindow = true;
            //processinfo.RedirectStandardInput = true;
            //processinfo.RedirectStandardOutput = true;
            //processinfo.RedirectStandardError = false;
            //processinfo.WindowStyle = ProcessWindowStyle.Hidden;
            Process avsx264mod = new Process();

            avsx264mod.StartInfo = processinfo;
            avsx264mod.Start();

            //var result = avsx264mod.StandardOutput.ReadToEnd();
            //while (!avsx264mod.HasExited)
            //{
            //    Thread.Sleep(1000);
            //    continue;
            //}

            avsx264mod.WaitForExit();
            avsx264mod.Dispose();
            return(outputpath);
        }