private void btnAVS9_Click(object sender, EventArgs e) { x264DemuxerComboBox.SelectedIndex = 0; //压制AVS始终使用分离器为auto if (string.IsNullOrEmpty(nameout9)) { ShowErrorMessage("请选择输出文件"); return; } if (Path.GetExtension(nameout9).ToLower() != ".mp4") { ShowErrorMessage("仅支持MP4输出", "不支持的输出格式"); return; } if (File.Exists(txtout9.Text.Trim())) { DialogResult dgs = ShowQuestion("目标文件:\r\n\r\n" + txtout9.Text.Trim() + "\r\n\r\n已经存在,是否覆盖继续压制?", "目标文件已经存在"); if (dgs == DialogResult.No) return; } if (string.IsNullOrEmpty(Util.CheckAviSynth()) && string.IsNullOrEmpty(Util.CheckinternalAviSynth())) { if (ShowQuestion("检测到本机未安装avisynth无法继续压制,是否去下载安装", "avisynth未安装") == DialogResult.Yes) Process.Start("http://sourceforge.net/projects/avisynth2/"); return; } string inputName = Path.GetFileNameWithoutExtension(namevideo9); string tempVideo = Path.Combine(tempfilepath, inputName + "_vtemp.mp4"); string tempAudio = Path.Combine(tempfilepath, inputName + "_atemp" + getAudioExt()); Util.ensureDirectoryExists(tempfilepath); string filepath = tempavspath; //string filepath = workpath + "\\temp.avs"; File.WriteAllText(filepath, AVSScriptTextBox.Text, Encoding.Default); //检测是否含有音频 bool hasAudio = false; MediaInfo MI = new MediaInfo(); MI.Open(namevideo9); string audio = MI.Get(StreamKind.Audio, 0, "Format"); if (!string.IsNullOrEmpty(audio)) { hasAudio = true; } //audio if (AVSwithAudioCheckBox.Checked && hasAudio) { if (!File.Exists(txtvideo9.Text)) { ShowErrorMessage("请选择视频文件"); return; } aextract = audiobat(namevideo9, tempAudio); } else aextract = string.Empty; //video if (x264ExeComboBox.SelectedItem.ToString().ToLower().Contains("x264")) { if (x264mode == 2) x264 = x264bat(filepath, tempVideo, 1) + "\r\n" + x264bat(filepath, tempVideo, 2); else x264 = x264bat(filepath, tempVideo); if (!AVSwithAudioCheckBox.Checked || !hasAudio) x264 = x264.Replace(tempVideo, nameout9); } else if (x264ExeComboBox.SelectedItem.ToString().ToLower().Contains("x265")) { tempVideo = Path.Combine(tempfilepath, inputName + "_vtemp.hevc"); if (x264mode == 2) x264 = x265bat(filepath, tempVideo, 1) + "\r\n" + x265bat(filepath, tempVideo, 2); else x264 = x265bat(filepath, tempVideo); if (!AVSwithAudioCheckBox.Checked || !hasAudio) { x264 += "\r\n\"" + workPath + "\\mp4box.exe\" -add \"" + tempVideo + "#trackID=1:name=\" -new \"" + nameout9 + "\" \r\n"; x264 += "del \"" + tempVideo + "\""; } } //mux if (AVSwithAudioCheckBox.Checked && hasAudio) //如果包含音频 mux = boxmuxbat(tempVideo, tempAudio, nameout9); else mux = string.Empty; auto = aextract + x264 + "\r\n" + mux + " \r\n"; auto += "\r\necho ===== one file is completed! =====\r\n"; LogRecord(auto); Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(GetCultureName()); WorkingForm wf = new WorkingForm(auto); wf.Owner = this; wf.Show(); //auto += "\r\ncmd"; //batpath = workPath + "\\x264avs.bat"; //File.WriteAllText(batpath, auto, Encoding.Default); //Process.Start(batpath); }
private void x264StartBtn_Click(object sender, EventArgs e) { #region validation if (string.IsNullOrEmpty(namevideo2)) { ShowErrorMessage("请选择视频文件"); return; } if (!string.IsNullOrEmpty(namesub2) && !File.Exists(namesub2)) { ShowErrorMessage("字幕文件不存在,请重新选择"); return; } if (string.IsNullOrEmpty(nameout2)) { ShowErrorMessage("请选择输出文件"); return; } if (x264ExeComboBox.SelectedIndex == -1) { ShowErrorMessage("请选择X264程序"); return; } if (AudioEncoderComboBox.SelectedIndex != 0 && AudioEncoderComboBox.SelectedIndex != 1 && AudioEncoderComboBox.SelectedIndex != 5) { ShowWarningMessage("音频页面中的编码器未采用AAC将可能导致压制失败,建议将编码器改为QAAC、NeroAAC或FDKAAC。"); } //防止未选择 x264 thread if (x264ThreadsComboBox.SelectedIndex == -1) { x264ThreadsComboBox.SelectedIndex = 0; } //目标文件已经存在提示是否覆盖 if (File.Exists(x264OutTextBox.Text.Trim())) { DialogResult dgs = ShowQuestion("目标文件:\r\n\r\n" + x264OutTextBox.Text.Trim() + "\r\n\r\n已经存在,是否覆盖继续压制?", "目标文件已经存在"); if (dgs == DialogResult.No) return; } //如果是AVS复制到C盘根目录 if (Path.GetExtension(x264VideoTextBox.Text) == ".avs") { if (string.IsNullOrEmpty(Util.CheckAviSynth()) && string.IsNullOrEmpty(Util.CheckinternalAviSynth())) { if (ShowQuestion("检测到本机未安装avisynth无法继续压制,是否去下载安装", "avisynth未安装") == DialogResult.Yes) Process.Start("http://sourceforge.net/projects/avisynth2/"); return; } //if (File.Exists(tempavspath)) File.Delete(tempavspath); File.Copy(x264VideoTextBox.Text, tempavspath, true); namevideo2 = tempavspath; x264DemuxerComboBox.SelectedIndex = 0; //压制AVS始终使用分离器为auto } #endregion validation string ext = Path.GetExtension(nameout2).ToLower(); bool hasAudio = false; string inputName = Path.GetFileNameWithoutExtension(namevideo2); string tempVideo = Path.Combine(tempfilepath, inputName + "_vtemp.mp4"); string tempAudio = Path.Combine(tempfilepath, inputName + "_atemp" + getAudioExt()); Util.ensureDirectoryExists(tempfilepath); #region Audio //检测是否含有音频 MediaInfo MI = new MediaInfo(); MI.Open(namevideo2); string audio = MI.Get(StreamKind.Audio, 0, "Format"); if (!string.IsNullOrEmpty(audio)) hasAudio = true; int audioMode = x264AudioModeComboBox.SelectedIndex; if (!hasAudio && x264AudioModeComboBox.SelectedIndex != 1) { DialogResult r = ShowQuestion("原视频不包含音频流,音频模式是否改为无音频流?", "提示"); if (r == DialogResult.Yes) audioMode = 1; } switch (audioMode) { case 0: aextract = audiobat(namevideo2, tempAudio); break; case 1: aextract = string.Empty; break; case 2: if (audio.ToLower() == "aac") { tempAudio = Path.Combine(tempfilepath, inputName + "_atemp.aac"); aextract = ExtractAudio(namevideo2, tempAudio); } else { ShowInfoMessage("因音频编码非AAC故无法复制音频流,音频将被重编码。"); aextract = audiobat(namevideo2, tempAudio); } break; default: break; } #endregion #region Video if (x264ExeComboBox.SelectedItem.ToString().ToLower().Contains("x264")) { if (x264mode == 2) x264 = x264bat(namevideo2, tempVideo, 1, namesub2) + "\r\n" + x264bat(namevideo2, tempVideo, 2, namesub2); else x264 = x264bat(namevideo2, tempVideo, 0, namesub2); if (audioMode == 1) x264 = x264.Replace(tempVideo, nameout2); } else if (x264ExeComboBox.SelectedItem.ToString().ToLower().Contains("x265")) { tempVideo = Path.Combine(tempfilepath, inputName + "_vtemp.hevc"); if (ext != ".mp4") { ShowErrorMessage("不支持的格式输出,x265当前工具箱仅支持MP4输出"); return; } if (x264mode == 2) x264 = x265bat(namevideo2, tempVideo, 1) + "\r\n" + x265bat(namevideo2, tempVideo, 2); else x264 = x265bat(namevideo2, tempVideo); if (audioMode == 1) { x264 += "\r\n\"" + workPath + "\\mp4box.exe\" -add \"" + tempVideo + "#trackID=1:name=\" -new \"" + Util.ChangeExt(nameout2, ".mp4") + "\" \r\n"; x264 += "del \"" + tempVideo + "\""; } } x264 += "\r\n"; #endregion #region Mux //封装 if (audioMode != 1) { if (ext == ".mp4") mux = boxmuxbat(tempVideo, tempAudio, Util.ChangeExt(nameout2, ext)); else mux = ffmuxbat(tempVideo, tempAudio, Util.ChangeExt(nameout2, ext)); x264 = aextract + x264 + mux + "\r\n" + "del \"" + tempVideo + "\"\r\n" + "del \"" + tempAudio + "\"\r\n"; } x264 += "\r\necho ===== one file is completed! =====\r\n"; #endregion LogRecord(x264); Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(GetCultureName()); WorkingForm wf = new WorkingForm(x264); wf.Owner = this; wf.Show(); //x264 += "\r\ncmd"; //batpath = workPath + "\\x264.bat"; //File.WriteAllText(batpath, x264, Encoding.Default); //Process.Start(batpath); }
private void btnBatchAuto_Click(object sender, EventArgs e) { if (lbAuto.Items.Count == 0) { ShowErrorMessage("请输入视频!"); return; } if (x264ExeComboBox.SelectedIndex == -1) { ShowErrorMessage("请选择X264程序"); return; } Util.ensureDirectoryExists(tempfilepath); string bat = string.Empty; for (int i = 0; i < this.lbAuto.Items.Count; i++) { string input = lbAuto.Items[i].ToString(); string output; if (Directory.Exists(x264PathTextBox.Text)) output = x264PathTextBox.Text + "\\" + Path.GetFileNameWithoutExtension(input) + "_batch." + VideoBatchFormatComboBox.Text; else output = Util.ChangeExt(input, "_batch." + VideoBatchFormatComboBox.Text); bat += VideoBatch(lbAuto.Items[i].ToString(), output); } LogRecord(bat); Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(GetCultureName()); WorkingForm wf = new WorkingForm(bat, lbAuto.Items.Count); wf.Owner = this; wf.Show(); //batpath = workPath + "\\auto.bat"; //File.WriteAllText(batpath, bat, Encoding.Default); //Process.Start(batpath); }