//添加任务 private void button1_Click_1(object sender, EventArgs e) { foreach (ListViewItem lvi in listView1.Items) { FileConfig fileConfig = lvi.Tag as FileConfig; fileConfig.OutputPath = textBox1.Text; fileConfig.CompleteDo = cbCompleteDo.Checked; fileConfig.CompleteAction = cblCompeteAction.Text; fileConfig.CompleteActionDir = textBox2.Text; fileConfig.KeepDirection = cbKeepFileTree.Checked; VedioConfig vedioConfig = fileConfig.VedioConfig; vedioConfig.crf = float.Parse(textBox3.Text); vedioConfig.depth = int.Parse(cbColorDepth.Text); vedioConfig.preset = cbpreset.Text; vedioConfig.tune = comboBox1.Text; vedioConfig.UserArgs = txtUserArgs.Text; vedioConfig.Resize = checkBox1.Checked; vedioConfig.ColorMatrix = ColorMatrix.Convert(cbColorMatrix.Text); vedioConfig.Width = textBox4.Text == "" ? 0 : int.Parse(textBox4.Text); vedioConfig.Height = textBox5.Text == "" ? 0 : int.Parse(textBox5.Text); AudioConfig audioConfig = fileConfig.AudioConfig; audioConfig.Enabled = cbUseAudio.Checked; audioConfig.Quality = float.Parse(txtQuality.Text); ListViewItem lvi2 = new ListViewItem(); lvi2.Text = (listView2.Items.Count + 1).ToString(); lvi2.SubItems.Add(fileConfig.FullName); //.Name = "FileName"; lvi2.SubItems.Add("待转码").Name = "States"; lvi2.SubItems.Add(fileConfig.DirPath); //.Name = "Path"; lvi2.Tag = fileConfig; listView2.Items.Add(lvi2); } }
public static string GetAvsScriptFileName(FileConfig fileConfig) { VedioConfig vedioConfig = fileConfig.VedioConfig; string avspluginpath = Path.Combine(Application.StartupPath, "tools\\avsplugin"); string avstemplete = Resource1.AvsScriptTemplete.Replace("$avspluginpath$", avspluginpath); avstemplete = avstemplete.Replace("$inputVedioFileName$", fileConfig.FullName); if (vedioConfig.Resize) { avstemplete = avstemplete.Replace("$resize$", string.Format("nnedi3_resize16({0}, {1},lsb_in=true,lsb=true)", vedioConfig.Width, vedioConfig.Height)); } else { avstemplete = avstemplete.Replace("$resize$", string.Empty); } avstemplete = avstemplete.Replace("$depth$", vedioConfig.depth.ToString()); avstemplete = avstemplete.Replace("$colormatrix$", vedioConfig.ColorMatrix.avs) .Replace("$tvrange$", vedioConfig.ColorMatrix.tvrange); string filename = Path.GetTempFileName() + ".avs"; File.WriteAllText(filename, avstemplete); return(filename); }
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); }