show confirm dialog box when click abort button in WorkingForm.
[marukotoolbox.git] / mp4box / MainForm.cs
blobb510bca8dd408b3d2e3a2883b776eb18882eee5b
1 // ------------------------------------------------------------------
2 // Copyright (C) 2011-2016 Maruko Toolbox Project
3 //
4 // Authors: komaruchan <sandy_0308@hotmail.com>
5 // LunarShaddow <aflyhorse@hotmail.com>
6 // LYF <lyfjxymf@sina.com>
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
17 // express or implied.
18 // See the License for the specific language governing permissions
19 // and limitations under the License.
20 // -------------------------------------------------------------------
23 using ControlExs;
24 using MediaInfoLib;
25 using System;
26 using System.Collections.Generic;
27 using System.ComponentModel;
28 using System.Configuration;
29 using System.Diagnostics;
30 using System.Drawing;
31 using System.Drawing.Imaging;
32 using System.IO;
33 using System.Linq;
34 using System.Net;
35 using System.Reflection;
36 using System.Runtime.InteropServices;
37 using System.Runtime.Remoting.Messaging;
38 using System.Text;
39 using System.Text.RegularExpressions;
40 using System.Threading;
41 using System.Windows.Forms;
42 using System.Xml.Linq;
44 namespace mp4box
46 public partial class MainForm : Form
48 public string workPath = "!undefined";
49 public bool shutdownState = false;
50 public bool trayMode = false;
51 private XDocument xdoc;
53 #region Private Members Declaration
55 private StringBuilder avsBuilder = new StringBuilder(1000);
56 private string syspath = Environment.GetFolderPath(Environment.SpecialFolder.System).Remove(1);
57 private int indexofsource;
58 private int indexoftarget;
59 private byte x264mode = 1;
60 private string clip = "";
61 private string MIvideo = "";
62 private string namevideo = "";
63 private string namevideo2 = "";
64 private string namevideo4 = "";
65 private string namevideo5 = "";
66 private string namevideo6 = "";
67 private string nameaudio = "";
68 private string nameaudio2 = "";
69 private string nameaudio3 = "";
70 private string namevideo8 = "";
71 private string namevideo9 = "video";
72 private string nameout;
73 private string nameout2;
74 private string nameout3;
75 private string nameout5;
76 private string nameout6;
77 private string nameout9;
78 private string namesub;
79 private string namesub2 = "";
80 private string namesub9 = "subtitle";
81 private string MItext = "把视频文件拖到这里";
82 private string mkvextract;
83 private string mkvmerge;
84 private string mux;
85 private string x264;
86 private string ffmpeg;
87 private string aac;
88 private string aextract;
89 private string batpath;
90 private string auto;
91 private string startpath;
92 private string avs = "";
93 private string tempavspath = "";
94 private string tempPic = "";
95 private string logFileName, logPath;
96 private string tempfilepath;
97 private DateTime ReleaseDate = DateTime.Parse("2015-9-10 8:0:0");
99 #endregion Private Members Declaration
101 #region CPU Porocessors Number
103 [StructLayout(LayoutKind.Sequential)]
104 public struct SYSTEM_INFO
106 public uint dwOemId;
107 public uint dwPageSize;
108 public uint lpMinimumApplicationAddress;
109 public uint lpMaximumApplicationAddress;
110 public uint dwActiveProcessorMask;
111 public uint dwNumberOfProcessors;
112 public uint dwProcessorType;
113 public uint dwAllocationGranularity;
114 public uint dwProcessorLevel;
115 public uint dwProcessorRevision;
118 [DllImport("kernel32")]
119 private static extern void GetSystemInfo(ref SYSTEM_INFO pSI);
121 #endregion CPU Porocessors Number
123 public MainForm()
125 logPath = Application.StartupPath + "\\logs";
126 logFileName = logPath + "\\LogFile-" + DateTime.Now.ToString("yyyy'-'MM'-'dd'_'HH'-'mm'-'ss") + ".log";
127 InitializeComponent();
130 public string MediaInfo(string VideoName)
132 StringBuilder info = new StringBuilder();
133 if (File.Exists(VideoName))
135 MediaInfo MI = new MediaInfo();
136 MI.Open(VideoName);
137 //全局
138 string container = MI.Get(StreamKind.General, 0, "Format");
139 string bitrate = MI.Get(StreamKind.General, 0, "BitRate/String");
140 string duration = MI.Get(StreamKind.General, 0, "Duration/String1");
141 string fileSize = MI.Get(StreamKind.General, 0, "FileSize/String");
142 //视频
143 string vid = MI.Get(StreamKind.Video, 0, "ID");
144 string vformat = MI.Get(StreamKind.Video, 0, "Format");
145 string vBitRate = MI.Get(StreamKind.Video, 0, "BitRate/String");
146 string vSize = MI.Get(StreamKind.Video, 0, "StreamSize/String");
147 string width = MI.Get(StreamKind.Video, 0, "Width");
148 string height = MI.Get(StreamKind.Video, 0, "Height");
149 string risplayAspectRatio = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio/String");
150 string risplayAspectRatio2 = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio");
151 string frameRate = MI.Get(StreamKind.Video, 0, "FrameRate/String");
152 string colorSpace = MI.Get(StreamKind.Video, 0, "ColorSpace");
153 string chromaSubsampling = MI.Get(StreamKind.Video, 0, "ChromaSubsampling");
154 string bitDepth = MI.Get(StreamKind.Video, 0, "BitDepth/String");
155 string scanType = MI.Get(StreamKind.Video, 0, "ScanType/String");
156 string pixelAspectRatio = MI.Get(StreamKind.Video, 0, "PixelAspectRatio");
157 string encodedLibrary = MI.Get(StreamKind.Video, 0, "Encoded_Library/String");
158 string encodingSettings = MI.Get(StreamKind.Video, 0, "Encoded_Library_Settings");
159 string encodeTime = MI.Get(StreamKind.Video, 0, "Encoded_Date");
160 string codecProfile = MI.Get(StreamKind.Video, 0, "Codec_Profile");
161 string frameCount = MI.Get(StreamKind.Video, 0, "FrameCount");
163 //音频
164 string aid = MI.Get(StreamKind.Audio, 0, "ID");
165 string aformat = MI.Get(StreamKind.Audio, 0, "Format");
166 string aBitRate = MI.Get(StreamKind.Audio, 0, "BitRate/String");
167 string samplingRate = MI.Get(StreamKind.Audio, 0, "SamplingRate/String");
168 string channel = MI.Get(StreamKind.Audio, 0, "Channel(s)");
169 string aSize = MI.Get(StreamKind.Audio, 0, "StreamSize/String");
171 string audioInfo = MI.Get(StreamKind.Audio, 0, "Inform") + MI.Get(StreamKind.Audio, 1, "Inform") + MI.Get(StreamKind.Audio, 2, "Inform") + MI.Get(StreamKind.Audio, 3, "Inform");
172 string videoInfo = MI.Get(StreamKind.Video, 0, "Inform");
174 info = info.Append(Path.GetFileName(VideoName) + "\r\n");
175 if (!string.IsNullOrEmpty(container))
176 info.Append("容器:" + container + "\r\n");
177 if (!string.IsNullOrEmpty(bitrate))
178 info.Append("总码率:" + bitrate + "\r\n");
179 if (!string.IsNullOrEmpty(fileSize))
180 info.Append("大小:" + fileSize + "\r\n");
181 if (!string.IsNullOrEmpty(duration))
182 info.Append("时长:" + duration + "\r\n");
184 if (!string.IsNullOrEmpty(vformat))
185 info.Append("\r\n" + "视频(" + vid + "):" + vformat + "\r\n");
186 if (!string.IsNullOrEmpty(codecProfile))
187 info.Append("Profile:" + codecProfile + "\r\n");
188 if (!string.IsNullOrEmpty(vBitRate))
189 info.Append("码率:" + vBitRate + "\r\n");
190 if (!string.IsNullOrEmpty(vSize))
191 info.Append("文件大小:" + vSize + "\r\n");
192 if (!string.IsNullOrEmpty(width) && !string.IsNullOrEmpty(height))
193 info.Append("分辨率:" + width + "x" + height + "\r\n");
194 if (!string.IsNullOrEmpty(risplayAspectRatio) && !string.IsNullOrEmpty(risplayAspectRatio2))
195 info.Append("画面比例:" + risplayAspectRatio + "(" + risplayAspectRatio2 + ")" + "\r\n");
196 if (!string.IsNullOrEmpty(pixelAspectRatio))
197 info.Append("像素宽高比:" + pixelAspectRatio + "\r\n");
198 if (!string.IsNullOrEmpty(frameRate))
199 info.Append("帧率:" + frameRate + "\r\n");
200 if (!string.IsNullOrEmpty(colorSpace))
201 info.Append("色彩空间:" + colorSpace + "\r\n");
202 if (!string.IsNullOrEmpty(chromaSubsampling))
203 info.Append("色度抽样:" + chromaSubsampling + "\r\n");
204 if (!string.IsNullOrEmpty(bitDepth))
205 info.Append("位深度:" + bitDepth + "\r\n");
206 if (!string.IsNullOrEmpty(scanType))
207 info.Append("扫描方式:" + scanType + "\r\n");
208 if (!string.IsNullOrEmpty(encodeTime))
209 info.Append("编码时间:" + encodeTime + "\r\n");
210 if (!string.IsNullOrEmpty(frameCount))
211 info.Append("总帧数:" + frameCount + "\r\n");
212 if (!string.IsNullOrEmpty(encodedLibrary))
213 info.Append("编码库:" + encodedLibrary + "\r\n");
214 if (!string.IsNullOrEmpty(encodingSettings))
215 info.Append("编码设置:" + encodingSettings + "\r\n");
217 if (!string.IsNullOrEmpty(aformat))
218 info.Append("\r\n" + "音频(" + aid + "):" + aformat + "\r\n");
219 if (!string.IsNullOrEmpty(aSize))
220 info.Append("大小:" + aSize + "\r\n");
221 if (!string.IsNullOrEmpty(aBitRate))
222 info.Append("码率:" + aBitRate + "\r\n");
223 if (!string.IsNullOrEmpty(samplingRate))
224 info.Append("采样率:" + samplingRate + "\r\n");
225 if (!string.IsNullOrEmpty(channel))
226 info.Append("声道数:" + channel + "\r\n");
227 info.Append("\r\n====详细信息====\r\n" + videoInfo + "\r\n" + audioInfo + "\r\n");
228 MI.Close();
230 else
231 info.Append("文件不存在、非有效文件或者文件夹 无视频信息");
232 return info.ToString();
235 public string ffmuxbat(string input1, string input2, string output)
237 return "\"" + workPath + "\\ffmpeg.exe\" -i \"" + input1 + "\" -i \"" + input2 + "\" -sn -c copy -y \"" + output + "\"\r\n";
240 public string boxmuxbat(string input1, string input2, string output)
242 return "\"" + workPath + "\\mp4box.exe\" -add \"" + input1 + "#trackID=1:name=\" -add \"" + input2 + "#trackID=1:name=\" -new \"" + output + "\"\r\n";
245 public string x264bat(string input, string output, int pass = 1, string sub = "")
247 StringBuilder sb = new StringBuilder();
248 //keyint设为fps的10倍
249 MediaInfo MI = new MediaInfo();
250 MI.Open(input);
251 string frameRate = MI.Get(StreamKind.Video, 0, "FrameRate");
252 double fps;
253 string keyint = "-1";
254 if (double.TryParse(frameRate, out fps))
256 fps = Math.Round(fps);
257 keyint = (fps * 10).ToString();
260 if (Path.GetExtension(input) == ".avs")
261 sb.Append("\"" + workPath + "\\avs4x26x.exe\"" + " -L ");
262 sb.Append("\"" + Path.Combine(workPath, x264ExeComboBox.SelectedItem.ToString()) + "\"");
263 // 编码模式
264 switch (x264mode)
266 case 0: // 自定义
267 sb.Append(" " + x264CustomParameterTextBox.Text);
268 break;
270 case 1: // crf
271 sb.Append(" --crf " + x264CRFNum.Value);
272 break;
274 case 2: // 2pass
275 sb.Append(" --pass " + pass + " --bitrate " + x264BitrateNum.Value + " --stats \"" + Path.Combine(tempfilepath, Path.GetFileNameWithoutExtension(output)) + ".stats\"");
276 break;
278 if (x264mode != 0)
280 if (x264DemuxerComboBox.Text != "auto" && x264DemuxerComboBox.Text != string.Empty)
281 sb.Append(" --demuxer " + x264DemuxerComboBox.Text);
282 if (x264ThreadsComboBox.SelectedItem.ToString() != "auto" && x264ThreadsComboBox.SelectedItem.ToString() != string.Empty)
283 sb.Append(" --threads " + x264ThreadsComboBox.SelectedItem.ToString());
284 if (x264extraLine.Text != string.Empty)
285 sb.Append(" " + x264extraLine.Text);
286 else
287 sb.Append(" --preset 8 " + " -I " + keyint + " -r 4 -b 3 --me umh -i 1 --scenecut 60 -f 1:1 --qcomp 0.5 --psy-rd 0.3:0 --aq-mode 2 --aq-strength 0.8");
288 if (x264HeightNum.Value != 0 && x264WidthNum.Value != 0 && !MaintainResolutionCheckBox.Checked)
289 sb.Append(" --vf resize:" + x264WidthNum.Value + "," + x264HeightNum.Value + ",,,,lanczos");
291 if (!string.IsNullOrEmpty(sub))
293 string x264tmpline = sb.ToString();
294 if (x264tmpline.IndexOf("--vf") == -1)
295 sb.Append(" --vf subtitles --sub \"" + sub + "\"");
296 else
298 Regex r = new Regex("--vf\\s\\S*");
299 Match m = r.Match(x264tmpline);
300 sb.Insert(m.Index + 5, "subtitles/").Append(" --sub \"" + sub + "\"");
303 if (x264SeekNumericUpDown.Value != 0)
304 sb.Append(" --seek " + x264SeekNumericUpDown.Value.ToString());
305 if (x264FramesNumericUpDown.Value != 0)
306 sb.Append(" --frames " + x264FramesNumericUpDown.Value.ToString());
307 if (x264mode == 2 && pass == 1)
308 sb.Append(" -o NUL");
309 else if (!string.IsNullOrEmpty(output))
310 sb.Append(" -o " + "\"" + output + "\"");
311 if (!string.IsNullOrEmpty(input))
312 sb.Append(" \"" + input + "\"");
313 return sb.ToString();
316 public string x265bat(string input, string output, int pass = 1)
318 StringBuilder sb = new StringBuilder();
319 sb.Append("\"" + workPath + "\\ffmpeg.exe\"" + " -i \"" + input + "\"");
320 if (x264HeightNum.Value != 0 && x264WidthNum.Value != 0 && !MaintainResolutionCheckBox.Checked)
321 sb.Append(" -s " + x264WidthNum.Value + "x" + x264HeightNum.Value);
322 sb.Append(" -f yuv4mpegpipe -an -v 0 - | ");
323 sb.Append(Util.FormatPath(Path.Combine(workPath, x264ExeComboBox.SelectedItem.ToString())) + " --y4m");
324 // 编码模式
325 switch (x264mode)
327 case 0: // 自定义
328 sb.Append(" " + x264CustomParameterTextBox.Text);
329 break;
331 case 1: // crf
332 sb.Append(" --crf " + x264CRFNum.Value);
333 break;
335 case 2: // 2pass
336 sb.Append(" --pass " + pass + " --bitrate " + x264BitrateNum.Value + " --stats \"" + Path.Combine(tempfilepath, Path.GetFileNameWithoutExtension(output)) + ".stats\"");
337 break;
339 if (x264mode != 0)
341 if (x264extraLine.Text != string.Empty)
342 sb.Append(" " + x264extraLine.Text);
343 else
344 sb.Append(" --preset slower --tu-intra-depth 3 --tu-inter-depth 3 --rdpenalty 2 --me 3 --subme 5 --merange 44 --b-intra --no-rect --no-amp --ref 5 --weightb --bframes 8 --aq-mode 1 --aq-strength 1.0 --rd 5 --psy-rd 0.7 --psy-rdoq 5.0 --rdoq-level 1 --no-sao --no-open-gop --rc-lookahead 80 --scenecut 40 --max-merge 4 --qcomp 0.7 --no-strong-intra-smoothing --deblock -1:-1 --qg-size 16");
346 if (x264SeekNumericUpDown.Value != 0)
347 sb.Append(" --seek " + x264SeekNumericUpDown.Value.ToString());
348 if (x264FramesNumericUpDown.Value != 0)
349 sb.Append(" --frames " + x264FramesNumericUpDown.Value.ToString());
350 if (x264mode == 2 && pass == 1)
351 sb.Append(" -o NUL");
352 else if (!string.IsNullOrEmpty(output))
353 sb.Append(" -o " + "\"" + output + "\"");
354 if (!string.IsNullOrEmpty(input))
355 sb.Append(" -");
356 return sb.ToString();
359 public static bool stringCheck(string str, string info = "")
361 if (string.IsNullOrEmpty(str))
363 MessageBox.Show("发现空或者无效的字符串 " + info);
365 return string.IsNullOrEmpty(str);
368 public string timeminus(int h1, int m1, int s1, int h2, int m2, int s2)
370 int h = 0;
371 int m = 0;
372 int s = 0;
373 s = s2 - s1;
374 if (s < 0)
376 m = -1;
377 s = s + 60;
379 m = m + m2 - m1;
380 if (m < 0)
382 h = -1;
383 m = m + 60;
385 h = h + h2 - h1;
386 return h.ToString() + ":" + m.ToString() + ":" + s.ToString();
389 public string timeplus(int h1, int m1, int s1, int h2, int m2, int s2)
391 int h = 0;
392 int m = 0;
393 int s = 0;
394 s = s1 + s2;
395 if (s >= 60)
397 m = 1;
398 s = s - 60;
400 m = m + m1 + m2;
401 if (m >= 60)
403 h = 1;
404 m = m - 60;
406 h = h + h1 + h2;
407 return h.ToString() + ":" + m.ToString() + ":" + s.ToString();
410 public string audiobat(string input, string output)
412 int AACbr = 1000 * Convert.ToInt32(AudioBitrateComboBox.Text);
413 string br = AACbr.ToString();
414 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -i \"" + input + "\" -vn -sn -v 0 -c:a pcm_s16le -f wav pipe:|";
415 switch (AudioEncoderComboBox.SelectedIndex)
417 case 0:
418 if (AudioBitrateRadioButton.Checked)
420 ffmpeg += "\"" + workPath + "\\neroAacEnc.exe\" -ignorelength -lc -br " + br + " -if - -of \"" + output + "\"";
422 if (AudioCustomizeRadioButton.Checked)
424 ffmpeg += "\"" + workPath + "\\neroAacEnc.exe\" -ignorelength " + AudioCustomParameterTextBox.Text.ToString() + " -if - -of \"" + output + "\"";
426 break;
428 case 1:
429 if (AudioBitrateRadioButton.Checked)
431 ffmpeg += "\"" + workPath + "\\qaac.exe\" -q 2 --ignorelength -c " + AudioBitrateComboBox.Text + " - -o \"" + output + "\"";
433 if (AudioCustomizeRadioButton.Checked)
435 ffmpeg += "\"" + workPath + "\\qaac.exe\" --ignorelength " + AudioCustomParameterTextBox.Text.ToString() + " - -o \"" + output + "\"";
437 break;
439 case 2:
440 if (Path.GetExtension(output) == ".aac")
441 output = Util.ChangeExt(output, ".wav");
442 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + input + "\" -f wav \"" + output + "\"";
443 break;
445 case 3:
446 ffmpeg += "\"" + workPath + "\\refalac.exe\" --ignorelength - -o \"" + output + "\"";
447 break;
449 case 4:
450 ffmpeg += "\"" + workPath + "\\flac.exe\" -f --ignore-chunk-sizes -5 - -o \"" + output + "\"";
451 break;
453 case 5:
454 if (AudioBitrateRadioButton.Checked)
456 ffmpeg += "\"" + workPath + "\\fdkaac.exe\" --ignorelength -b " + AudioBitrateComboBox.Text + " - -o \"" + output + "\"";
458 if (AudioCustomizeRadioButton.Checked)
460 ffmpeg += "\"" + workPath + "\\fdkaac.exe\" --ignorelength " + AudioCustomParameterTextBox.Text.ToString() + " - -o \"" + output + "\"";
462 break;
464 case 6:
465 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -i \"" + input + "\" -c:a ac3 -b:a " + AudioBitrateComboBox.Text.ToString() + "k \"" + output + "\"";
466 break;
468 default:
469 break;
471 aac = ffmpeg + "\r\n";
472 return aac;
475 private string getAudioExt()
477 string ext = ".aac";
478 switch (AudioEncoderComboBox.SelectedIndex)
480 case 0: ext = ".mp4"; break;
481 case 1: ext = ".m4a"; break;
482 case 2: ext = ".wav"; break;
483 case 3: ext = ".m4a"; break;
484 case 4: ext = ".flac"; break;
485 case 5: ext = ".m4a"; break;
486 case 6: ext = ".ac3"; break;
487 default: ext = ".aac"; break;
489 return ext;
492 private void btnaudio_Click(object sender, EventArgs e)
494 openFileDialog1.Filter = "音频(*.mp4;*.aac;*.mp2;*.mp3;*.m4a;*.ac3)|*.mp4;*.aac;*.mp2;*.mp3;*.m4a;*.ac3|所有文件(*.*)|*.*";
495 DialogResult result = openFileDialog1.ShowDialog();
496 if (result == DialogResult.OK)
498 nameaudio = openFileDialog1.FileName;
499 txtaudio.Text = nameaudio;
503 private void btnvideo_Click(object sender, EventArgs e)
505 openFileDialog1.Filter = "视频(*.avi;*.mp4;*.m1v;*.m2v;*.m4v;*.264;*.h264;*.hevc)|*.avi;*.mp4;*.m1v;*.m2v;*.m4v;*.264;*.h264;*.hevc|所有文件(*.*)|*.*";
506 DialogResult result = openFileDialog1.ShowDialog();
507 if (result == DialogResult.OK)
509 namevideo = openFileDialog1.FileName;
510 txtvideo.Text = namevideo;
514 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
518 private void btnout_Click(object sender, EventArgs e)
520 SaveFileDialog savefile = new SaveFileDialog();
521 savefile.Filter = "视频(*.mp4)|*.mp4";
522 DialogResult result = savefile.ShowDialog();
523 if (result == DialogResult.OK)
525 nameout = savefile.FileName;
526 txtout.Text = nameout;
530 private void btnmux_Click(object sender, EventArgs e)
532 if (namevideo == "")
534 ShowErrorMessage("请选择视频文件");
535 return;
537 string inputExt = Path.GetExtension(txtvideo.Text.Trim()).ToLower();
538 if (inputExt != ".avi" //Only MPEG-4 SP/ASP video and MP3 audio supported at the current time. To import AVC/H264 video, you must first extract the avi track.
539 && inputExt != ".mp4" //MPEG-4 Video
540 && inputExt != ".m1v" //MPEG-1 Video
541 && inputExt != ".m2v" //MPEG-2 Video
542 && inputExt != ".m4v" //MPEG-4 Video
543 && inputExt != ".264" //AVC/H264 Video
544 && inputExt != ".h264" //AVC/H264 Video
545 && inputExt != ".hevc") //HEVC/H265 Video
547 ShowErrorMessage("输入文件: \r\n\r\n" + txtvideo.Text.Trim() + "\r\n\r\n是一个mp4box不支持的视频文件!");
548 return;
551 if (nameout == "")
553 ShowErrorMessage("请选择输出文件");
554 return;
556 StringBuilder sb = new StringBuilder();
557 sb.Append(Util.FormatPath(workPath + "\\mp4box.exe") + " -add \"" + namevideo + "#trackID=1");
558 if (Mp4BoxParComboBox.Text != "")
559 sb.Append(":par=" + Mp4BoxParComboBox.Text);
560 if (cbFPS.Text != "auto" && cbFPS.Text != "")
561 sb.Append(":fps=" + cbFPS.Text);
562 sb.Append(":name=\""); //输入raw时删除默认添加的gpac字符串
563 if (nameaudio != "")
564 sb.Append(" -add \"" + nameaudio + ":name=\"");
565 sb.Append(" -new \"" + nameout + "\" \r\n cmd");
566 mux = sb.ToString();
567 batpath = workPath + "\\mux.bat";
568 File.WriteAllText(batpath, mux, Encoding.Default);
569 LogRecord(mux);
570 Process.Start(batpath);
573 private void btnaextract_Click(object sender, EventArgs e)
575 //MP4 抽取音频1
576 ExtractAV(namevideo, "a", 0);
577 //if (namevideo == "")
579 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
581 //else
583 // //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 2 \"" + namevideo + "\"";
584 // aextract = "";
585 // aextract += Cmd.FormatPath(workPath + "\\ffmpeg.exe");
586 // aextract += " -i " + Cmd.FormatPath(namevideo);
587 // aextract += " -vn -sn -c:a:0 copy ";
588 // string outfile = Cmd.GetDir(namevideo) +
589 // Path.GetFileNameWithoutExtension(namevideo) + "_抽取音频1" + Path.GetExtension(namevideo);
590 // aextract += Cmd.FormatPath(outfile);
591 // batpath = workPath + "\\aextract.bat";
592 // File.WriteAllText(batpath, aextract, Encoding.Default);
593 // LogRecord(aextract);
594 // Process.Start(batpath);
598 private void ExtractAV(string namevideo, string av, int streamIndex)
600 if (string.IsNullOrEmpty(namevideo))
602 ShowErrorMessage("请选择视频文件");
603 return;
606 string ext = Path.GetExtension(namevideo);
607 //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 2 \"" + namevideo + "\"";
608 string aextract = "";
609 aextract += Util.FormatPath(workPath + "\\ffmpeg.exe");
610 aextract += " -i " + Util.FormatPath(namevideo);
611 if (av == "a")
613 aextract += " -vn -sn -c:a copy -y -map 0:a:" + streamIndex + " ";
615 MediaInfo MI = new MediaInfo();
616 MI.Open(namevideo);
617 string audioFormat = MI.Get(StreamKind.Audio, streamIndex, "Format");
618 string audioProfile = MI.Get(StreamKind.Audio, streamIndex, "Format_Profile");
619 if (!string.IsNullOrEmpty(audioFormat))
621 if (audioFormat.Contains("MPEG") && audioProfile == "Layer 3")
622 ext = ".mp3";
623 else if (audioFormat.Contains("MPEG") && audioProfile == "Layer 2")
624 ext = ".mp2";
625 else if (audioFormat.Contains("PCM")) //flv support(PCM_U8 * PCM_S16BE * PCM_MULAW * PCM_ALAW * ADPCM_SWF)
626 ext = ".wav";
627 else if (audioFormat == "AAC")
628 ext = ".aac";
629 else if (audioFormat == "AC-3")
630 ext = ".ac3";
631 else if (audioFormat == "ALAC")
632 ext = ".m4a";
633 else
634 ext = ".mka";
636 else
638 ShowInfoMessage("该轨道无音频");
639 return;
642 else if (av == "v")
644 aextract += " -an -sn -c:v copy -y -map 0:v:" + streamIndex + " ";
646 else
648 throw new Exception("未知流!");
650 string suf = "_audio_";
651 if (av == "v")
653 suf = "_video_";
655 suf += "index" + streamIndex;
656 string outfile = Util.GetDir(namevideo) +
657 Path.GetFileNameWithoutExtension(namevideo) + suf + ext;
658 aextract += Util.FormatPath(outfile);
659 batpath = workPath + "\\" + av + "extract.bat";
660 File.WriteAllText(batpath, aextract, Encoding.Default);
661 LogRecord(aextract);
662 Process.Start(batpath);
665 private string ExtractAudio(string namevideo, string outfile, int streamIndex = 0)
667 if (string.IsNullOrEmpty(namevideo))
669 return "";
671 string ext = Path.GetExtension(namevideo);
672 //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 2 \"" + namevideo + "\"";
673 string aextract = "";
674 aextract += Util.FormatPath(workPath + "\\ffmpeg.exe");
675 aextract += " -i " + Util.FormatPath(namevideo);
676 aextract += " -vn -sn -c:a copy -y -map 0:a:" + streamIndex + " ";
677 MediaInfo MI = new MediaInfo();
678 MI.Open(namevideo);
679 string audioFormat = MI.Get(StreamKind.Audio, streamIndex, "Format");
680 string audioProfile = MI.Get(StreamKind.Audio, streamIndex, "Format_Profile");
681 if (!string.IsNullOrEmpty(audioFormat))
683 if (audioFormat.Contains("MPEG") && audioProfile == "Layer 3")
684 ext = ".mp3";
685 else if (audioFormat.Contains("MPEG") && audioProfile == "Layer 2")
686 ext = ".mp2";
687 else if (audioFormat.Contains("PCM")) //flv support(PCM_U8 * PCM_S16BE * PCM_MULAW * PCM_ALAW * ADPCM_SWF)
688 ext = ".wav";
689 else if (audioFormat == "AAC")
690 ext = ".aac";
691 else if (audioFormat == "AC-3")
692 ext = ".ac3";
693 else if (audioFormat == "ALAC")
694 ext = ".m4a";
695 else
696 ext = ".mka";
698 else
700 return "";
702 aextract += Util.FormatPath(outfile) + "\r\n";
703 return aextract;
706 private void ExtractTrack(string namevideo, int streamIndex)
708 if (string.IsNullOrEmpty(namevideo))
710 ShowErrorMessage("请选择视频文件");
711 return;
714 string aextract = "";
715 aextract += Util.FormatPath(workPath + "\\ffmpeg.exe");
716 aextract += " -i " + Util.FormatPath(namevideo);
717 aextract += " -map 0:" + streamIndex + " -c copy ";
718 string suf = "_抽取流Index" + streamIndex;
719 string outfile = Util.GetDir(namevideo) +
720 Path.GetFileNameWithoutExtension(namevideo) + suf + '.' +
721 FormatExtractor.Extract(workPath, namevideo)[streamIndex].Format;
722 aextract += Util.FormatPath(outfile);
723 batpath = workPath + "\\mkvextract.bat";
724 File.WriteAllText(batpath, aextract, Encoding.Default);
725 LogRecord(aextract);
726 Process.Start(batpath);
729 private void button1_Click(object sender, EventArgs e)
731 ShowInfoMessage(string.Format(" \r\n有任何建议或疑问可以通过以下方式联系小丸。\nQQ:57655408\n微博:weibo.com/xiaowan3\n百度贴吧ID:小丸到达\n\n\t\t\t发布日期:2012年10月17日\n\t\t\t- ( ゜- ゜)つロ 乾杯~"), "关于");
734 private void btnvextract_Click(object sender, EventArgs e)
736 //MP4抽取视频1
737 ExtractAV(namevideo, "v", 0);
738 //if (namevideo == "")
740 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
742 //else
744 // //vextract = "\"" + workPath + "\\mp4box.exe\" -raw 1 \"" + namevideo + "\"";
745 // vextract = "";
746 // vextract += Cmd.FormatPath(workPath + "\\ffmpeg.exe");
747 // vextract += " -i " + Cmd.FormatPath(namevideo);
748 // vextract += " -an -sn -c:v:0 copy ";
749 // string outfile = Cmd.GetDir(namevideo) +
750 // Path.GetFileNameWithoutExtension(namevideo) + "_抽取视频1" + Path.GetExtension(namevideo);
751 // vextract += Cmd.FormatPath(outfile);
752 // batpath = workPath + "\\vextract.bat";
753 // File.WriteAllText(batpath, vextract, Encoding.Default);
754 // LogRecord(vextract);
755 // Process.Start(batpath);
759 private void txtvideo_TextChanged(object sender, EventArgs e)
763 if (txtvideo.Text.Trim().Length > 0)
765 if (!File.Exists(txtvideo.Text.Trim()))
767 throw new Exception("输入文件: \r\n\r\n" + txtvideo.Text.Trim() + "\r\n\r\n不存在!");
769 string inputExt = Path.GetExtension(txtvideo.Text.Trim()).ToLower();
770 //if (inputExt != ".avi" //Only MPEG-4 SP/ASP video and MP3 audio supported at the current time. To import AVC/H264 video, you must first extract the avi track.
771 // && inputExt != ".mp4" //MPEG-4 Video
772 // && inputExt != ".m1v" //MPEG-1 Video
773 // && inputExt != ".m2v" //MPEG-2 Video
774 // && inputExt != ".m4v" //MPEG-4 Video
775 // && inputExt != ".264" //AVC/H264 Video
776 // && inputExt != ".h264" //AVC/H264 Video
777 // && inputExt != ".hevc") //HEVC/H265 Video
779 // throw new Exception("输入文件: \r\n\r\n" + txtvideo.Text.Trim() + "\r\n\r\n是一个mp4box不支持的视频文件!");
781 if (inputExt == ".264" || inputExt == ".h264" || inputExt == ".hevc")
783 ShowWarningMessage("H.264或者HEVC流文件mp4box将会自动侦测帧率\r\n如果侦测不到将默认为25fps\r\n如果你知道该文件的帧率建议手动设置");
785 namevideo = txtvideo.Text;
786 txtout.Text = Util.ChangeExt(txtvideo.Text, "_Mux.mp4");
789 catch (Exception ex)
791 txtvideo.Text = string.Empty;
792 ShowErrorMessage(ex.Message);
796 private void txtaudio_TextChanged(object sender, EventArgs e)
800 if (txtaudio.Text.Trim().Length > 0)
802 if (!File.Exists(txtaudio.Text.Trim()))
804 throw new Exception("输入文件: \r\n\r\n" + txtaudio.Text.Trim() + "\r\n\r\n不存在!");
806 string inputExt = Path.GetExtension(txtaudio.Text.Trim()).ToLower();
807 if (inputExt != ".mp4"
808 && inputExt != ".aac" //ADIF or RAW formats not supported
809 && inputExt != ".mp3"
810 && inputExt != ".m4a"
811 && inputExt != ".mp2"
812 && inputExt != ".ac3")
814 throw new Exception("输入文件: \r\n\r\n" + txtaudio.Text.Trim() + "\r\n\r\n是一个mp4box不支持的音频文件!");
816 nameaudio = txtaudio.Text;
819 catch (Exception ex)
821 txtaudio.Text = string.Empty;
822 ShowErrorMessage(ex.Message);
826 private void txtout_TextChanged(object sender, EventArgs e)
828 nameout = txtout.Text;
831 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
833 #region Delete Temp Files
835 if (SetupDeleteTempFileCheckBox.Checked && !workPath.Equals("!undefined"))
837 List<string> deleteFileList = new List<string>();
839 string systemDisk = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 3);
840 string systemTempPath = systemDisk + @"windows\temp";
842 //Delete all BAT files
843 DirectoryInfo theFolder = new DirectoryInfo(workPath);
844 foreach (FileInfo NextFile in theFolder.GetFiles())
846 if (NextFile.Extension.Equals(".bat"))
847 deleteFileList.Add(NextFile.FullName);
850 if (Directory.Exists(tempfilepath))
852 foreach (var item in Directory.GetFiles(tempfilepath))
854 deleteFileList.Add(item);
858 string[] deletedfiles = { "concat.txt", tempPic, tempavspath, workPath + "msg.vbs" };
859 deleteFileList.AddRange(deletedfiles);
861 foreach (string file in deleteFileList)
863 File.Delete(file);
867 #endregion Delete Temp Files
869 #region Save Settings
871 SaveSettings();
873 #endregion Save Settings
876 private void txtvideo4_TextChanged(object sender, EventArgs e)
878 if (File.Exists(txtvideo4.Text.ToString()))
880 namevideo4 = txtvideo4.Text;
881 //string finish = namevideo4.Insert(namevideo4.LastIndexOf(".")-1,"");
882 //string ext = namevideo4.Substring(namevideo4.LastIndexOf(".") + 1, 3);
883 //finish += "_clip." + ext;
884 string finish = namevideo4.Insert(namevideo4.LastIndexOf("."), "_output");
885 txtout5.Text = finish;
889 private void txtout5_TextChanged(object sender, EventArgs e)
891 nameout5 = txtout5.Text;
894 private void btnvideo4_Click(object sender, EventArgs e)
896 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
897 DialogResult result = openFileDialog1.ShowDialog();
898 if (result == DialogResult.OK)
900 namevideo4 = openFileDialog1.FileName;
901 txtvideo4.Text = namevideo4;
905 private void btnout5_Click(object sender, EventArgs e)
907 SaveFileDialog savefile = new SaveFileDialog();
908 savefile.Filter = "视频(*.*)|*.*";
909 DialogResult result = savefile.ShowDialog();
910 if (result == DialogResult.OK)
912 nameout5 = savefile.FileName;
913 txtout5.Text = nameout5;
917 public static bool IsWindowsVistaOrNewer
919 get { return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 6); }
922 #region Settings
924 /// <summary>
925 /// 还原默认参数
926 /// </summary>
927 private void InitParameter()
929 #region Video Tab
931 x264CRFNum.Value = 23.5m;
932 x264BitrateNum.Value = 800;
933 x264AudioParameterTextBox.Text = "--abitrate 128";
934 x264AudioModeComboBox.SelectedIndex = 0;
935 x264DemuxerComboBox.SelectedIndex = 0;
936 x264WidthNum.Value = 0;
937 x264HeightNum.Value = 0;
938 x264CustomParameterTextBox.Text = "";
939 x264PriorityComboBox.SelectedIndex = 2;
940 x264FramesNumericUpDown.Value = 0;
941 x264SeekNumericUpDown.Value = 0;
942 x264Mode1RadioButton.Checked = true;
943 x264ShutdownCheckBox.Checked = false;
945 #endregion Video Tab
947 #region Audio Tab
949 AudioEncoderComboBox.SelectedIndex = 0;
950 AudioPresetComboBox.SelectedIndex = 0;
951 AudioBitrateComboBox.Text = "128";
952 AudioBitrateRadioButton.Checked = true;
954 #endregion Audio Tab
956 #region General Tab
958 OnePicAudioBitrateNum.Value = 128;
959 OnePicFPSNum.Value = 1;
960 OnePicCRFNum.Value = 24;
962 BlackFPSNum.Value = 1;
963 BlackCRFNum.Value = 51;
964 BlackBitrateNum.Value = 900;
966 maskb.Text = "000000";
967 maske.Text = "000020";
969 TransposeComboBox.SelectedIndex = 1;
971 #endregion General Tab
973 #region Mux Tab
975 cbFPS.SelectedIndex = 0;
976 Mp4BoxParComboBox.SelectedIndex = 0;
977 MuxAacEncoderComboBox.SelectedIndex = 0;
978 MuxFormatComboBox.Text = "flv";
980 #endregion Mux Tab
982 #region AVS Tab
984 AVSwithAudioCheckBox.Checked = false;
986 #endregion AVS Tab
988 #region Setup Tab
990 SplashScreenCheckBox.Checked = true;
991 TrayModeCheckBox.Checked = false;
992 x264PriorityComboBox.SelectedIndex = 2;
993 x264ThreadsComboBox.SelectedIndex = 0;
994 SetupDeleteTempFileCheckBox.Checked = true;
995 CheckUpdateCheckBox.Checked = true;
996 x265CheckBox.Checked = false;
998 #endregion Setup Tab
1001 private void LoadSettings()
1005 //load settings
1006 x264CRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264CRF"]);
1007 x264BitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Bitrate"]);
1008 x264AudioParameterTextBox.Text = ConfigurationManager.AppSettings["x264AudioParameter"];
1009 x264AudioModeComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264AudioMode"]);
1010 if (int.Parse(ConfigurationManager.AppSettings["x264Exe"]) > x264ExeComboBox.Items.Count - 1)
1011 x264ExeComboBox.SelectedIndex = 0;
1012 else
1013 x264ExeComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Exe"]);
1014 x264DemuxerComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Demuxer"]);
1015 x264WidthNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Width"]);
1016 x264HeightNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Height"]);
1017 x264CustomParameterTextBox.Text = ConfigurationManager.AppSettings["x264CustomParameter"];
1018 x264PriorityComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Priority"]);
1019 x264extraLine.Text = ConfigurationManager.AppSettings["x264ExtraParameter"];
1020 AVSScriptTextBox.Text = ConfigurationManager.AppSettings["AVSScript"];
1021 AudioEncoderComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["AudioEncoder"]);
1022 AudioBitrateComboBox.Text = ConfigurationManager.AppSettings["AudioBitrate"];
1023 OnePicAudioBitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicAudioBitrate"]);
1024 OnePicFPSNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicFPS"]);
1025 OnePicCRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicCRF"]);
1026 BlackFPSNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackFPS"]);
1027 BlackCRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackCRF"]);
1028 BlackBitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackBitrate"]);
1029 SetupDeleteTempFileCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["SetupDeleteTempFile"]);
1030 CheckUpdateCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["CheckUpdate"]);
1031 x264ThreadsComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Threads"]);
1032 x265CheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["x265Enable"]);
1033 TrayModeCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["TrayMode"]);
1034 SplashScreenCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["SplashScreen"]);
1035 SetupPlayerTextBox.Text = ConfigurationManager.AppSettings["PreviewPlayer"];
1036 string SubLangExt = Convert.ToString(ConfigurationManager.AppSettings["SubLanguageExtension"]);
1037 MuxFormatComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["MuxFormat"]);
1038 x264BatchSubSpecialLanguage.DataSource = SubLangExt.Split(',');
1039 if (x264ExeComboBox.SelectedIndex == -1)
1041 x264ExeComboBox.SelectedIndex = x264ExeComboBox.Items.IndexOf("x264_32-8bit");
1044 if (int.Parse(ConfigurationManager.AppSettings["LanguageIndex"]) == -1) //First Startup
1046 string culture = Thread.CurrentThread.CurrentCulture.Name;
1047 switch (culture)
1049 case "zh-CN":
1050 languageComboBox.SelectedIndex = 0;
1051 break;
1053 case "zh-SG":
1054 languageComboBox.SelectedIndex = 0;
1055 break;
1057 case "zh-TW":
1058 languageComboBox.SelectedIndex = 1;
1059 break;
1061 case "zh-HK ":
1062 languageComboBox.SelectedIndex = 1;
1063 break;
1065 case "zh-MO":
1066 languageComboBox.SelectedIndex = 1;
1067 break;
1069 case "en-US":
1070 languageComboBox.SelectedIndex = 2;
1071 break;
1073 case "ja-JP":
1074 languageComboBox.SelectedIndex = 3;
1075 break;
1077 default:
1078 break;
1081 else
1082 languageComboBox.SelectedIndex = int.Parse(ConfigurationManager.AppSettings["LanguageIndex"]);
1084 if (CheckUpdateCheckBox.Checked && Util.IsConnectInternet())
1086 DateTime d;
1087 bool f;
1088 CheckUpadateDelegate checkUpdateDelegate = CheckUpdate;
1089 checkUpdateDelegate.BeginInvoke(out d, out f, new AsyncCallback(CheckUpdateCallBack), null);
1091 x264ExeComboBox_SelectedIndexChanged(null, null);
1093 catch (Exception)
1095 throw;
1099 private void SaveSettings()
1101 Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
1102 cfa.AppSettings.Settings["x264CRF"].Value = x264CRFNum.Value.ToString();
1103 cfa.AppSettings.Settings["x264Bitrate"].Value = x264BitrateNum.Value.ToString();
1104 cfa.AppSettings.Settings["x264AudioParameter"].Value = x264AudioParameterTextBox.Text;
1105 cfa.AppSettings.Settings["x264AudioMode"].Value = x264AudioModeComboBox.SelectedIndex.ToString();
1106 cfa.AppSettings.Settings["x264Exe"].Value = x264ExeComboBox.SelectedIndex.ToString();
1107 cfa.AppSettings.Settings["x264Demuxer"].Value = x264DemuxerComboBox.SelectedIndex.ToString();
1108 cfa.AppSettings.Settings["x264Width"].Value = x264WidthNum.Value.ToString();
1109 cfa.AppSettings.Settings["x264Height"].Value = x264HeightNum.Value.ToString();
1110 cfa.AppSettings.Settings["x264CustomParameter"].Value = x264CustomParameterTextBox.Text;
1111 cfa.AppSettings.Settings["x264Priority"].Value = x264PriorityComboBox.SelectedIndex.ToString();
1112 cfa.AppSettings.Settings["x264ExtraParameter"].Value = x264extraLine.Text;
1113 cfa.AppSettings.Settings["AVSScript"].Value = AVSScriptTextBox.Text;
1114 cfa.AppSettings.Settings["AudioEncoder"].Value = AudioEncoderComboBox.SelectedIndex.ToString();
1115 cfa.AppSettings.Settings["AudioParameter"].Value = AudioBitrateComboBox.Text;
1116 cfa.AppSettings.Settings["OnePicAudioBitrate"].Value = OnePicAudioBitrateNum.Value.ToString();
1117 cfa.AppSettings.Settings["OnePicFPS"].Value = OnePicFPSNum.Value.ToString();
1118 cfa.AppSettings.Settings["OnePicCRF"].Value = OnePicCRFNum.Value.ToString();
1119 cfa.AppSettings.Settings["BlackFPS"].Value = BlackFPSNum.Value.ToString();
1120 cfa.AppSettings.Settings["BlackCRF"].Value = BlackCRFNum.Value.ToString();
1121 cfa.AppSettings.Settings["BlackBitrate"].Value = BlackBitrateNum.Value.ToString();
1122 cfa.AppSettings.Settings["SetupDeleteTempFile"].Value = SetupDeleteTempFileCheckBox.Checked.ToString();
1123 cfa.AppSettings.Settings["CheckUpdate"].Value = CheckUpdateCheckBox.Checked.ToString();
1124 cfa.AppSettings.Settings["TrayMode"].Value = TrayModeCheckBox.Checked.ToString();
1125 cfa.AppSettings.Settings["LanguageIndex"].Value = languageComboBox.SelectedIndex.ToString();
1126 cfa.AppSettings.Settings["SplashScreen"].Value = SplashScreenCheckBox.Checked.ToString();
1127 cfa.AppSettings.Settings["x264Threads"].Value = x264ThreadsComboBox.SelectedIndex.ToString();
1128 cfa.AppSettings.Settings["x265Enable"].Value = x265CheckBox.Checked.ToString();
1129 cfa.AppSettings.Settings["PreviewPlayer"].Value = SetupPlayerTextBox.Text;
1130 cfa.AppSettings.Settings["MuxFormat"].Value = MuxFormatComboBox.SelectedIndex.ToString(); ;
1131 cfa.Save();
1132 ConfigurationManager.RefreshSection("appSettings"); // 刷新命名节,在下次检索它时将从磁盘重新读取它。记住应用程序要刷新节点
1135 #endregion
1137 private void PresetXml()
1139 if (!File.Exists("preset.xml"))
1141 xdoc = new XDocument(
1142 new XDeclaration("1.0", "utf-8", "yes"),
1143 new XElement("root",
1144 new XElement("Video",
1145 new XElement("VideoEncoder",
1146 new XElement("x264",
1147 new XElement("Parameter", "--crf 24 --preset 8 -r 6 -b 6 -i 1 --scenecut 60 -f 1:1 --qcomp 0.5 --psy-rd 0.3:0 --aq-mode 2 --aq-strength 0.8 --vf resize:960,540,,,,lanczos", new XAttribute("Name", "default")),
1148 new XElement("Parameter", "-p1 --crf 20 --aq-mode 2 --sar 32:27 --vf yadif:, --stat \"TEMP.stat\" --slow-firstpass --ref 8 --preset 8 --subme 10", new XAttribute("Name", "DVDRIP不切边,16:9")),
1149 new XElement("Parameter", "-p1 --crf 20 --aq-mode 2 --sar 40:33 --vf yadif:, --stat \"TEMP.stat\" --slow-firstpass --ref 8 --preset 8 --subme 10", new XAttribute("Name", "DVDRIP不切边,sar40:33")),
1150 new XElement("Parameter", "-p1 --crf 20 --aq-mode 2 --sar 40:33 --vf yadif:,/crop:8,0,8,0 --stat \"TEMP.stat\" --slow-firstpass --ref 8 --preset 8 --subme 10", new XAttribute("Name", "DVDRIP切边,sar40:33")),
1151 new XElement("Parameter", "--profile high --level 3.1 --level-force --device iphone", new XAttribute("Name", "iOS")),
1152 new XElement("Parameter", "--crf 25 --preset placebo --subme 10 --ref 7 --bframes 7 --qcomp 0.75 --psy-rd 0:0 --keyint infinite --min-keyint 1", new XAttribute("Name", "MAD")),
1153 new XElement("Parameter", "--profile main --level 3.0 --ref 3 --b-pyramid none --weightp 1 --vbv-maxrate 10000 --vbv-bufsize 10000 --vf resize:480,272,,,,lanczos --device psp", new XAttribute("Name", "PSP"))
1155 new XElement("x265",
1156 new XElement("Parameter", "", new XAttribute("Name", "x265default"))
1160 new XElement("Audio",
1161 new XElement("AudioEncoder",
1162 new XElement("NeroAAC",
1163 new XElement("Parameter", "-he -br 32000", new XAttribute("Name", "NeroAAC_HE-32Kbps")),
1164 new XElement("Parameter", "-he -br 48000", new XAttribute("Name", "NeroAAC_HE-48Kbps")),
1165 new XElement("Parameter", "-he -br 64000", new XAttribute("Name", "NeroAAC_HE-64Kbps")),
1166 new XElement("Parameter", "-lc -br 128000", new XAttribute("Name", "NeroAAC_LC-128Kbps")),
1167 new XElement("Parameter", "-lc -br 192000", new XAttribute("Name", "NeroAAC_LC-192Kbps")),
1168 new XElement("Parameter", "-lc -br 256000", new XAttribute("Name", "NeroAAC_LC-256Kbps")),
1169 new XElement("Parameter", "-q 1 -lc", new XAttribute("Name", "NeroAAC_LC-Q1"))
1171 new XElement("FDKAAC",
1172 new XElement("Parameter", "-m 1", new XAttribute("Name", "FDKAAC_VBR1")),
1173 new XElement("Parameter", "-m 2", new XAttribute("Name", "FDKAAC_VBR2")),
1174 new XElement("Parameter", "-m 3", new XAttribute("Name", "FDKAAC_VBR3")),
1175 new XElement("Parameter", "-m 4", new XAttribute("Name", "FDKAAC_VBR4")),
1176 new XElement("Parameter", "-m 5", new XAttribute("Name", "FDKAAC_VBR5")),
1177 new XElement("Parameter", "-p 5 -b 64", new XAttribute("Name", "FDKAAC_HE-_CBR64Kbps")),
1178 new XElement("Parameter", "-b 128", new XAttribute("Name", "FDKAAC_LC-_CBR128Kbps")),
1179 new XElement("Parameter", "-b 192", new XAttribute("Name", "FDKAAC_LC-_CBR192Kbps")),
1180 new XElement("Parameter", "-b 256", new XAttribute("Name", "FDKAAC_LC-_CBR256Kbps"))
1182 new XElement("QAAC",
1183 new XElement("Parameter", "--he -c 64 -q 2 --no-optimize", new XAttribute("Name", "QAAC_HE-CBR64Kbps")),
1184 new XElement("Parameter", "--he -v 64 -q 2 --no-optimize", new XAttribute("Name", "QAAC_HE-CVBR64Kbps")),
1185 new XElement("Parameter", "-c 128 -q 2 --no-optimize", new XAttribute("Name", "QAAC_LC-CBR128Kbps")),
1186 new XElement("Parameter", "-v 128 -q 2 --no-optimize", new XAttribute("Name", "QAAC_LC-CVBR128Kbps")),
1187 new XElement("Parameter", "-c 256 -q 2 --no-optimize", new XAttribute("Name", "QAAC_LC-CBR256Kbps")),
1188 new XElement("Parameter", "-v 256 -q 2 --no-optimize", new XAttribute("Name", "QAAC_LC-CVBR256Kbps")),
1189 new XElement("Parameter", "-V 90 -q 2 --no-optimize", new XAttribute("Name", "QAAC_TVBR_V90")),
1190 new XElement("Parameter", "-V 127 -q 2 --no-optimize", new XAttribute("Name", "QAAC_TVBR_V127"))
1196 xdoc.Save("preset.xml");
1198 else
1199 xdoc = XDocument.Load("preset.xml");
1202 private void LoadVideoPreset()
1204 VideoPresetComboBox.Items.Clear();
1205 var xlsv = xdoc.Element("root").Element("Video").Element("VideoEncoder").Element("x264").Elements();
1206 foreach (var item in xlsv)
1208 VideoPresetComboBox.Items.Add(item.Attribute("Name").Value);
1210 if (VideoPresetComboBox.Items.Count > 0 && VideoPresetComboBox.SelectedIndex == -1)
1211 VideoPresetComboBox.SelectedIndex = 0;
1214 private void LoadAudioPreset()
1216 AudioPresetComboBox.Items.Clear();
1217 var xlsa = xdoc.Element("root").Element("Audio").Element("AudioEncoder").Element(AudioEncoderComboBox.Text).Elements();
1218 foreach (var item in xlsa)
1220 AudioPresetComboBox.Items.Add(item.Attribute("Name").Value);
1222 if (AudioPresetComboBox.Items.Count > 0 && AudioPresetComboBox.SelectedIndex == -1)
1223 AudioPresetComboBox.SelectedIndex = 0;
1226 private void Form1_Load(object sender, EventArgs e)
1228 SYSTEM_INFO pSI = new SYSTEM_INFO();
1229 GetSystemInfo(ref pSI);
1230 int processorNumber = (int)pSI.dwNumberOfProcessors;
1232 x264ThreadsComboBox.Items.Add("auto");
1233 for (int i = 1; i <= 16; i++)
1235 x264ThreadsComboBox.Items.Add(i.ToString());
1237 //Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-TW");
1238 //use YAHEI in VistaOrNewer
1239 //if (IsWindowsVistaOrNewer)
1241 // FontFamily myFontFamily = new FontFamily("微软雅黑"); //采用哪种字体
1242 // Font myFont = new Font(myFontFamily, 9, FontStyle.Regular); //字是那种字体,显示的风格
1243 // this.Font = myFont;
1246 //define workpath
1247 startpath = System.Windows.Forms.Application.StartupPath;
1248 workPath = startpath + "\\tools";
1249 if (!Directory.Exists(workPath))
1251 MessageBox.Show("tools文件夹没有解压喔~ 工具箱里没有工具的话运行不起来的喔~", "(这只丸子)",
1252 MessageBoxButtons.OK, MessageBoxIcon.Error);
1253 Environment.Exit(1);
1255 //Directory.CreateDirectory(workPath);
1256 //string diskSymbol = startpath.Substring(0, 1);
1258 //string systemDisk = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 3);
1259 //string systemTempPath = systemDisk + @"windows\temp";
1260 string systemTempPath = Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.Machine);
1261 tempavspath = systemTempPath + "\\temp.avs";
1262 tempPic = systemTempPath + "\\marukotemp.jpg";
1263 tempfilepath = startpath + "\\temp";
1265 //load x264 exe
1266 DirectoryInfo folder = new DirectoryInfo(workPath);
1267 List<string> x264exe = new List<string>();
1270 bool usex265 = bool.Parse(ConfigurationManager.AppSettings["x265Enable"].ToString());
1271 foreach (FileInfo FileName in folder.GetFiles())
1273 if ((FileName.Name.ToLower().Contains("x264") || FileName.Name.ToLower().Contains(usex265 ? "x265" : "xxxx")) && Path.GetExtension(FileName.Name) == ".exe")
1275 x264exe.Add(FileName.Name);
1278 x264exe = x264exe.OrderByDescending(i => i.Substring(7)).ToList();
1279 x264ExeComboBox.Items.AddRange(x264exe.ToArray());
1281 catch { }
1283 // avisynth未安装使用本地内置的avs
1284 if (string.IsNullOrEmpty(Util.CheckAviSynth()))
1286 string sourceAviSynthdll = Path.Combine(workPath, @"avs\AviSynth.dll");
1287 string sourceDevILdll = Path.Combine(workPath, @"avs\DevIL.dll");
1288 if (File.Exists(sourceAviSynthdll) && File.Exists(sourceDevILdll))
1290 File.Copy(sourceAviSynthdll, Path.Combine(workPath, "AviSynth.dll"), true);
1291 File.Copy(sourceDevILdll, Path.Combine(workPath, "DevIL.dll"), true);
1292 LogRecord("未安装avisynth,使用本地内置avs.");
1295 else
1297 File.Delete(Path.Combine(workPath, "AviSynth.dll"));
1298 File.Delete(Path.Combine(workPath, "DevIL.dll"));
1301 //load AVS filter
1302 DirectoryInfo avspath = new DirectoryInfo(workPath + @"\avs\plugins");
1303 List<string> avsfilters = new List<string>();
1304 if (Directory.Exists(workPath + @"\avs\plugins"))
1306 foreach (FileInfo FileName in avspath.GetFiles())
1308 if (Path.GetExtension(FileName.Name) == ".dll")
1310 avsfilters.Add(FileName.Name);
1313 AVSFilterComboBox.Items.AddRange(avsfilters.ToArray());
1316 //ReleaseDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
1317 ReleaseDatelabel.Text = ReleaseDate.ToString("yyyy-M-d");
1319 // load Help Text
1320 if (File.Exists(startpath + "\\help.rtf"))
1322 HelpTextBox.LoadFile(startpath + "\\help.rtf");
1325 PresetXml();
1326 LoadVideoPreset();
1327 LoadSettings();
1330 private void button2_Click(object sender, EventArgs e)
1332 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
1333 DialogResult result = openFileDialog1.ShowDialog();
1334 if (result == DialogResult.OK)
1336 namevideo6 = openFileDialog1.FileName;
1337 txtvideo6.Text = namevideo6;
1341 private void button3_Click(object sender, EventArgs e)
1343 if (namevideo6 == "")
1345 ShowErrorMessage("请选择视频文件");
1347 else
1349 mkvextract = workPath + "\\ mkvextract.exe tracks \"" + namevideo6 + "\" 1:video.h264 2:audio.aac";
1350 batpath = workPath + "\\mkvextract.bat";
1351 File.WriteAllText(batpath, mkvextract, Encoding.Default);
1352 Process.Start(batpath);
1356 private void button4_Click(object sender, EventArgs e)
1358 openFileDialog1.Filter = "视频(*.mp4)|*.mp4|所有文件(*.*)|*.*";
1359 DialogResult result = openFileDialog1.ShowDialog();
1360 if (result == DialogResult.OK)
1362 namevideo5 = openFileDialog1.FileName;
1363 txtvideo5.Text = namevideo5;
1367 private void button5_Click(object sender, EventArgs e)
1369 openFileDialog1.Filter = "音频(*.mp3)|*.mp3|音频(*.aac)|*.aac|所有文件(*.*)|*.*";
1370 DialogResult result = openFileDialog1.ShowDialog();
1371 if (result == DialogResult.OK)
1373 nameaudio3 = openFileDialog1.FileName;
1374 txtaudio3.Text = nameaudio3;
1378 private void button6_Click(object sender, EventArgs e)
1380 SaveFileDialog savefile = new SaveFileDialog();
1381 savefile.Filter = "视频(*.mkv)|*.mkv";
1382 DialogResult result = savefile.ShowDialog();
1383 if (result == DialogResult.OK)
1385 nameout6 = savefile.FileName;
1386 txtout6.Text = nameout6;
1390 private void button7_Click(object sender, EventArgs e)
1392 if (namevideo5 == "")
1394 ShowErrorMessage("请选择视频文件");
1396 else if (nameaudio3 == "")
1398 ShowErrorMessage("请选择音频文件");
1400 else if (nameout6 == "")
1402 ShowErrorMessage("请选择输出文件");
1404 else
1406 mkvmerge = workPath + "\\mkvmerge.exe -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\"";
1407 batpath = workPath + "\\mkvmerge.bat";
1408 File.WriteAllText(batpath, mkvmerge, Encoding.Default);
1409 Process.Start(batpath);
1413 private void button2_Click_1(object sender, EventArgs e)
1415 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1416 DialogResult result = openFileDialog1.ShowDialog();
1417 if (result == DialogResult.OK)
1419 namevideo5 = openFileDialog1.FileName;
1420 txtvideo5.Text = namevideo5;
1424 private void button6_Click_1(object sender, EventArgs e)
1426 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
1427 DialogResult result = openFileDialog1.ShowDialog();
1428 if (result == DialogResult.OK)
1430 namevideo6 = openFileDialog1.FileName;
1431 txtvideo6.Text = namevideo6;
1435 private void button7_Click_1(object sender, EventArgs e)
1437 if (namevideo5 == "" && nameaudio3 == "")
1439 ShowErrorMessage("请选择文件");
1441 else
1443 if (txtaudio3.Text != "" && txtsub.Text != "")
1445 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\" \"" + namesub + "\"";
1447 if (txtaudio3.Text == "" && txtsub.Text == "")
1449 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\"";
1451 if (txtaudio3.Text != "" && txtsub.Text == "")
1453 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\"";
1455 if (txtaudio3.Text == "" && txtsub.Text != "")
1457 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + namesub + "\"";
1459 mkvmerge += "\r\ncmd";
1460 batpath = workPath + "\\mkvmerge.bat";
1461 File.WriteAllText(batpath, mkvmerge, Encoding.Default);
1462 LogRecord(mkvmerge);
1463 Process.Start(batpath);
1467 private void button4_Click_1(object sender, EventArgs e)
1469 SaveFileDialog savefile = new SaveFileDialog();
1470 savefile.Filter = "视频(*.mkv)|*.mkv";
1471 DialogResult result = savefile.ShowDialog();
1472 if (result == DialogResult.OK)
1474 nameout6 = savefile.FileName;
1475 txtout6.Text = nameout6;
1479 private void button3_Click_1(object sender, EventArgs e)
1481 openFileDialog1.Filter = "音频(*.mp3;*.aac;*.ac3)|*.mp3;*.aac;*.ac3|所有文件(*.*)|*.*";
1482 DialogResult result = openFileDialog1.ShowDialog();
1483 if (result == DialogResult.OK)
1485 nameaudio3 = openFileDialog1.FileName;
1486 txtaudio3.Text = nameaudio3;
1490 private void button5_Click_1(object sender, EventArgs e)
1492 openFileDialog1.Filter = "字幕(*.ass;*.ssa;*.srt)|*.ass;*.ssa;*.srt|所有文件(*.*)|*.*";
1493 DialogResult result = openFileDialog1.ShowDialog();
1494 if (result == DialogResult.OK)
1496 namesub = openFileDialog1.FileName;
1497 txtsub.Text = namesub;
1501 private void button8_Click(object sender, EventArgs e)
1503 if (namevideo6 == "")
1505 ShowErrorMessage("请选择视频文件");
1507 else
1509 int i = namevideo6.IndexOf(".mkv");
1510 string mkvname = namevideo6.Remove(i);
1511 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 1:\"" + mkvname + "_video.h264\" 2:\"" + mkvname + "_audio.aac\"";
1512 batpath = workPath + "\\mkvextract.bat";
1513 File.WriteAllText(batpath, mkvextract, Encoding.Default);
1514 Process.Start(batpath);
1518 private void txtvideo5_TextChanged(object sender, EventArgs e)
1520 if (File.Exists(txtvideo5.Text.ToString()))
1522 namevideo5 = txtvideo5.Text;
1523 string finish = namevideo5.Remove(namevideo5.LastIndexOf("."));
1524 finish += "_mkv封装.mkv";
1525 txtout6.Text = finish;
1529 private void txtaudio3_TextChanged(object sender, EventArgs e)
1531 nameaudio3 = txtaudio3.Text;
1534 private void txtsub_TextChanged(object sender, EventArgs e)
1536 namesub = txtsub.Text;
1539 private void txtout6_TextChanged_1(object sender, EventArgs e)
1541 nameout6 = txtout6.Text;
1544 private void txtvideo6_TextChanged(object sender, EventArgs e)
1546 namevideo6 = txtvideo6.Text;
1549 private void btnAutoAdd_Click(object sender, EventArgs e)
1551 openFileDialog1.Multiselect = true;
1552 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1553 DialogResult result = openFileDialog1.ShowDialog();
1554 if (result == DialogResult.OK)
1556 lbAuto.Items.AddRange(openFileDialog1.FileNames);
1560 private void btnAutoDel_Click(object sender, EventArgs e)
1562 if (lbAuto.Items.Count > 0)
1564 if (lbAuto.SelectedItems.Count > 0)
1566 int index = lbAuto.SelectedIndex;
1567 lbAuto.Items.RemoveAt(lbAuto.SelectedIndex);
1568 if (index == lbAuto.Items.Count)
1570 lbAuto.SelectedIndex = index - 1;
1572 if (index >= 0 && index < lbAuto.Items.Count && lbAuto.Items.Count > 0)
1574 lbAuto.SelectedIndex = index;
1580 private void btnAutoClear_Click(object sender, EventArgs e)
1582 lbAuto.Items.Clear();
1585 private void lbAuto_DragDrop(object sender, DragEventArgs e)
1587 ListBox listbox = (ListBox)sender;
1588 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
1590 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
1591 foreach (String s in files)
1593 listbox.Items.Add(s);
1595 return;
1597 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
1598 if (indexoftarget != ListBox.NoMatches)
1600 string temp = listbox.Items[indexoftarget].ToString();
1601 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
1602 listbox.Items[indexofsource] = temp;
1603 listbox.SelectedIndex = indexoftarget;
1607 private void lbAuto_DragEnter(object sender, DragEventArgs e)
1609 //if (e.Data.GetDataPresent(DataFormats.FileDrop))
1610 // e.Effect = DragDropEffects.All;
1611 //else e.Effect = DragDropEffects.None;
1614 private void lbAuto_DragOver(object sender, DragEventArgs e)
1616 //拖动源和放置的目的地一定是一个ListBox
1617 ListBox listbox = (ListBox)sender;
1618 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(listbox))
1620 e.Effect = DragDropEffects.Move;
1622 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
1624 e.Effect = DragDropEffects.Link;
1626 else e.Effect = DragDropEffects.None;
1629 private void lbAuto_MouseDown(object sender, MouseEventArgs e)
1631 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
1632 if (indexofsource == 65535)
1633 return;
1634 if (indexofsource != ListBox.NoMatches)
1636 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
1640 public string VideoBatch(string input, string output)
1642 bool hasAudio = false;
1643 string bat = "";
1644 string inputName = Path.GetFileNameWithoutExtension(input);
1645 string tempVideo = Path.Combine(tempfilepath, inputName + "_vtemp.mp4");
1646 string tempAudio = Path.Combine(tempfilepath, inputName + "_atemp" + getAudioExt());
1648 //检测是否含有音频
1649 MediaInfo MI = new MediaInfo();
1650 MI.Open(input);
1651 string audio = MI.Get(StreamKind.Audio, 0, "Format");
1652 if (!string.IsNullOrEmpty(audio)) { hasAudio = true; }
1653 string sub = (x264BatchSubCheckBox.Checked) ? GetSubtitlePath(input) : string.Empty;
1655 int audioMode = x264AudioModeComboBox.SelectedIndex;
1656 if (!hasAudio)
1657 audioMode = 1;
1658 switch (audioMode)
1660 case 0:
1661 aextract = audiobat(input, tempAudio);
1662 break;
1663 case 1:
1664 aextract = string.Empty;
1665 break;
1666 case 2:
1667 if (audio.ToLower() == "aac")
1669 tempAudio = Path.Combine(tempfilepath, inputName + "_atemp.aac");
1670 aextract = ExtractAudio(input, tempAudio);
1672 else
1673 aextract = audiobat(input, tempAudio);
1674 break;
1675 default:
1676 break;
1679 if (x264ExeComboBox.SelectedItem.ToString().ToLower().Contains("x264"))
1681 if (x264mode == 2)
1682 x264 = x264bat(input, tempVideo, 1, sub) + "\r\n" +
1683 x264bat(input, tempVideo, 2, sub);
1684 else x264 = x264bat(input, tempVideo, 0, sub);
1685 if (audioMode == 1 || !hasAudio)
1686 x264 = x264.Replace(tempVideo, output);
1688 else if (x264ExeComboBox.SelectedItem.ToString().ToLower().Contains("x265"))
1690 tempVideo = Path.Combine(tempfilepath, inputName + "_vtemp.hevc");
1691 if (x264mode == 2)
1692 x264 = x265bat(input, tempVideo, 1) + "\r\n" +
1693 x265bat(input, tempVideo, 2);
1694 else x264 = x265bat(input, tempVideo);
1695 if (audioMode == 1 || !hasAudio)
1696 x264 += "\r\n\"" + workPath + "\\mp4box.exe\" -add \"" + tempVideo + "#trackID=1:name=\" -new \"" + output + "\" \r\n";
1698 x264 += "\r\n";
1700 //封装
1701 if (VideoBatchFormatComboBox.Text == "mp4")
1702 mux = boxmuxbat(tempVideo, tempAudio, output);
1703 else
1704 mux = ffmuxbat(tempVideo, tempAudio, output);
1705 if (audioMode != 1 && hasAudio) //如果压制音频
1706 bat += aextract + x264 + mux + " \r\n";
1707 else
1708 bat += x264 + " \r\n";
1710 bat += "del \"" + tempAudio + "\"\r\n";
1711 bat += "del \"" + tempVideo + "\"\r\n";
1712 bat += "echo ===== one file is completed! =====\r\n";
1713 return bat;
1716 private void btnBatchAuto_Click(object sender, EventArgs e)
1718 if (lbAuto.Items.Count == 0)
1720 ShowErrorMessage("请输入视频!");
1721 return;
1724 if (x264ExeComboBox.SelectedIndex == -1)
1726 ShowErrorMessage("请选择X264程序");
1727 return;
1730 Util.ensureDirectoryExists(tempfilepath);
1731 string bat = string.Empty;
1732 for (int i = 0; i < this.lbAuto.Items.Count; i++)
1734 string input = lbAuto.Items[i].ToString();
1735 string output;
1736 if (Directory.Exists(x264PathTextBox.Text))
1737 output = x264PathTextBox.Text + "\\" + Path.GetFileNameWithoutExtension(input) + "_batch." + VideoBatchFormatComboBox.Text;
1738 else
1739 output = Util.ChangeExt(input, "_batch." + VideoBatchFormatComboBox.Text);
1740 bat += VideoBatch(lbAuto.Items[i].ToString(), output);
1743 LogRecord(bat);
1744 Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(GetCultureName());
1745 WorkingForm wf = new WorkingForm(bat, lbAuto.Items.Count);
1746 wf.Owner = this;
1747 wf.Show();
1748 //batpath = workPath + "\\auto.bat";
1749 //File.WriteAllText(batpath, bat, Encoding.Default);
1750 //Process.Start(batpath);
1753 private void lbffmpeg_MouseDown(object sender, MouseEventArgs e)
1755 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
1756 if (indexofsource != ListBox.NoMatches)
1758 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
1762 private void lbffmpeg_DragDrop(object sender, DragEventArgs e)
1764 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
1766 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
1767 foreach (String s in files)
1769 (sender as ListBox).Items.Add(s);
1772 ListBox listbox = (ListBox)sender;
1773 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
1774 if (indexoftarget != ListBox.NoMatches)
1776 string temp = listbox.Items[indexoftarget].ToString();
1777 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
1778 listbox.Items[indexofsource] = temp;
1779 listbox.SelectedIndex = indexoftarget;
1783 private void lbffmpeg_DragOver(object sender, DragEventArgs e)
1785 //拖动源和放置的目的地一定是一个ListBox
1786 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lbffmpeg))
1788 e.Effect = DragDropEffects.Move;
1790 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
1792 e.Effect = DragDropEffects.Link;
1794 else e.Effect = DragDropEffects.None;
1797 private void btnffmpegAdd_Click(object sender, EventArgs e)
1799 openFileDialog1.Multiselect = true;
1800 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1801 DialogResult result = openFileDialog1.ShowDialog();
1802 if (result == DialogResult.OK)
1804 lbffmpeg.Items.AddRange(openFileDialog1.FileNames);
1808 private void btnffmpegDel_Click(object sender, EventArgs e)
1810 if (lbffmpeg.Items.Count > 0)
1812 if (lbffmpeg.SelectedItems.Count > 0)
1814 int index = lbffmpeg.SelectedIndex;
1815 lbffmpeg.Items.RemoveAt(lbffmpeg.SelectedIndex);
1816 if (index == lbffmpeg.Items.Count)
1818 lbffmpeg.SelectedIndex = index - 1;
1820 if (index >= 0 && index < lbffmpeg.Items.Count && lbffmpeg.Items.Count > 0)
1822 lbffmpeg.SelectedIndex = index;
1828 private void btnffmpegClear_Click(object sender, EventArgs e)
1830 lbffmpeg.Items.Clear();
1833 private void btnBatchMP4_Click(object sender, EventArgs e)
1835 if (lbffmpeg.Items.Count != 0)
1837 string ext = MuxFormatComboBox.Text;
1838 string mux = "";
1839 for (int i = 0; i < lbffmpeg.Items.Count; i++)
1841 string filePath = lbffmpeg.Items[i].ToString();
1842 //如果是源文件的格式和目标格式相同则跳过
1843 if (Path.GetExtension(filePath).Contains(ext))
1844 continue;
1845 string finish = filePath.Remove(filePath.LastIndexOf(".") + 1) + ext;
1846 aextract = "";
1848 //检测音频是否需要转换为AAC
1849 MediaInfo MI = new MediaInfo();
1850 MI.Open(filePath);
1851 string audio = MI.Get(StreamKind.Audio, 0, "Format");
1852 if (audio.ToLower() != "aac")
1854 mux += "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + lbffmpeg.Items[i].ToString() + "\" -c:v copy -c:a " + MuxAacEncoderComboBox.Text + " \"" + finish + "\" \r\n";
1856 else
1858 mux += "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + lbffmpeg.Items[i].ToString() + "\" -c copy \"" + finish + "\" \r\n";
1861 mux += "\r\ncmd";
1862 batpath = workPath + "\\mux.bat";
1863 File.WriteAllText(batpath, mux, Encoding.Default);
1864 LogRecord(mux);
1865 Process.Start(batpath);
1867 else ShowErrorMessage("请输入视频!");
1870 private void txtvideo8_TextChanged(object sender, EventArgs e)
1872 namevideo8 = txtvideo8.Text;
1875 private void btnvextract8_Click(object sender, EventArgs e)
1877 //FLV vcopy
1878 ExtractAV(namevideo8, "v", 0);
1879 //if (namevideo8 == "")
1881 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1883 //else
1885 // vextract = "\"" + workPath + "\\FLVExtractCL.exe\" -v \"" + namevideo8 + "\"";
1886 // batpath = workPath + "\\vextract.bat";
1887 // File.WriteAllText(batpath, vextract, Encoding.Default);
1888 // LogRecord(vextract);
1889 // Process.Start(batpath);
1893 private void btnaextract8_Click(object sender, EventArgs e)
1895 //FLV acopy
1896 ExtractAV(namevideo8, "a", 0);
1897 //if (namevideo8 == "")
1899 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1901 //else
1903 // aextract = "\"" + workPath + "\\FLVExtractCL.exe\" -a \"" + namevideo8 + "\"";
1904 // batpath = workPath + "\\aextract.bat";
1905 // File.WriteAllText(batpath, aextract, Encoding.Default);
1906 // LogRecord(aextract);
1907 // Process.Start(batpath);
1911 private void btnvideo8_Click(object sender, EventArgs e)
1913 openFileDialog1.Filter = "视频(*.flv;*.hlv)|*.flv;*.hlv";
1914 DialogResult result = openFileDialog1.ShowDialog();
1915 if (result == DialogResult.OK)
1917 namevideo8 = openFileDialog1.FileName;
1918 txtvideo8.Text = namevideo;
1922 private void btnpreview9_Click(object sender, EventArgs e)
1924 if (AVSScriptTextBox.Text != "")
1926 string filepath = workPath + "\\temp.avs";
1927 File.WriteAllText(filepath, AVSScriptTextBox.Text.ToString(), Encoding.Default);
1928 if (File.Exists(SetupPlayerTextBox.Text))
1930 Process.Start(SetupPlayerTextBox.Text, filepath);
1932 else
1934 PreviewForm pf = new PreviewForm();
1935 pf.Show();
1936 pf.axWindowsMediaPlayer1.URL = filepath;
1939 else
1941 ShowErrorMessage("请输入正确的AVS脚本!");
1945 private void txtout_MouseDoubleClick(object sender, MouseEventArgs e)
1947 if (File.Exists(txtout.Text.ToString()))
1949 Process.Start(txtout.Text.ToString());
1953 private void txtout3_MouseDoubleClick(object sender, MouseEventArgs e)
1955 if (File.Exists(AudioOutputTextBox.Text.ToString()))
1957 Process.Start(AudioOutputTextBox.Text.ToString());
1961 private void txtout6_MouseDoubleClick(object sender, MouseEventArgs e)
1963 if (File.Exists(txtout6.Text.ToString()))
1965 Process.Start(txtout6.Text.ToString());
1969 private void txtout9_MouseDoubleClick(object sender, MouseEventArgs e)
1971 if (File.Exists(txtout9.Text.ToString()))
1973 Process.Start(txtout9.Text.ToString());
1977 private void txtvideo9_TextChanged(object sender, EventArgs e)
1979 if (File.Exists(txtvideo9.Text.ToString()))
1981 namevideo9 = txtvideo9.Text;
1982 string finish = namevideo9.Remove(namevideo9.LastIndexOf("."));
1983 finish += "_AVS压制.mp4";
1984 txtout9.Text = finish;
1985 GenerateAVS();
1987 //if (txtvideo9.Text != "")
1989 // if (txtAVS.Text != "")
1990 // {
1991 // txtAVS.Text = txtAVS.Text.Replace(prevideo9, txtvideo9.Text);
1992 // }
1993 // else
1994 // {
1995 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1996 // foreach (FileInfo FileName in TheFolder.GetFiles())
1997 // {
1998 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1999 // }
2000 // avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\n" + "TextSub(\"" + namesub9 + "\")\r\n";
2001 // txtAVS.Text = avs;
2002 // avs = "";
2003 // }
2004 // prevideo9 = txtvideo9.Text;
2008 private void txtsub9_TextChanged(object sender, EventArgs e)
2010 namesub9 = txtsub9.Text;
2011 GenerateAVS();
2012 //if (txtAVS.Text != "")
2014 // txtAVS.Text=txtAVS.Text.Replace(namesub9, txtsub9.Text);
2015 // namesub9 = txtsub9.Text;
2017 //else
2019 // namesub9 = txtsub9.Text;
2020 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
2021 // foreach (FileInfo FileName in TheFolder.GetFiles())
2022 // {
2023 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
2024 // }
2025 // avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\n" + "TextSub(\"" + namesub9 + "\")\r\n";
2026 // txtAVS.Text = avs;
2027 // avs = "";
2031 private void txtout9_TextChanged(object sender, EventArgs e)
2033 nameout9 = txtout9.Text;
2036 private void btnAVS9_Click(object sender, EventArgs e)
2038 x264DemuxerComboBox.SelectedIndex = 0; //压制AVS始终使用分离器为auto
2040 if (string.IsNullOrEmpty(nameout9))
2042 ShowErrorMessage("请选择输出文件");
2043 return;
2046 if (Path.GetExtension(nameout9).ToLower() != ".mp4")
2048 ShowErrorMessage("仅支持MP4输出", "不支持的输出格式");
2049 return;
2052 if (File.Exists(txtout9.Text.Trim()))
2054 DialogResult dgs = ShowQuestion("目标文件:\r\n\r\n" + txtout9.Text.Trim() + "\r\n\r\n已经存在,是否覆盖继续压制?", "目标文件已经存在");
2055 if (dgs == DialogResult.No) return;
2058 if (string.IsNullOrEmpty(Util.CheckAviSynth()) && string.IsNullOrEmpty(Util.CheckinternalAviSynth()))
2060 if (ShowQuestion("检测到本机未安装avisynth无法继续压制,是否去下载安装", "avisynth未安装") == DialogResult.Yes)
2061 Process.Start("http://sourceforge.net/projects/avisynth2/");
2062 return;
2065 string inputName = Path.GetFileNameWithoutExtension(namevideo9);
2066 string tempVideo = Path.Combine(tempfilepath, inputName + "_vtemp.mp4");
2067 string tempAudio = Path.Combine(tempfilepath, inputName + "_atemp" + getAudioExt());
2068 Util.ensureDirectoryExists(tempfilepath);
2070 string filepath = tempavspath;
2071 //string filepath = workpath + "\\temp.avs";
2072 File.WriteAllText(filepath, AVSScriptTextBox.Text, Encoding.Default);
2074 //检测是否含有音频
2075 bool hasAudio = false;
2076 MediaInfo MI = new MediaInfo();
2077 MI.Open(namevideo9);
2078 string audio = MI.Get(StreamKind.Audio, 0, "Format");
2079 if (!string.IsNullOrEmpty(audio)) { hasAudio = true; }
2081 //audio
2082 if (AVSwithAudioCheckBox.Checked && hasAudio)
2084 if (!File.Exists(txtvideo9.Text))
2086 ShowErrorMessage("请选择视频文件");
2087 return;
2089 aextract = audiobat(namevideo9, tempAudio);
2091 else
2092 aextract = string.Empty;
2094 //video
2095 if (x264ExeComboBox.SelectedItem.ToString().ToLower().Contains("x264"))
2097 if (x264mode == 2)
2098 x264 = x264bat(filepath, tempVideo, 1) + "\r\n" +
2099 x264bat(filepath, tempVideo, 2);
2100 else x264 = x264bat(filepath, tempVideo);
2101 if (!AVSwithAudioCheckBox.Checked || !hasAudio)
2102 x264 = x264.Replace(tempVideo, nameout9);
2104 else if (x264ExeComboBox.SelectedItem.ToString().ToLower().Contains("x265"))
2106 tempVideo = Path.Combine(tempfilepath, inputName + "_vtemp.hevc");
2107 if (x264mode == 2)
2108 x264 = x265bat(filepath, tempVideo, 1) + "\r\n" +
2109 x265bat(filepath, tempVideo, 2);
2110 else x264 = x265bat(filepath, tempVideo);
2111 if (!AVSwithAudioCheckBox.Checked || !hasAudio)
2113 x264 += "\r\n\"" + workPath + "\\mp4box.exe\" -add \"" + tempVideo + "#trackID=1:name=\" -new \"" + nameout9 + "\" \r\n";
2114 x264 += "del \"" + tempVideo + "\"";
2117 //mux
2118 if (AVSwithAudioCheckBox.Checked && hasAudio) //如果包含音频
2119 mux = boxmuxbat(tempVideo, tempAudio, nameout9);
2120 else
2121 mux = string.Empty;
2123 auto = aextract + x264 + "\r\n" + mux + " \r\n";
2124 auto += "\r\necho ===== one file is completed! =====\r\n";
2125 LogRecord(auto);
2126 Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(GetCultureName());
2127 WorkingForm wf = new WorkingForm(auto);
2128 wf.Owner = this;
2129 wf.Show();
2130 //auto += "\r\ncmd";
2131 //batpath = workPath + "\\x264avs.bat";
2132 //File.WriteAllText(batpath, auto, Encoding.Default);
2133 //Process.Start(batpath);
2136 private void btnout9_Click(object sender, EventArgs e)
2138 SaveFileDialog savefile = new SaveFileDialog();
2139 savefile.Filter = "视频(*.mp4)|*.mp4";
2140 DialogResult result = savefile.ShowDialog();
2141 if (result == DialogResult.OK)
2143 txtout9.Text = nameout9 = savefile.FileName;
2147 private void button6_Click_2(object sender, EventArgs e)
2149 //if (Directory.Exists("avsfilter"))
2151 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
2152 // foreach (FileInfo FileName in TheFolder.GetFiles())
2153 // {
2154 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
2155 // }
2157 avs += "LoadPlugin(\"avs\\plugins\\VSFilter.DLL\")\r\n";
2158 avs += string.Format("\r\nLWLibavVideoSource(\"{0}\",23.976,convertFPS=True)\r\nConvertToYV12()\r\nCrop(0,0,0,0)\r\nAddBorders(0,0,0,0)\r\n" + "TextSub(\"{1}\")\r\n#LanczosResize(1280,960)\r\n", namevideo9, namesub9);
2159 //avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\nCrop(0,0,0,0)\r\nAddBorders(0,0,0,0)\r\n" + "TextSub(\"" + namesub9 + "\")\r\n#LanczosResize(1280,960)\r\n";
2160 AVSScriptTextBox.Text = avs;
2161 avs = "";
2164 private void txth264_TextChanged(object sender, EventArgs e)
2168 private void txtvideo_MouseDoubleClick(object sender, MouseEventArgs e)
2170 if (File.Exists(txtvideo.Text.ToString()))
2172 Process.Start(txtvideo.Text.ToString());
2176 private void txtvideo4_MouseDoubleClick(object sender, MouseEventArgs e)
2178 if (File.Exists(txtvideo4.Text.ToString()))
2180 Process.Start(txtvideo4.Text.ToString());
2184 private void txtout5_MouseDoubleClick(object sender, MouseEventArgs e)
2186 if (File.Exists(txtout5.Text.ToString()))
2188 Process.Start(txtout5.Text.ToString());
2192 private void txtvideo8_MouseDoubleClick(object sender, MouseEventArgs e)
2194 if (File.Exists(txtvideo8.Text.ToString()))
2196 Process.Start(txtvideo8.Text.ToString());
2200 private void txtvideo9_MouseDoubleClick(object sender, MouseEventArgs e)
2202 if (File.Exists(txtvideo9.Text.ToString()))
2204 Process.Start(txtvideo9.Text.ToString());
2208 private void txtvideo6_MouseDoubleClick(object sender, MouseEventArgs e)
2210 if (File.Exists(txtvideo6.Text.ToString()))
2212 Process.Start(txtvideo6.Text.ToString());
2216 private void txtvideo5_MouseDoubleClick(object sender, MouseEventArgs e)
2218 if (File.Exists(txtvideo5.Text.ToString()))
2220 Process.Start(txtvideo5.Text.ToString());
2224 private void txtaudio3_MouseDoubleClick(object sender, MouseEventArgs e)
2226 if (File.Exists(txtaudio3.Text.ToString()))
2228 Process.Start(txtaudio3.Text.ToString());
2232 private void timer1_Tick(object sender, EventArgs e)
2234 Process[] processes = Process.GetProcesses();
2235 for (int i = 0; i < processes.GetLength(0); i++)
2237 //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
2238 if (processes[i].ProcessName.Equals(Path.GetFileNameWithoutExtension(x264ExeComboBox.Text)))
2240 switch (x264PriorityComboBox.SelectedIndex)
2242 case 0: processes[i].PriorityClass = ProcessPriorityClass.Idle; break;
2243 case 1: processes[i].PriorityClass = ProcessPriorityClass.BelowNormal; break;
2244 case 2: processes[i].PriorityClass = ProcessPriorityClass.Normal; break;
2245 case 3: processes[i].PriorityClass = ProcessPriorityClass.AboveNormal; break;
2246 case 4: processes[i].PriorityClass = ProcessPriorityClass.High; break;
2247 case 5: processes[i].PriorityClass = ProcessPriorityClass.RealTime; break;
2253 private void btnsub9_Click(object sender, EventArgs e)
2255 openFileDialog1.Filter = "字幕(*.ass;*.ssa;*.srt)|*.ass;*.ssa;*.srt|所有文件(*.*)|*.*";
2256 DialogResult result = openFileDialog1.ShowDialog();
2257 if (result == DialogResult.OK)
2259 namesub9 = openFileDialog1.FileName;
2260 txtsub9.Text = namesub9;
2264 private void btnvideo9_Click(object sender, EventArgs e)
2266 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv;*.wmv)|*.mp4;*.flv;*.mkv;*.wmv|所有文件(*.*)|*.*";
2267 DialogResult result = openFileDialog1.ShowDialog();
2268 if (result == DialogResult.OK)
2270 namevideo9 = openFileDialog1.FileName;
2271 txtvideo9.Text = namevideo9;
2275 private void button9_Click(object sender, EventArgs e)
2277 AVSScriptTextBox.Clear();
2280 private void btnClip_Click(object sender, EventArgs e)
2282 if (namevideo4 == "")
2284 ShowErrorMessage("请选择视频文件");
2286 else if (nameout5 == "")
2288 ShowErrorMessage("请选择输出文件");
2290 else
2292 //int h1 = int.Parse(maskb.Text.ToString().Substring(0, 2));
2293 //int m1 = int.Parse(maskb.Text.ToString().Substring(3, 2));
2294 //int s1 = int.Parse(maskb.Text.ToString().Substring(6, 2));
2295 //int h2 = int.Parse(maske.Text.ToString().Substring(0, 2));
2296 //int m2 = int.Parse(maske.Text.ToString().Substring(3, 2));
2297 //int s2 = int.Parse(maske.Text.ToString().Substring(6, 2));
2298 //clip = "\"" + workPath + "\\ffmpeg.exe\" -ss " + maskb.Text + " -to " + maske.Text + " -i \"" + namevideo4 + "\" -acodec copy -vcodec copy \"" + nameout5 + "\" \r\ncmd";
2300 // "<workPath>\ffmpeg.exe" -i "<namevideo4>" -ss <maskb.Text> -to <maske.Text> -c copy "<nameout5>"
2301 clip = string.Format(@"""{0}\ffmpeg.exe"" -i ""{1}"" -ss {2} -to {3} -y -c copy ""{4}""",
2302 workPath, namevideo4, maskb.Text, maske.Text, nameout5) + Environment.NewLine + "cmd";
2303 batpath = workPath + "\\clip.bat";
2304 LogRecord(clip);
2305 File.WriteAllText(batpath, clip, Encoding.Default);
2306 Process.Start(batpath);
2310 private void cbX264_SelectedIndexChanged(object sender, EventArgs e)
2312 XElement xel = xdoc.Element("root").Element("Video").Element("VideoEncoder").Element("x264").Elements()
2313 .Where(x => x.Attribute("Name").Value == VideoPresetComboBox.Text).First();
2314 x264CustomParameterTextBox.Text = xel.Value;
2317 private void cbFPS_SelectedIndexChanged(object sender, EventArgs e)
2319 string ext = Path.GetExtension(namevideo).ToLower();
2320 if (cbFPS.SelectedIndex != 0 && ext != ".264" && ext != ".h264" && ext != ".hevc")
2322 ShowWarningMessage("只有扩展名为.264 .h264 .hevc的流文件设置帧率(fps)才有效");
2323 cbFPS.SelectedIndex = 0;
2327 private void btnMIopen_Click(object sender, EventArgs e)
2329 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
2330 DialogResult result = openFileDialog1.ShowDialog();
2331 if (result == DialogResult.OK)
2333 MIvideo = openFileDialog1.FileName;
2334 MediaInfoTextBox.Text = MediaInfo(MIvideo);
2338 private void btnMIplay_Click(object sender, EventArgs e)
2340 Process.Start(MIvideo);
2343 private void btnMIcopy_Click(object sender, EventArgs e)
2345 Clipboard.SetText(MItext);
2348 private void btnvideo7_Click(object sender, EventArgs e)
2350 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
2351 DialogResult result = openFileDialog1.ShowDialog();
2352 if (result == DialogResult.OK)
2354 namevideo6 = openFileDialog1.FileName;
2355 txtvideo6.Text = namevideo6;
2359 private void btnextract7_Click(object sender, EventArgs e)
2361 //MKV抽0
2362 ExtractTrack(namevideo6, 0);
2365 private void MkvExtract1Button_Click(object sender, EventArgs e)
2367 //MKV 抽1
2368 ExtractTrack(namevideo6, 1);
2371 private void MkvExtract2Button_Click(object sender, EventArgs e)
2373 //MKV 抽2
2374 ExtractTrack(namevideo6, 2);
2377 private void MkvExtract3Button_Click(object sender, EventArgs e)
2379 //MKV 抽3
2380 ExtractTrack(namevideo6, 3);
2383 private void MkvExtract4Button_Click(object sender, EventArgs e)
2385 //MKV 抽4
2386 ExtractTrack(namevideo6, 4);
2389 private void txtMI_TextChanged(object sender, EventArgs e)
2391 MItext = MediaInfoTextBox.Text;
2394 private void txtAVScreate_Click(object sender, EventArgs e)
2398 private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
2400 Process.Start("http://www.sosg.net/read.php?tid=480646");
2403 private void btnaextract2_Click(object sender, EventArgs e)
2405 //MP4 抽取音频2
2406 ExtractAV(namevideo, "a", 1);
2407 //if (namevideo == "")
2409 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2411 //else
2413 // //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 3 \"" + namevideo + "\"";
2414 // aextract = "";
2415 // aextract += Cmd.FormatPath(workPath + "\\ffmpeg.exe");
2416 // aextract += " -i " + Cmd.FormatPath(namevideo);
2417 // aextract += " -vn -sn -c:a:1 copy ";
2418 // string outfile = Cmd.GetDir(namevideo) +
2419 // Path.GetFileNameWithoutExtension(namevideo) + "_抽取音频2" + Path.GetExtension(namevideo);
2420 // aextract += Cmd.FormatPath(outfile);
2421 // batpath = workPath + "\\aextract.bat";
2422 // File.WriteAllText(batpath, aextract, Encoding.Default);
2423 // LogRecord(aextract);
2424 // Process.Start(batpath);
2428 private void btnaextract3_Click(object sender, EventArgs e)
2430 //MP4 抽取音频3
2431 ExtractAV(namevideo, "a", 2);
2432 //if (namevideo == "")
2434 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2436 //else
2438 // //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 4 \"" + namevideo + "\"";
2439 // aextract = "";
2440 // aextract += Cmd.FormatPath(workPath + "\\ffmpeg.exe");
2441 // aextract += " -i " + Cmd.FormatPath(namevideo);
2442 // aextract += " -vn -sn -c:a:2 copy ";
2443 // string outfile = Cmd.GetDir(namevideo) +
2444 // Path.GetFileNameWithoutExtension(namevideo) + "_抽取音频3" + Path.GetExtension(namevideo);
2445 // aextract += Cmd.FormatPath(outfile);
2446 // batpath = workPath + "\\aextract.bat";
2447 // File.WriteAllText(batpath, aextract, Encoding.Default);
2448 // LogRecord(aextract);
2449 // Process.Start(batpath);
2453 private void txtvideo6_TextChanged_1(object sender, EventArgs e)
2455 if (File.Exists(txtvideo6.Text.ToString()))
2457 namevideo6 = txtvideo6.Text;
2461 #region 帮助页面
2463 private void AboutBtn_Click(object sender, EventArgs e)
2465 DateTime CompileDate = File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
2466 QQMessageBox.Show(
2467 this,
2468 "小丸工具箱 七七版\r\n主页:http://www.maruko.in/ \r\n编译日期:" + CompileDate.ToString(),
2469 "关于",
2470 QQMessageBoxIcon.Information,
2471 QQMessageBoxButtons.OK);
2474 private void HomePageBtn_Click(object sender, EventArgs e)
2476 Process.Start("http://www.maruko.in/");
2479 #endregion 帮助页面
2481 #region 视频页面
2483 private void x264VideoBtn_Click(object sender, EventArgs e)
2485 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv;*.avi;*.wmv;*.mpg;*.avs)|*.mp4;*.flv;*.mkv;*.avi;*.wmv;*.mpg;*.avs|所有文件(*.*)|*.*";
2486 DialogResult result = openFileDialog1.ShowDialog();
2487 if (result == DialogResult.OK)
2489 namevideo2 = openFileDialog1.FileName;
2490 x264VideoTextBox.Text = namevideo2;
2494 private void x264OutBtn_Click(object sender, EventArgs e)
2496 SaveFileDialog savefile = new SaveFileDialog();
2497 savefile.Filter = "MPEG-4 视频(*.mp4)|*.mp4|Flash 视频(*.flv)|*.flv|Matroska 视频(*.mkv)|*.mkv|AVI 视频(*.avi)|*.avi|H.264 流(*.raw)|*.raw";
2498 savefile.FileName = Path.GetFileName(x264OutTextBox.Text);
2499 DialogResult result = savefile.ShowDialog();
2500 if (result == DialogResult.OK)
2502 nameout2 = savefile.FileName;
2503 x264OutTextBox.Text = nameout2;
2507 private void x264SubBtn_Click(object sender, EventArgs e)
2509 openFileDialog1.Filter = "字幕(*.ass;*.ssa;*.srt)|*.ass;*.ssa;*.srt|所有文件(*.*)|*.*";
2510 DialogResult result = openFileDialog1.ShowDialog();
2511 if (result == DialogResult.OK)
2513 namesub2 = openFileDialog1.FileName;
2514 x264SubTextBox.Text = namesub2;
2518 private void x264StartBtn_Click(object sender, EventArgs e)
2520 #region validation
2522 if (string.IsNullOrEmpty(namevideo2))
2524 ShowErrorMessage("请选择视频文件");
2525 return;
2528 if (!string.IsNullOrEmpty(namesub2) && !File.Exists(namesub2))
2530 ShowErrorMessage("字幕文件不存在,请重新选择");
2531 return;
2534 if (string.IsNullOrEmpty(nameout2))
2536 ShowErrorMessage("请选择输出文件");
2537 return;
2540 if (x264ExeComboBox.SelectedIndex == -1)
2542 ShowErrorMessage("请选择X264程序");
2543 return;
2546 if (AudioEncoderComboBox.SelectedIndex != 0 && AudioEncoderComboBox.SelectedIndex != 1 && AudioEncoderComboBox.SelectedIndex != 5)
2548 ShowWarningMessage("音频页面中的编码器未采用AAC将可能导致压制失败,建议将编码器改为QAAC、NeroAAC或FDKAAC。");
2551 //防止未选择 x264 thread
2552 if (x264ThreadsComboBox.SelectedIndex == -1)
2554 x264ThreadsComboBox.SelectedIndex = 0;
2557 //目标文件已经存在提示是否覆盖
2558 if (File.Exists(x264OutTextBox.Text.Trim()))
2560 DialogResult dgs = ShowQuestion("目标文件:\r\n\r\n" + x264OutTextBox.Text.Trim() + "\r\n\r\n已经存在,是否覆盖继续压制?", "目标文件已经存在");
2561 if (dgs == DialogResult.No) return;
2564 //如果是AVS复制到C盘根目录
2565 if (Path.GetExtension(x264VideoTextBox.Text) == ".avs")
2567 if (string.IsNullOrEmpty(Util.CheckAviSynth()) && string.IsNullOrEmpty(Util.CheckinternalAviSynth()))
2569 if (ShowQuestion("检测到本机未安装avisynth无法继续压制,是否去下载安装", "avisynth未安装") == DialogResult.Yes)
2570 Process.Start("http://sourceforge.net/projects/avisynth2/");
2571 return;
2573 //if (File.Exists(tempavspath)) File.Delete(tempavspath);
2574 File.Copy(x264VideoTextBox.Text, tempavspath, true);
2575 namevideo2 = tempavspath;
2576 x264DemuxerComboBox.SelectedIndex = 0; //压制AVS始终使用分离器为auto
2579 #endregion validation
2581 string ext = Path.GetExtension(nameout2).ToLower();
2582 bool hasAudio = false;
2583 string inputName = Path.GetFileNameWithoutExtension(namevideo2);
2584 string tempVideo = Path.Combine(tempfilepath, inputName + "_vtemp.mp4");
2585 string tempAudio = Path.Combine(tempfilepath, inputName + "_atemp" + getAudioExt());
2586 Util.ensureDirectoryExists(tempfilepath);
2588 #region Audio
2590 //检测是否含有音频
2591 MediaInfo MI = new MediaInfo();
2592 MI.Open(namevideo2);
2593 string audio = MI.Get(StreamKind.Audio, 0, "Format");
2594 if (!string.IsNullOrEmpty(audio))
2595 hasAudio = true;
2596 int audioMode = x264AudioModeComboBox.SelectedIndex;
2597 if (!hasAudio && x264AudioModeComboBox.SelectedIndex != 1)
2599 DialogResult r = ShowQuestion("原视频不包含音频流,音频模式是否改为无音频流?", "提示");
2600 if (r == DialogResult.Yes)
2601 audioMode = 1;
2603 switch (audioMode)
2605 case 0:
2606 aextract = audiobat(namevideo2, tempAudio);
2607 break;
2608 case 1:
2609 aextract = string.Empty;
2610 break;
2611 case 2:
2612 if (audio.ToLower() == "aac")
2614 tempAudio = Path.Combine(tempfilepath, inputName + "_atemp.aac");
2615 aextract = ExtractAudio(namevideo2, tempAudio);
2617 else
2619 ShowInfoMessage("因音频编码非AAC故无法复制音频流,音频将被重编码。");
2620 aextract = audiobat(namevideo2, tempAudio);
2622 break;
2623 default:
2624 break;
2627 #endregion
2629 #region Video
2630 if (x264ExeComboBox.SelectedItem.ToString().ToLower().Contains("x264"))
2632 if (x264mode == 2)
2633 x264 = x264bat(namevideo2, tempVideo, 1, namesub2) + "\r\n" +
2634 x264bat(namevideo2, tempVideo, 2, namesub2);
2635 else x264 = x264bat(namevideo2, tempVideo, 0, namesub2);
2636 if (audioMode == 1)
2637 x264 = x264.Replace(tempVideo, nameout2);
2639 else if (x264ExeComboBox.SelectedItem.ToString().ToLower().Contains("x265"))
2641 tempVideo = Path.Combine(tempfilepath, inputName + "_vtemp.hevc");
2642 if (ext != ".mp4")
2644 ShowErrorMessage("不支持的格式输出,x265当前工具箱仅支持MP4输出");
2645 return;
2647 if (x264mode == 2)
2648 x264 = x265bat(namevideo2, tempVideo, 1) + "\r\n" +
2649 x265bat(namevideo2, tempVideo, 2);
2650 else x264 = x265bat(namevideo2, tempVideo, 0);
2651 if (audioMode == 1)
2653 x264 += "\r\n\"" + workPath + "\\mp4box.exe\" -add \"" + tempVideo + "#trackID=1:name=\" -new \"" + Util.ChangeExt(nameout2, ".mp4") + "\" \r\n";
2654 x264 += "del \"" + tempVideo + "\"";
2657 x264 += "\r\n";
2659 #endregion
2661 #region Mux
2663 //封装
2664 if (audioMode != 1)
2666 if (ext == ".mp4")
2667 mux = boxmuxbat(tempVideo, tempAudio, Util.ChangeExt(nameout2, ext));
2668 else
2669 mux = ffmuxbat(tempVideo, tempAudio, Util.ChangeExt(nameout2, ext));
2670 x264 = aextract + x264 + mux + "\r\n"
2671 + "del \"" + tempVideo + "\"\r\n"
2672 + "del \"" + tempAudio + "\"\r\n";
2674 x264 += "\r\necho ===== one file is completed! =====\r\n";
2676 #endregion
2678 LogRecord(x264);
2679 Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(GetCultureName());
2680 WorkingForm wf = new WorkingForm(x264);
2681 wf.Owner = this;
2682 wf.Show();
2683 //x264 += "\r\ncmd";
2684 //batpath = workPath + "\\x264.bat";
2685 //File.WriteAllText(batpath, x264, Encoding.Default);
2686 //Process.Start(batpath);
2689 private void x264AddPresetBtn_Click(object sender, EventArgs e)
2693 string vPresetName = InputBox.Show("请输入这个预设名称", "请为预置配置命名", "新预置名称");
2694 if (!string.IsNullOrEmpty(vPresetName))
2696 var xl = xdoc.Element("root").Element("Video").Element("VideoEncoder").Element("x264");
2697 XElement xelnew = new XElement("Parameter", x264CustomParameterTextBox.Text,
2698 new XAttribute("Name", vPresetName));
2699 foreach (var item in xl.Elements())
2701 if (item.Attribute("Name").Value == vPresetName)
2703 ShowErrorMessage("预设名称已经存在", "预设名称重复");
2704 return;
2707 xl.Add(xelnew);
2708 xdoc.Save("preset.xml");
2709 LoadVideoPreset();
2710 VideoPresetComboBox.SelectedIndex = VideoPresetComboBox.FindString(vPresetName);
2713 catch (Exception ex)
2715 ShowErrorMessage("添加失败! Reason: " + ex.Message);
2719 private void x264DeletePresetBtn_Click(object sender, EventArgs e)
2721 if (ShowQuestion("确定要删除这条预设参数?", "提示") == DialogResult.Yes)
2725 var xls = xdoc.Element("root").Element("Video").Element("VideoEncoder").Element("x264").Elements();
2726 foreach (var item in xls)
2728 if (item.Attribute("Name").Value == VideoPresetComboBox.Text)
2729 item.Remove();
2731 xdoc.Save("preset.xml");
2732 LoadVideoPreset();
2734 catch (Exception ex)
2736 ShowErrorMessage("删除失败! Reason: " + ex.Message);
2741 private void x264Mode2RadioButton_CheckedChanged(object sender, EventArgs e)
2743 x264mode = 2;
2744 lbrate.Visible = true;
2745 x264BitrateNum.Visible = true;
2746 label12.Visible = true;
2747 //x264FpsComboBox.Visible = true;
2748 //lbFPS2.Visible = true;
2749 lbwidth.Visible = true;
2750 lbheight.Visible = true;
2751 x264WidthNum.Visible = true;
2752 x264HeightNum.Visible = true;
2753 MaintainResolutionCheckBox.Visible = true;
2754 lbcrf.Visible = false;
2755 x264CRFNum.Visible = false;
2756 label4.Visible = false;
2757 x264CustomParameterTextBox.Visible = false;
2758 VideoPresetComboBox.Visible = false;
2759 x264AddPresetBtn.Visible = false;
2760 x264DeletePresetBtn.Visible = false;
2763 private void x264Mode3RadioButton_CheckedChanged(object sender, EventArgs e)
2765 x264mode = 0;
2766 label4.Visible = true;
2767 x264CustomParameterTextBox.Visible = true;
2768 VideoPresetComboBox.Visible = true;
2769 x264AddPresetBtn.Visible = true;
2770 x264DeletePresetBtn.Visible = true;
2771 lbwidth.Visible = false;
2772 lbheight.Visible = false;
2773 x264WidthNum.Visible = false;
2774 x264HeightNum.Visible = false;
2775 MaintainResolutionCheckBox.Visible = false;
2776 lbrate.Visible = false;
2777 x264BitrateNum.Visible = false;
2778 label12.Visible = false;
2779 lbcrf.Visible = false;
2780 x264CRFNum.Visible = false;
2781 //x264FpsComboBox.Visible = false;
2782 //lbFPS2.Visible = false;
2785 private void x264Mode1RadioButton_CheckedChanged(object sender, EventArgs e)
2787 x264mode = 1;
2788 lbcrf.Visible = true;
2789 x264CRFNum.Visible = true;
2790 //x264FpsComboBox.Visible = true;
2791 //lbFPS2.Visible = true;
2792 lbwidth.Visible = true;
2793 lbheight.Visible = true;
2794 x264WidthNum.Visible = true;
2795 x264HeightNum.Visible = true;
2796 MaintainResolutionCheckBox.Visible = true;
2797 lbrate.Visible = false;
2798 x264BitrateNum.Visible = false;
2799 label12.Visible = false;
2800 label4.Visible = false;
2801 x264CustomParameterTextBox.Visible = false;
2802 VideoPresetComboBox.Visible = false;
2803 x264AddPresetBtn.Visible = false;
2804 x264DeletePresetBtn.Visible = false;
2807 private void x264PriorityComboBox_SelectedIndexChanged(object sender, EventArgs e)
2809 string processName = x264ExeComboBox.Text;
2810 processName = processName.Replace(".exe", "");
2811 Process[] processes = Process.GetProcesses();
2812 //if (x264PriorityComboBox.SelectedIndex == 4 || x264PriorityComboBox.SelectedIndex == 5)
2814 // if (MessageBox.Show("优先级那么高的话会严重影响其他进程的运行速度,\r\n是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
2815 // {
2816 // x264PriorityComboBox.SelectedIndex = 2;
2817 // }
2819 //遍历电脑中的进程
2820 for (int i = 0; i < processes.GetLength(0); i++)
2822 //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
2823 if (processes[i].ProcessName.Equals(processName))
2825 switch (x264PriorityComboBox.SelectedIndex)
2827 case 0: processes[i].PriorityClass = ProcessPriorityClass.Idle; break;
2828 case 1: processes[i].PriorityClass = ProcessPriorityClass.BelowNormal; break;
2829 case 2: processes[i].PriorityClass = ProcessPriorityClass.Normal; break;
2830 case 3: processes[i].PriorityClass = ProcessPriorityClass.AboveNormal; break;
2831 case 4: processes[i].PriorityClass = ProcessPriorityClass.High; break;
2832 case 5: processes[i].PriorityClass = ProcessPriorityClass.RealTime; break;
2838 private void x264VideoTextBox_TextChanged(object sender, EventArgs e)
2840 string path = x264VideoTextBox.Text;
2841 if (File.Exists(path))
2843 namevideo2 = path;
2844 int num = 1;
2845 string encType = x264ExeComboBox.SelectedItem.ToString().Contains("x265") ? "x265" : "x264";
2846 x264OutTextBox.Text = Util.ChangeExt(namevideo2, string.Format("_{0}.mp4", encType));
2847 while (namevideo2.Equals(x264OutTextBox.Text) || File.Exists(x264OutTextBox.Text))
2849 x264OutTextBox.Text = Util.ChangeExt(namevideo2, string.Format("_new_file({0})_{1}.mp4", num, encType));
2850 num++;
2853 if (Path.GetExtension(namevideo2) != ".avs" && encType == "x264")
2855 string[] subExt = { ".ass", ".ssa", ".srt" };
2856 foreach (string ext in subExt)
2858 if (File.Exists(Util.ChangeExt(namevideo2, ext)))
2860 x264SubTextBox.Text = Util.ChangeExt(namevideo2, ext);
2861 break;
2863 else
2864 x264SubTextBox.Text = string.Empty;
2871 private void x264OutTextBox_TextChanged(object sender, EventArgs e)
2873 nameout2 = x264OutTextBox.Text;
2876 private void x264SubTextBox_TextChanged(object sender, EventArgs e)
2878 namesub2 = x264SubTextBox.Text;
2881 private void x264BatchClearBtn_Click(object sender, EventArgs e)
2883 lbAuto.Items.Clear();
2886 private void x264BatchDeleteBtn_Click(object sender, EventArgs e)
2888 if (lbAuto.Items.Count > 0)
2890 if (lbAuto.SelectedItems.Count > 0)
2892 int index = lbAuto.SelectedIndex;
2893 lbAuto.Items.RemoveAt(lbAuto.SelectedIndex);
2894 if (index == lbAuto.Items.Count)
2896 lbAuto.SelectedIndex = index - 1;
2898 if (index >= 0 && index < lbAuto.Items.Count && lbAuto.Items.Count > 0)
2900 lbAuto.SelectedIndex = index;
2906 private void x264BatchAddBtn_Click(object sender, EventArgs e)
2908 openFileDialog1.Multiselect = true;
2909 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2910 DialogResult result = openFileDialog1.ShowDialog();
2911 if (result == DialogResult.OK)
2913 lbAuto.Items.AddRange(openFileDialog1.FileNames);
2917 #endregion 视频页面
2919 #region 音频界面
2921 // <summary>
2922 /// 是否安装 Apple Application Support
2923 /// </summary>
2924 /// <returns>true:安装 false:没有安装</returns>
2925 private bool isAppleAppSupportInstalled()
2927 Microsoft.Win32.RegistryKey uninstallNode_1 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Wow6432Node\Apple Inc.\Apple Application Support"); //x64 OS
2928 Microsoft.Win32.RegistryKey uninstallNode_2 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Apple Inc.\Apple Application Support"); //x86 OS
2929 if (uninstallNode_1 != null || uninstallNode_2 != null)
2931 return true;
2933 else
2935 return false;
2939 private void AudioEncoderComboBox_SelectedIndexChanged(object sender, EventArgs e)
2941 switch (AudioEncoderComboBox.SelectedIndex)
2943 case 0:
2944 if (File.Exists(txtaudio2.Text))
2945 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.mp4");
2946 AudioBitrateComboBox.Enabled = true;
2947 AudioBitrateRadioButton.Enabled = true;
2948 AudioCustomizeRadioButton.Enabled = true;
2949 if (AudioCustomizeRadioButton.Checked)
2951 audioDeleteBt.Visible = true;
2952 audioAddBt.Visible = true;
2954 break;
2956 case 1:
2957 if (!isAppleAppSupportInstalled())
2959 if (ShowQuestion("Apple Application Support未安装.\r\n音频编码器QAAC可能无法使用.\r\n\r\n是否前往QuickTime下载页面?", "Apple Application Support未安装") == DialogResult.Yes)
2960 Process.Start("http://www.apple.com/cn/quicktime/download");
2962 if (File.Exists(txtaudio2.Text))
2963 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.m4a");
2964 AudioBitrateComboBox.Enabled = true;
2965 AudioBitrateRadioButton.Enabled = true;
2966 AudioCustomizeRadioButton.Enabled = true;
2967 if (AudioCustomizeRadioButton.Checked)
2969 audioDeleteBt.Visible = true;
2970 audioAddBt.Visible = true;
2972 break;
2974 case 2:
2975 if (File.Exists(txtaudio2.Text))
2976 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_WAV.wav");
2977 AudioBitrateComboBox.Enabled = false;
2978 AudioBitrateRadioButton.Enabled = false;
2979 AudioCustomizeRadioButton.Enabled = false;
2980 audioDeleteBt.Visible = false;
2981 audioAddBt.Visible = false;
2982 break;
2984 case 3:
2985 if (File.Exists(txtaudio2.Text))
2986 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_ALAC.m4a");
2987 AudioBitrateComboBox.Enabled = false;
2988 AudioBitrateRadioButton.Enabled = false;
2989 AudioCustomizeRadioButton.Enabled = false;
2990 audioDeleteBt.Visible = false;
2991 audioAddBt.Visible = false;
2992 break;
2994 case 4:
2995 if (File.Exists(txtaudio2.Text))
2996 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_FLAC.flac");
2997 AudioBitrateComboBox.Enabled = false;
2998 AudioBitrateRadioButton.Enabled = false;
2999 AudioCustomizeRadioButton.Enabled = false;
3000 audioDeleteBt.Visible = false;
3001 audioAddBt.Visible = false;
3002 break;
3004 case 5:
3005 if (File.Exists(txtaudio2.Text))
3006 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.m4a");
3007 AudioBitrateComboBox.Enabled = true;
3008 AudioBitrateRadioButton.Enabled = true;
3009 AudioCustomizeRadioButton.Enabled = true;
3010 if (AudioCustomizeRadioButton.Checked)
3012 audioDeleteBt.Visible = true;
3013 audioAddBt.Visible = true;
3015 break;
3017 case 6:
3018 if (File.Exists(txtaudio2.Text))
3019 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AC3.ac3");
3020 AudioBitrateComboBox.Enabled = true;
3021 AudioBitrateRadioButton.Enabled = true;
3022 AudioCustomizeRadioButton.Enabled = false;
3023 audioDeleteBt.Visible = false;
3024 audioAddBt.Visible = false;
3025 break;
3027 default:
3028 break;
3031 XElement xAudios = xdoc.Element("root").Element("Audio").Element("AudioEncoder").Element(AudioEncoderComboBox.Text);
3032 if (xAudios != null)
3034 AudioPresetComboBox.Items.Clear();
3035 AudioCustomParameterTextBox.Text = string.Empty;
3036 foreach (XElement item in xAudios.Elements())
3038 AudioPresetComboBox.Items.Add(item.Attribute("Name").Value);
3039 AudioPresetComboBox.SelectedIndex = 0;
3042 else
3044 AudioPresetComboBox.Items.Clear();
3045 AudioCustomParameterTextBox.Text = string.Empty;
3050 private void AudioListBox_DragDrop(object sender, DragEventArgs e)
3052 ListBox listbox = (ListBox)sender;
3053 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
3055 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
3056 foreach (String s in files)
3058 listbox.Items.Add(s);
3060 return;
3062 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
3063 if (indexoftarget != ListBox.NoMatches)
3065 string temp = listbox.Items[indexoftarget].ToString();
3066 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
3067 listbox.Items[indexofsource] = temp;
3068 listbox.SelectedIndex = indexoftarget;
3072 private void AudioListBox_DragOver(object sender, DragEventArgs e)
3074 ListBox listbox = (ListBox)sender;
3075 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(listbox))
3077 e.Effect = DragDropEffects.Move;
3079 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
3081 e.Effect = DragDropEffects.Link;
3083 else e.Effect = DragDropEffects.None;
3086 private void AudioListBox_MouseDown(object sender, MouseEventArgs e)
3088 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
3089 if (indexofsource != ListBox.NoMatches)
3091 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
3095 private void AudioBatchButton_Click(object sender, EventArgs e)
3097 if (AudioListBox.Items.Count != 0)
3099 string finish, outputExt, codec;
3100 aac = "";
3101 switch (AudioEncoderComboBox.SelectedIndex)
3103 case 0: outputExt = "mp4"; codec = "AAC"; break;
3104 case 1: outputExt = "m4a"; codec = "AAC"; break;
3105 case 2: outputExt = "wav"; codec = "WAV"; break;
3106 case 3: outputExt = "m4a"; codec = "ALAC"; break;
3107 case 4: outputExt = "flac"; codec = "FLAC"; break;
3108 case 5: outputExt = "m4a"; codec = "AAC"; break;
3109 case 6: outputExt = "ac3"; codec = "AC3"; break;
3110 default: outputExt = "aac"; codec = "AAC"; break;
3112 for (int i = 0; i < this.AudioListBox.Items.Count; i++)
3114 string outname = "_" + codec + "." + outputExt;
3115 finish = Util.ChangeExt(AudioListBox.Items[i].ToString(), outname);
3116 aac += audiobat(AudioListBox.Items[i].ToString(), finish);
3117 aac += "\r\n";
3119 aac += "\r\ncmd";
3120 batpath = workPath + "\\aac.bat";
3121 File.WriteAllText(batpath, aac, Encoding.Default);
3122 LogRecord(aac);
3123 Process.Start(batpath);
3125 else ShowErrorMessage("请输入文件!");
3128 private void btnaudio2_Click(object sender, EventArgs e)
3130 openFileDialog1.Filter = "所有文件(*.*)|*.*";
3131 DialogResult result = openFileDialog1.ShowDialog();
3132 if (result == DialogResult.OK)
3134 nameaudio2 = openFileDialog1.FileName;
3135 txtaudio2.Text = nameaudio2;
3139 private void btnout3_Click(object sender, EventArgs e)
3141 SaveFileDialog savefile = new SaveFileDialog();
3142 savefile.Filter = "所有文件(*.*)|*.*";
3143 //savefile.Filter = "音频(*.aac;*.wav;*.m4a;*.flac)|*.aac*.wav;*.m4a;*.flac;";
3144 DialogResult result = savefile.ShowDialog();
3145 if (result == DialogResult.OK)
3147 nameout3 = savefile.FileName + getAudioExt();
3148 AudioOutputTextBox.Text = nameout3;
3152 private void btnaac_Click(object sender, EventArgs e)
3154 if (nameaudio2 == "")
3156 ShowErrorMessage("请选择音频文件");
3158 else if (nameout3 == "")
3160 ShowErrorMessage("请选择输出文件");
3162 else
3164 batpath = workPath + "\\aac.bat";
3165 File.WriteAllText(batpath, audiobat(nameaudio2, nameout3), Encoding.Default);
3166 LogRecord(audiobat(nameaudio2, nameout3));
3167 Process.Start(batpath);
3171 private void txtaudio2_TextChanged(object sender, EventArgs e)
3173 if (File.Exists(txtaudio2.Text.ToString()))
3175 nameaudio2 = txtaudio2.Text;
3176 switch (AudioEncoderComboBox.SelectedIndex)
3178 case 0: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.mp4"); break;
3179 case 1: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.m4a"); break;
3180 case 2: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_WAV.wav"); break;
3181 case 3: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_ALAC.m4a"); break;
3182 case 4: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_FLAC.flac"); break;
3183 case 5: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.m4a"); break;
3184 case 6: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AC3.ac3"); break;
3185 default: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.aac"); break;
3190 private void txtout3_TextChanged(object sender, EventArgs e)
3192 nameout3 = AudioOutputTextBox.Text;
3195 private void txtaudio2_MouseDoubleClick(object sender, MouseEventArgs e)
3197 if (File.Exists(txtaudio2.Text.ToString()))
3199 Process.Start(txtaudio2.Text.ToString());
3203 private void radioButton5_CheckedChanged(object sender, EventArgs e)
3205 lbaacrate.Visible = false;
3206 lbaackbps.Visible = false;
3207 AudioBitrateComboBox.Visible = false;
3208 AudioCustomParameterTextBox.Visible = true;
3209 AudioPresetLabel.Visible = true;
3210 AudioPresetComboBox.Visible = true;
3211 audioDeleteBt.Visible = true;
3212 audioAddBt.Visible = true;
3215 private void radioButton4_CheckedChanged(object sender, EventArgs e)
3217 lbaacrate.Visible = true;
3218 lbaackbps.Visible = true;
3219 AudioBitrateComboBox.Visible = true;
3220 AudioCustomParameterTextBox.Visible = false;
3221 AudioPresetLabel.Visible = false;
3222 AudioPresetComboBox.Visible = false;
3223 audioDeleteBt.Visible = false;
3224 audioAddBt.Visible = false;
3227 private void AudioAddButton_Click(object sender, EventArgs e)
3229 openFileDialog1.Multiselect = true;
3230 openFileDialog1.Filter = "所有文件(*.*)|*.*";
3231 DialogResult result = openFileDialog1.ShowDialog();
3232 if (result == DialogResult.OK)
3234 AudioListBox.Items.AddRange(openFileDialog1.FileNames);
3238 private void AudioDeleteButton_Click(object sender, EventArgs e)
3240 if (AudioListBox.Items.Count > 0)
3242 if (AudioListBox.SelectedItems.Count > 0)
3244 int index = AudioListBox.SelectedIndex;
3245 AudioListBox.Items.RemoveAt(AudioListBox.SelectedIndex);
3246 if (index == AudioListBox.Items.Count)
3248 AudioListBox.SelectedIndex = index - 1;
3250 if (index >= 0 && index < AudioListBox.Items.Count && AudioListBox.Items.Count > 0)
3252 AudioListBox.SelectedIndex = index;
3258 private void AudioClearButton_Click(object sender, EventArgs e)
3260 AudioListBox.Items.Clear();
3263 #endregion 音频界面
3265 #region AVS页面
3267 private void GenerateAVS()
3269 //if (Directory.Exists("avsfilter"))
3271 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
3272 // foreach (FileInfo FileName in TheFolder.GetFiles())
3273 // {
3274 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
3275 // }
3277 avsBuilder.Remove(0, avsBuilder.Length);
3278 string vsfilterDLLPath = Path.Combine(workPath, @"avs\plugins\VSFilter.DLL");
3279 string LSMASHSourceDLLPath = Path.Combine(workPath, @"avs\plugins\LSMASHSource.DLL");
3280 string undotDLLPath = Path.Combine(workPath, @"avs\plugins\UnDot.DLL");
3281 avsBuilder.AppendLine("LoadPlugin(\"" + vsfilterDLLPath + "\")");
3282 avsBuilder.AppendLine("LoadPlugin(\"" + LSMASHSourceDLLPath + "\")");
3283 string extInput = Path.GetExtension(namevideo9).ToLower();
3285 if (UndotCheckBox.Checked)
3286 avsBuilder.AppendLine("LoadPlugin(\"" + undotDLLPath + "\")");
3287 if (extInput == ".mp4"
3288 || extInput == ".mov"
3289 || extInput == ".qt"
3290 || extInput == ".3gp"
3291 || extInput == ".3g2")
3292 avsBuilder.AppendLine("LSMASHVideoSource(\"" + namevideo9 + "\")");
3293 else
3294 avsBuilder.AppendLine("LWLibavVideoSource(\"" + namevideo9 + "\")");
3295 avsBuilder.AppendLine("ConvertToYV12()");
3296 if (UndotCheckBox.Checked)
3297 avsBuilder.AppendLine("Undot()");
3298 if (TweakCheckBox.Checked)
3299 avsBuilder.AppendLine("Tweak(" + TweakChromaNumericUpDown.Value.ToString() + ", " + TweakSaturationNumericUpDown.Value.ToString() + ", " + TweakBrightnessNumericUpDown.Value.ToString() + ", " + TweakContrastNumericUpDown.Value.ToString() + ")");
3300 if (LevelsCheckBox.Checked)
3301 avsBuilder.AppendLine("Levels(0," + LevelsNumericUpDown.Value.ToString() + ",255,0,255)");
3302 if (LanczosResizeCheckBox.Checked)
3303 avsBuilder.AppendLine("LanczosResize(" + AVSWidthNumericUpDown.Value.ToString() + "," + AVSHeightNumericUpDown.Value.ToString() + ")");
3304 if (SharpenCheckBox.Checked)
3305 avsBuilder.AppendLine("Sharpen(" + SharpenNumericUpDown.Value.ToString() + ")");
3306 if (CropCheckBox.Checked)
3307 avsBuilder.AppendLine("Crop(" + AVSCropTextBox.Text + ")");
3308 if (AddBordersCheckBox.Checked)
3309 avsBuilder.AppendLine("AddBorders(" + AddBorders1NumericUpDown.Value.ToString() + "," + AddBorders2NumericUpDown.Value.ToString() + "," + AddBorders3NumericUpDown.Value.ToString() + "," + AddBorders4NumericUpDown.Value.ToString() + ")");
3310 if (!string.IsNullOrEmpty(txtsub9.Text))
3312 if (Path.GetExtension(namesub9) == ".idx")
3313 avsBuilder.AppendLine("vobsub(\"" + namesub9 + "\")");
3314 else
3315 avsBuilder.AppendLine("TextSub(\"" + namesub9 + "\")");
3317 if (TrimCheckBox.Checked)
3318 avsBuilder.AppendLine("Trim(" + TrimStartNumericUpDown.Value.ToString() + "," + TrimEndNumericUpDown.Value.ToString() + ")");
3319 AVSScriptTextBox.Text = avsBuilder.ToString();
3322 #region 更改AVS
3324 private void TweakCheckBox_CheckedChanged(object sender, EventArgs e)
3326 GenerateAVS();
3329 private void LanczosResizeCheckBox_CheckedChanged(object sender, EventArgs e)
3331 GenerateAVS();
3334 private void AddBordersCheckBox_CheckedChanged(object sender, EventArgs e)
3336 GenerateAVS();
3339 private void CropCheckBox_CheckedChanged(object sender, EventArgs e)
3341 GenerateAVS();
3344 private void TrimCheckBox_CheckedChanged(object sender, EventArgs e)
3346 GenerateAVS();
3349 private void LevelsCheckBox_CheckedChanged(object sender, EventArgs e)
3351 GenerateAVS();
3354 private void SharpenCheckBox_CheckedChanged(object sender, EventArgs e)
3356 GenerateAVS();
3359 private void UndotCheckBox_CheckedChanged(object sender, EventArgs e)
3361 GenerateAVS();
3364 private void TweakChromaNumericUpDown_ValueChanged(object sender, EventArgs e)
3366 GenerateAVS();
3369 private void TweakSaturationNumericUpDown_ValueChanged(object sender, EventArgs e)
3371 GenerateAVS();
3374 private void TweakBrightnessNumericUpDown_ValueChanged(object sender, EventArgs e)
3376 GenerateAVS();
3379 private void TweakContrastNumericUpDown_ValueChanged(object sender, EventArgs e)
3381 GenerateAVS();
3384 private void AVSWidthNumericUpDown_ValueChanged(object sender, EventArgs e)
3386 GenerateAVS();
3389 private void AVSHeightNumericUpDown_ValueChanged(object sender, EventArgs e)
3391 GenerateAVS();
3394 private void AddBorders1NumericUpDown_ValueChanged(object sender, EventArgs e)
3396 GenerateAVS();
3399 private void AddBorders2NumericUpDown_ValueChanged(object sender, EventArgs e)
3401 GenerateAVS();
3404 private void AddBorders3NumericUpDown_ValueChanged(object sender, EventArgs e)
3406 GenerateAVS();
3409 private void AddBorders4NumericUpDown_ValueChanged(object sender, EventArgs e)
3411 GenerateAVS();
3414 private void AVSCropTextBox_TextChanged(object sender, EventArgs e)
3416 GenerateAVS();
3419 private void TrimStartNumericUpDown_ValueChanged(object sender, EventArgs e)
3421 GenerateAVS();
3424 private void TrimEndNumericUpDown_ValueChanged(object sender, EventArgs e)
3426 GenerateAVS();
3429 private void LevelsNumericUpDown_ValueChanged(object sender, EventArgs e)
3431 GenerateAVS();
3434 private void SharpenNumericUpDown_ValueChanged(object sender, EventArgs e)
3436 GenerateAVS();
3439 #endregion 更改AVS
3441 #endregion AVS页面
3443 private void ExtractMP4Button_Click(object sender, EventArgs e)
3445 openFileDialog1.Filter = "视频(*.mp4)|*.mp4|所有文件(*.*)|*.*";
3446 DialogResult result = openFileDialog1.ShowDialog();
3447 if (result == DialogResult.OK)
3449 namevideo = openFileDialog1.FileName;
3450 ExtractMP4TextBox.Text = namevideo;
3454 private void txtAVS_TextChanged(object sender, EventArgs e)
3456 Match m = Regex.Match(AVSScriptTextBox.Text, "ource\\(\"[a-zA-Z]:\\\\.+\\.\\w+\"");
3457 if (m.Success)
3459 string str = m.ToString();
3460 str = str.Replace("ource(\"", "");
3461 str = str.Replace("\"", "");
3462 str = Util.ChangeExt(str, "_AVS.mp4");
3463 txtout9.Text = str;
3467 public void Log(string path)
3469 ProcessStartInfo start = new ProcessStartInfo(path);//设置运行的命令行文件问ping.exe文件,这个文件系统会自己找到
3470 //如果是其它exe文件,则有可能需要指定详细路径,如运行winRar.exe
3471 start.CreateNoWindow = false;//不显示dos命令行窗口
3472 start.RedirectStandardOutput = true;//
3473 start.RedirectStandardInput = true;//
3474 start.UseShellExecute = false;//是否指定操作系统外壳进程启动程序
3475 Process p = Process.Start(start);
3476 StreamReader reader = p.StandardOutput;//截取输出流
3477 string line = reader.ReadLine();//每次读取一行
3478 StringBuilder log = new StringBuilder(2000);
3479 while (!reader.EndOfStream)
3481 log.Append(line + "\r\n");
3482 line = reader.ReadLine();
3484 p.WaitForExit();//等待程序执行完退出进程
3485 File.WriteAllText(startpath + "\\log.txt", log.ToString(), Encoding.Default);
3486 p.Close();//关闭进程
3487 reader.Close();//关闭流
3490 public void LogRecord(string log)
3492 Util.ensureDirectoryExists(logPath);
3493 File.AppendAllText(logFileName,
3494 "===========" + DateTime.Now.ToString() + "===========\r\n" + log + "\r\n\r\n", Encoding.Default);
3497 private void DeleteLogButton_Click(object sender, EventArgs e)
3499 if (Directory.Exists(logPath))
3501 Util.DeleteDirectoryIfExists(logPath, true);
3502 ShowInfoMessage("已经删除日志文件。");
3504 else ShowInfoMessage("没有找到日志文件。");
3507 private void ViewLogButton_Click(object sender, EventArgs e)
3509 if (File.Exists(logFileName))
3511 Process.Start(logFileName);
3513 else ShowInfoMessage("没有找到日志文件。");
3516 private void x264PathButton_Click(object sender, EventArgs e)
3518 FolderBrowserDialog fbd = new FolderBrowserDialog();
3519 if (fbd.ShowDialog() == DialogResult.OK)
3520 x264PathTextBox.Text = fbd.SelectedPath;
3523 private void ExtractMP4TextBox_TextChanged(object sender, EventArgs e)
3525 namevideo = ExtractMP4TextBox.Text;
3528 private void MaintainResolutionCheckBox_CheckedChanged(object sender, EventArgs e)
3530 if (MaintainResolutionCheckBox.Checked)
3532 x264WidthNum.Value = 0;
3533 x264HeightNum.Value = 0;
3534 x264WidthNum.Enabled = false;
3535 x264HeightNum.Enabled = false;
3537 else
3539 x264WidthNum.Enabled = true;
3540 x264HeightNum.Enabled = true;
3544 #region globalization
3546 public static void SetLang(string lang, Form form, Type formType)
3548 Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
3549 if (form != null)
3551 ComponentResourceManager resources = new ComponentResourceManager(formType);
3552 resources.ApplyResources(form, "$this");
3553 AppLang(form, resources);
3557 private static void AppLang(Control control, ComponentResourceManager resources)
3559 foreach (Control c in control.Controls)
3561 resources.ApplyResources(c, c.Name);
3562 AppLang(c, resources);
3566 private void languageComboBox_SelectedIndexChanged(object sender, EventArgs e)
3568 //StreamReader sr;
3569 x264Mode1RadioButton.Checked = true;
3570 AudioBitrateRadioButton.Checked = true;
3571 int x264AudioModeComboBoxIndex = 0;
3572 switch (languageComboBox.SelectedIndex)
3574 case 0:
3575 SetLang("zh-CN", this, typeof(MainForm));
3576 this.Text = string.Format("小丸工具箱 {0}", Assembly.GetExecutingAssembly().GetName().Version.Build);
3577 x264PriorityComboBox.Items.Clear();
3578 x264PriorityComboBox.Items.AddRange(new string[] { "低", "低于标准", "普通", "高于标准", "高", "实时" });
3579 x264PriorityComboBox.SelectedIndex = 2;
3580 x264AudioModeComboBoxIndex = x264AudioModeComboBox.SelectedIndex;
3581 x264AudioModeComboBox.Items.Clear();
3582 x264AudioModeComboBox.Items.Add("压制音频");
3583 x264AudioModeComboBox.Items.Add("无音频流");
3584 x264AudioModeComboBox.Items.Add("复制音频流");
3585 x264AudioModeComboBox.SelectedIndex = x264AudioModeComboBoxIndex;
3586 x264VideoTextBox.EmptyTextTip = "可以把文件拖拽到这里";
3587 x264SubTextBox.EmptyTextTip = "双击清空字幕文件文本框";
3588 //x264OutTextBox.EmptyTextTip = "宽度和高度全为0即不改变分辨率";
3589 x264PathTextBox.EmptyTextTip = "字幕文件和视频文件在同一目录下且同名,不同名仅有语言后缀时请在右方选择或输入";
3590 //txtvideo3.EmptyTextTip = "音频参数在音频选项卡设定";
3591 ExtractMP4TextBox.EmptyTextTip = "抽取的视频或音频在原视频目录下";
3592 txtvideo8.EmptyTextTip = "抽取的视频或音频在原视频目录下";
3593 txtvideo6.EmptyTextTip = "抽取的视频或音频在原视频目录下";
3594 //load Help Text
3595 if (File.Exists(startpath + "\\help.rtf"))
3597 HelpTextBox.LoadFile(startpath + "\\help.rtf");
3599 break;
3601 case 1:
3602 SetLang("zh-TW", this, typeof(MainForm));
3603 this.Text = string.Format("小丸工具箱 {0}", Assembly.GetExecutingAssembly().GetName().Version.Build);
3604 x264PriorityComboBox.Items.Clear();
3605 x264PriorityComboBox.Items.AddRange(new string[] { "低", "在標準以下", "標準", "在標準以上", "高", "即時" });
3606 x264PriorityComboBox.SelectedIndex = 2;
3607 x264AudioModeComboBoxIndex = x264AudioModeComboBox.SelectedIndex;
3608 x264AudioModeComboBox.Items.Clear();
3609 x264AudioModeComboBox.Items.Add("壓制音頻");
3610 x264AudioModeComboBox.Items.Add("無音頻流");
3611 x264AudioModeComboBox.Items.Add("拷貝音頻流");
3612 x264AudioModeComboBox.SelectedIndex = x264AudioModeComboBoxIndex;
3613 x264VideoTextBox.EmptyTextTip = "可以把文件拖拽到這裡";
3614 x264SubTextBox.EmptyTextTip = "雙擊清空字幕檔案文本框";
3615 //x264OutTextBox.EmptyTextTip = "寬度和高度全為0即不改變解析度";
3616 x264PathTextBox.EmptyTextTip = "字幕和視頻在同一資料夾下且同名,不同名僅有語言後綴時請在右方選擇或輸入";
3617 //txtvideo3.EmptyTextTip = "音頻參數需在音頻選項卡设定";
3618 ExtractMP4TextBox.EmptyTextTip = "新檔案生成在原資料夾";
3619 txtvideo8.EmptyTextTip = "新檔案生成在原資料夾";
3620 txtvideo6.EmptyTextTip = "新檔案生成在原資料夾";
3621 //load Help Text
3622 if (File.Exists(startpath + "\\help_zh_tw.rtf"))
3624 HelpTextBox.LoadFile(startpath + "\\help_zh_tw.rtf");
3626 break;
3628 case 2:
3629 SetLang("en-US", this, typeof(MainForm));
3630 this.Text = string.Format("Maruko Toolbox {0}", Assembly.GetExecutingAssembly().GetName().Version.Build);
3631 x264PriorityComboBox.Items.Clear();
3632 x264PriorityComboBox.Items.AddRange(new string[] { "Idle", "BelowNormal", "Normal", "AboveNormal", "High", "RealTime" });
3633 x264PriorityComboBox.SelectedIndex = 2;
3634 x264AudioModeComboBoxIndex = x264AudioModeComboBox.SelectedIndex;
3635 x264AudioModeComboBox.Items.Clear();
3636 x264AudioModeComboBox.Items.Add("with audio");
3637 x264AudioModeComboBox.Items.Add("no audio");
3638 x264AudioModeComboBox.Items.Add("copy audio");
3639 x264AudioModeComboBox.SelectedIndex = x264AudioModeComboBoxIndex;
3640 x264VideoTextBox.EmptyTextTip = "Drag file here";
3641 x264SubTextBox.EmptyTextTip = "Clear subtitle text box by double click";
3642 //x264OutTextBox.EmptyTextTip = "Both the width and height equal zero means using original resolution";
3643 x264PathTextBox.EmptyTextTip = "Subtitle and Video must be of the same name and in the same folder";
3644 //txtvideo3.EmptyTextTip = "It is necessary to set audio parameter in the Audio tab";
3645 ExtractMP4TextBox.EmptyTextTip = "New file will be created in the original folder";
3646 txtvideo8.EmptyTextTip = "New file will be created in the original folder";
3647 txtvideo6.EmptyTextTip = "New file will be created in the original folder";
3648 //load Help Text
3649 if (File.Exists(startpath + "\\help.rtf"))
3651 HelpTextBox.LoadFile(startpath + "\\help.rtf");
3653 break;
3655 case 3:
3656 SetLang("ja-JP", this, typeof(MainForm));
3657 this.Text = string.Format("Maruko Toolbox {0}", Assembly.GetExecutingAssembly().GetName().Version.Build);
3658 x264PriorityComboBox.Items.Clear();
3659 x264PriorityComboBox.Items.AddRange(new string[] { "低", "通常以下", "通常", "通常以上", "高", "リアルタイム" });
3660 x264PriorityComboBox.SelectedIndex = 2;
3661 x264AudioModeComboBoxIndex = x264AudioModeComboBox.SelectedIndex;
3662 x264AudioModeComboBox.Items.Clear();
3663 x264AudioModeComboBox.Items.Add("オーディオ付き");
3664 x264AudioModeComboBox.Items.Add("オーディオなし");
3665 x264AudioModeComboBox.Items.Add("オーディオ コピー");
3666 x264AudioModeComboBox.SelectedIndex = x264AudioModeComboBoxIndex;
3667 x264VideoTextBox.EmptyTextTip = "ビデオファイルをここに引きずってください";
3668 x264SubTextBox.EmptyTextTip = "ダブルクリックで字幕を削除する";
3669 //x264OutTextBox.EmptyTextTip = "Both the width and height equal zero means using original resolution";
3670 x264PathTextBox.EmptyTextTip = "字幕とビデオは同じ名前と同じフォルダにある必要があります";
3671 //txtvideo3.EmptyTextTip = "It is necessary to set audio parameter in the Audio tab";
3672 ExtractMP4TextBox.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
3673 txtvideo8.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
3674 txtvideo6.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
3675 if (File.Exists(startpath + "\\help.rtf"))
3677 HelpTextBox.LoadFile(startpath + "\\help.rtf");
3679 break;
3681 default:
3682 break;
3686 private string GetCultureName()
3688 string name = "zh-CN";
3689 switch (languageComboBox.SelectedIndex)
3691 case 0:
3692 name = "zh-CN";
3693 break;
3695 case 1:
3696 name = "zh-TW";
3697 break;
3699 case 2:
3700 name = "en-US";
3701 break;
3703 case 3:
3704 name = "ja-JP";
3705 break;
3707 default:
3708 break;
3710 return name;
3713 #endregion globalization
3715 public static void RunProcess(string exe, string arg)
3717 Thread thread = new Thread(() =>
3719 ProcessStartInfo psi = new ProcessStartInfo(exe, arg);
3720 psi.CreateNoWindow = true;
3721 Process p = new Process();
3722 p.StartInfo = psi;
3723 p.Start();
3724 p.WaitForExit();
3725 MessageBox.Show("ts");
3726 p.Close();
3728 thread.IsBackground = true;
3729 thread.Start();
3732 private void AVSSaveButton_Click(object sender, EventArgs e)
3734 SaveFileDialog savefile = new SaveFileDialog();
3735 savefile.Filter = "AVS(*.avs)|*.avs";
3736 DialogResult result = savefile.ShowDialog();
3737 if (result == DialogResult.OK)
3739 File.WriteAllText(savefile.FileName, AVSScriptTextBox.Text, Encoding.Default);
3743 private void MuxReplaceAudioButton_Click(object sender, EventArgs e)
3745 if (namevideo == "")
3747 ShowErrorMessage("请选择视频文件");
3748 return;
3750 if (nameaudio == "")
3752 ShowErrorMessage("请选择音频文件");
3753 return;
3755 if (nameout == "")
3757 ShowErrorMessage("请选择输出文件");
3758 return;
3760 mux = "";
3761 //mux = "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + namevideo + "\" -c:v copy -an \"" + workPath + "\\video_noaudio.mp4\" \r\n";
3762 //mux += "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + workPath + "\\video_noaudio.mp4\" -i \"" + nameaudio + "\" -vcodec copy -acodec copy \"" + nameout + "\" \r\n";
3763 //mux += "del \"" + workPath + "\\video_noaudio.mp4\" \r\n";
3764 mux = "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + namevideo + "\" -i \"" + nameaudio + "\" -map 0:v -c:v copy -map 1:0 -c:a copy \"" + txtout.Text + "\" \r\n";
3765 batpath = workPath + "\\mux.bat";
3766 File.WriteAllText(batpath, mux, Encoding.Default);
3767 LogRecord(mux);
3768 Process.Start(batpath);
3771 #region 一图流
3773 private void AudioPicButton_Click(object sender, EventArgs e)
3775 openFileDialog1.Filter = "图片(*.jpg;*.jpeg;*.png;*.bmp;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件(*.*)|*.*";
3776 DialogResult result = openFileDialog1.ShowDialog();
3777 if (result == DialogResult.OK)
3779 AudioPicTextBox.Text = openFileDialog1.FileName;
3783 private void AudioPicAudioButton_Click(object sender, EventArgs e)
3785 openFileDialog1.Filter = "音频(*.aac;*.mp3;*.mp4;*.wav)|*.aac;*.mp3;*.mp4;*.wav|所有文件(*.*)|*.*";
3786 DialogResult result = openFileDialog1.ShowDialog();
3787 if (result == DialogResult.OK)
3789 AudioPicAudioTextBox.Text = openFileDialog1.FileName;
3793 private void AudioOnePicOutputButton_Click(object sender, EventArgs e)
3795 SaveFileDialog savefile = new SaveFileDialog();
3796 savefile.Filter = "MP4视频(*.mp4)|*.mp4|FLV视频(*.flv)|*.flv";
3797 savefile.FileName = "Single";
3798 DialogResult result = savefile.ShowDialog();
3799 if (result == DialogResult.OK)
3801 AudioOnePicOutputTextBox.Text = savefile.FileName;
3805 public int SecondsFromHHMMSS(string hhmmss)
3807 int hh = int.Parse(hhmmss.Substring(0, 2));
3808 int mm = int.Parse(hhmmss.Substring(3, 2));
3809 int ss = int.Parse(hhmmss.Substring(6, 2));
3810 return hh * 3600 + mm * 60 + ss;
3813 private void AudioOnePicButton_Click(object sender, EventArgs e)
3815 if (!File.Exists(AudioPicTextBox.Text))
3817 ShowErrorMessage("请选择图片文件");
3819 else if (!File.Exists(AudioPicAudioTextBox.Text))
3821 ShowErrorMessage("请选择音频文件");
3823 else if (AudioOnePicOutputTextBox.Text == "")
3825 ShowErrorMessage("请选择输出文件");
3827 else
3829 System.Drawing.Image img = System.Drawing.Image.FromFile(AudioPicTextBox.Text);
3830 // if not even number, chop 1 pixel out
3831 int newWidth = (img.Width % 2 == 0 ? img.Width : img.Width - 1);
3832 int newHeight = (img.Height % 2 == 0 ? img.Height : img.Height - 1);
3833 Rectangle cropArea;
3834 if (img.Width % 2 != 0 || img.Height % 2 != 0)
3836 Bitmap bmp = new Bitmap(img);
3837 cropArea = new Rectangle(0, 0, newWidth, newHeight);
3838 img = (Image)bmp.Clone(cropArea, bmp.PixelFormat);
3841 //if (img.Width % 2 != 0 || img.Height % 2 != 0)
3843 // MessageBox.Show("图片的长和宽必须是偶数。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3844 // img.Dispose();
3845 // return;
3847 //if (img.RawFormat.Equals(ImageFormat.Jpeg))
3849 // File.Copy(AudioPicTextBox.Text, tempPic, true);
3851 //else
3853 System.Drawing.Imaging.Encoder ImageEncoder = System.Drawing.Imaging.Encoder.Quality;
3854 EncoderParameter ep = new EncoderParameter(ImageEncoder, 100L);
3855 EncoderParameters eps = new EncoderParameters(1);
3856 ImageCodecInfo ImageCoderType = getImageCoderInfo("image/jpeg");
3857 eps.Param[0] = ep;
3858 img.Save(tempPic, ImageCoderType, eps);
3859 //img.Save(tempPic, ImageFormat.Jpeg);
3861 //获得音频时长
3862 MediaInfo MI = new MediaInfo();
3863 MI.Open(AudioPicAudioTextBox.Text);
3864 int seconds = SecondsFromHHMMSS(MI.Get(StreamKind.General, 0, "Duration/String3"));
3865 string ffPath = Path.Combine(workPath, "ffmpeg.exe");
3866 string neroPath = Path.Combine(workPath, "neroaacenc.exe");
3867 if (AudioCopyCheckBox.Checked)
3869 mux = "\"" + ffPath + "\" -loop 1 -r " + OnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + tempPic + "\" -c:v libx264 -crf " + OnePicCRFNum.Value.ToString() + " -y SinglePictureVideo.mp4\r\n";
3870 mux += "\"" + ffPath + "\" -i SinglePictureVideo.mp4 -i \"" + AudioPicAudioTextBox.Text + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
3871 mux += "del SinglePictureVideo.mp4\r\n";
3872 mux += "cmd";
3874 else
3876 mux = "\"" + ffPath + "\" -i \"" + AudioPicAudioTextBox.Text + "\" -f wav - |" + neroPath + " -br " + OnePicAudioBitrateNum.Value.ToString() + "000 -ignorelength -if - -of audio.mp4 -lc\r\n";
3877 mux += "\"" + ffPath + "\" -loop 1 -r " + OnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + tempPic + "\" -c:v libx264 -crf " + OnePicCRFNum.Value.ToString() + " -y SinglePictureVideo.mp4\r\n";
3878 mux += "\"" + ffPath + "\" -i SinglePictureVideo.mp4 -i audio.mp4 -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
3879 mux += "del SinglePictureVideo.mp4\r\ndel audio.mp4\r\n";
3880 mux += "cmd";
3883 string audioPath = AddExt(Path.GetFileName(AudioPicAudioTextBox.Text), "_atmp.mp4");
3884 string videoPath = AddExt(Path.GetFileName(AudioPicAudioTextBox.Text), "_vtmp.mp4");
3885 string picturePath = "c:\\" + Path.GetFileNameWithoutExtension(AudioPicTextBox.Text) + "_tmp.jpg";
3886 if (AudioCopyCheckBox.Checked)
3888 mux = "ffmpeg -loop 1 -r " + AudioOnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + picturePath + "\" -vcodec libx264 -crf 24 -y \"" + videoPath + "\"\r\n";
3889 mux += "ffmpeg -i \"" + videoPath + "\" -i \"" + AudioPicAudioTextBox.Text + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
3890 mux += "del \"" + videoPath + "\"\r\ndel \"" + picturePath + "\"\r\n";
3892 else
3894 mux = "ffmpeg -i \"" + AudioPicAudioTextBox.Text + "\" -f wav - |neroaacenc -br " + AudioOnePicAudioBitrateNum.Value.ToString() + "000 -ignorelength -if - -of \"" + audioPath + "\" -lc\r\n";
3895 mux += "ffmpeg -loop 1 -r " + AudioOnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + picturePath + "\" -vcodec libx264 -crf 24 -y \"" + videoPath + "\"\r\n";
3896 mux += "ffmpeg -i \"" + videoPath + "\" -i \"" + audioPath + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
3897 mux += "del \"" + videoPath + "\"\r\ndel \"" + audioPath + "\"\r\ndel \"" + picturePath + "\"\r\n";
3900 batpath = Path.Combine(workPath, Path.GetRandomFileName() + ".bat");
3901 File.WriteAllText(batpath, mux, Encoding.Default);
3902 LogRecord(mux);
3903 Process.Start(batpath);
3907 private void txtMI_DragDrop(object sender, DragEventArgs e)
3909 MIvideo = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
3910 MediaInfoTextBox.Text = MediaInfo(MIvideo);
3913 private void txtMI_DragEnter(object sender, DragEventArgs e)
3915 if (e.Data.GetDataPresent(DataFormats.FileDrop))
3916 e.Effect = DragDropEffects.Link;
3917 else e.Effect = DragDropEffects.None;
3920 private void AudioPicAudioTextBox_TextChanged(object sender, EventArgs e)
3922 if (File.Exists(AudioPicAudioTextBox.Text.ToString()))
3924 AudioOnePicOutputTextBox.Text = Util.ChangeExt(AudioPicAudioTextBox.Text, "_SP.flv");
3928 /// <summary>
3929 /// 获取图片编码类型信息
3930 /// </summary>
3931 /// <param name="ImageCoderType">编码类型</param>
3932 /// <returns>ImageCodecInfo</returns>
3933 private ImageCodecInfo getImageCoderInfo(string ImageCoderType)
3935 ImageCodecInfo[] coderTypeArray = ImageCodecInfo.GetImageEncoders();
3936 foreach (ImageCodecInfo coderType in coderTypeArray)
3938 if (coderType.MimeType.Equals(ImageCoderType))
3939 return coderType;
3941 return null;
3944 #endregion 一图流
3946 #region 后黑
3948 private void BlackVideoButton_Click(object sender, EventArgs e)
3950 openFileDialog1.Filter = "FLV视频(*.flv)|*.flv";
3951 DialogResult result = openFileDialog1.ShowDialog();
3952 if (result == DialogResult.OK)
3954 BlackVideoTextBox.Text = openFileDialog1.FileName;
3958 private void BlackOutputButton_Click(object sender, EventArgs e)
3960 SaveFileDialog savefile = new SaveFileDialog();
3961 savefile.Filter = "FLV视频(*.flv)|*.flv";
3962 DialogResult result = savefile.ShowDialog();
3963 if (result == DialogResult.OK)
3965 BlackOutputTextBox.Text = savefile.FileName;
3969 private void BlackPicButton_Click(object sender, EventArgs e)
3971 openFileDialog1.Filter = "图片(*.jpg;*.jpeg;*.png;*.bmp;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件(*.*)|*.*";
3972 DialogResult result = openFileDialog1.ShowDialog();
3973 if (result == DialogResult.OK)
3975 BlackPicTextBox.Text = openFileDialog1.FileName;
3979 private void BlackStartButton_Click(object sender, EventArgs e)
3981 //验证
3982 if (!File.Exists(BlackVideoTextBox.Text) || Path.GetExtension(BlackVideoTextBox.Text) != ".flv")
3984 ShowErrorMessage("请选择FLV视频文件");
3985 return;
3988 MediaInfo MI = new MediaInfo();
3989 MI.Open(BlackVideoTextBox.Text);
3990 double videobitrate = double.Parse(MI.Get(StreamKind.General, 0, "BitRate"));
3991 double targetBitrate = (double)BlackBitrateNum.Value;
3993 if (!File.Exists(BlackPicTextBox.Text) && BlackNoPicCheckBox.Checked == false)
3995 ShowErrorMessage("请选择图片文件或勾选使用黑屏");
3996 return;
3998 if (BlackOutputTextBox.Text == "")
4000 ShowErrorMessage("请选择输出文件");
4001 return;
4004 if (videobitrate < 1000000)
4006 ShowInfoMessage("此视频不需要后黑。");
4007 return;
4009 if (videobitrate > 5000000)
4011 ShowInfoMessage("此视频码率过大,请先压制再后黑。");
4012 return;
4015 //处理图片
4016 int videoWidth = int.Parse(MI.Get(StreamKind.Video, 0, "Width"));
4017 int videoHeight = int.Parse(MI.Get(StreamKind.Video, 0, "Height"));
4018 if (BlackNoPicCheckBox.Checked)
4020 Bitmap bm = new Bitmap(videoWidth, videoHeight);
4021 Graphics g = Graphics.FromImage(bm);
4022 //g.FillRectangle(Brushes.White, new Rectangle(0, 0, 800, 600));
4023 g.Clear(Color.Black);
4024 bm.Save(tempPic, ImageFormat.Jpeg);
4025 g.Dispose();
4026 bm.Dispose();
4028 else
4030 System.Drawing.Image img = System.Drawing.Image.FromFile(BlackPicTextBox.Text);
4031 int sourceWidth = img.Width;
4032 int sourceHeight = img.Height;
4033 if (img.Width % 2 != 0 || img.Height % 2 != 0)
4035 ShowErrorMessage("图片的长和宽必须都是偶数。");
4036 img.Dispose();
4037 return;
4039 if (img.Width != videoWidth || img.Height != videoHeight)
4041 ShowErrorMessage("图片的长和宽和视频不一致。");
4042 img.Dispose();
4043 return;
4045 if (img.RawFormat.Equals(ImageFormat.Jpeg))
4047 File.Copy(BlackPicTextBox.Text, tempPic, true);
4049 else
4051 System.Drawing.Imaging.Encoder ImageEncoder = System.Drawing.Imaging.Encoder.Quality;
4052 EncoderParameter ep = new EncoderParameter(ImageEncoder, 100L);
4053 EncoderParameters eps = new EncoderParameters(1);
4054 ImageCodecInfo ImageCoderType = getImageCoderInfo("image/jpeg");
4055 eps.Param[0] = ep;
4056 img.Save(tempPic, ImageCoderType, eps);
4057 //img.Save(tempPic, ImageFormat.Jpeg);
4060 int blackSecond = 300;
4061 //计算后黑时长
4062 if (BlackSecondComboBox.Text == "auto")
4064 int seconds = SecondsFromHHMMSS(MI.Get(StreamKind.General, 0, "Duration/String3"));
4065 double s = videobitrate / 1000.0 * (double)seconds / targetBitrate - (double)seconds;
4066 blackSecond = (int)s;
4067 BlackSecondComboBox.Text = blackSecond.ToString();
4069 else
4071 blackSecond = int.Parse(Regex.Replace(BlackSecondComboBox.Text.ToString(), @"\D", "")); //排除除数字外的所有字符
4074 //批处理
4075 mux = "\"" + workPath + "\\ffmpeg\" -loop 1 -r " + BlackFPSNum.Value.ToString() + " -t " + blackSecond.ToString() + " -f image2 -i \"" + tempPic + "\" -c:v libx264 -crf " + BlackCRFNum.Value.ToString() + " -y black.flv\r\n";
4076 mux += string.Format("\"{0}\\flvbind\" \"{1}\" \"{2}\" black.flv\r\n", workPath, BlackOutputTextBox.Text, BlackVideoTextBox.Text);
4077 mux += "del black.flv\r\n";
4079 batpath = Path.Combine(workPath, Path.GetRandomFileName() + ".bat");
4080 File.WriteAllText(batpath, mux, Encoding.Default);
4081 LogRecord(mux);
4082 Process.Start(batpath);
4085 private void BlackVideoTextBox_TextChanged(object sender, EventArgs e)
4087 string path = BlackVideoTextBox.Text;
4088 if (File.Exists(path))
4090 BlackOutputTextBox.Text = Util.ChangeExt(path, "_black.flv");
4094 #endregion 后黑
4096 private void BlackNoPicCheckBox_CheckedChanged(object sender, EventArgs e)
4098 BlackPicTextBox.Enabled = !BlackNoPicCheckBox.Checked;
4099 BlackPicButton.Enabled = !BlackNoPicCheckBox.Checked;
4102 private void BlackSecondComboBox_SelectedIndexChanged(object sender, EventArgs e)
4104 if (BlackSecondComboBox.Text != "auto")
4106 BlackBitrateNum.Enabled = false;
4108 else
4110 BlackBitrateNum.Enabled = true;
4114 private void SetDefaultButton_Click(object sender, EventArgs e)
4116 DialogResult dr = ShowQuestion(string.Format("是否将所有界面参数恢复到默认设置?"), "提示");
4117 if (dr == DialogResult.Yes)
4119 InitParameter();
4120 ShowInfoMessage("恢复默认设置完成!");
4124 //Ctrl+A 可以全选文本
4125 private void MediaInfoTextBox_KeyDown(object sender, KeyEventArgs e)
4127 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
4129 ((TextBox)sender).SelectAll();
4133 private void AVSScriptTextBox_KeyDown(object sender, KeyEventArgs e)
4135 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
4137 ((TextBox)sender).SelectAll();
4141 private void x264CustomParameterTextBox_KeyDown(object sender, KeyEventArgs e)
4143 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
4145 ((TextBox)sender).SelectAll();
4149 #region CheckUpdate
4151 public delegate bool CheckUpadateDelegate(out DateTime newdate, out bool isFullUpdate);
4153 public void CheckUpdateCallBack(IAsyncResult ar)
4155 DateTime NewDate;
4156 bool isFullUpdate;
4157 AsyncResult result = (AsyncResult)ar;
4158 CheckUpadateDelegate func = (CheckUpadateDelegate)result.AsyncDelegate;
4162 bool needUpdate = func.EndInvoke(out NewDate, out isFullUpdate, ar);
4163 if (needUpdate)
4165 if (isFullUpdate)
4167 DialogResult dr = ShowQuestion(string.Format("新版已于{0}发布,是否前往官网下载?", NewDate.ToString("yyyy-M-d")), "喜大普奔");
4168 if (dr == DialogResult.Yes)
4170 Process.Start("http://www.maruko.in/");
4173 else
4175 DialogResult dr = ShowQuestion(string.Format("新版已于{0}发布,是否自动升级?(文件约1.5MB)", NewDate.ToString("yyyy-M-d")), "喜大普奔");
4176 if (dr == DialogResult.Yes)
4178 FormUpdater formUpdater = new FormUpdater(startpath, NewDate.ToString());
4179 formUpdater.ShowDialog(this);
4183 else
4185 //MessageBox.Show("已经是最新版了喵!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
4188 catch (Exception) { }
4191 public bool CheckUpdate(out DateTime NewDate, out bool isFullUpdate)
4193 WebRequest request = WebRequest.Create("http://mtbftest.sinaapp.com/version.php");
4194 WebResponse wrs = request.GetResponse();
4195 // read the response ...
4196 Stream dataStream = wrs.GetResponseStream();
4197 // Open the stream using a StreamReader for easy access.
4198 StreamReader reader = new StreamReader(dataStream);
4199 // Read the content.
4200 string responseFromServer = reader.ReadToEnd();
4201 Regex dateReg = new Regex(@"Date20\S+Date");
4202 Regex VersionReg = new Regex(@"Version\d+Version");
4203 Match dateMatch = dateReg.Match(responseFromServer);
4204 Match versionMatch = VersionReg.Match(responseFromServer);
4205 NewDate = DateTime.Parse("1990-03-08");
4206 isFullUpdate = false;
4207 if (dateMatch.Success)
4209 string date = dateMatch.Value.Replace("Date", "");
4210 string version = versionMatch.Value.Replace("Version", "");
4211 NewDate = DateTime.Parse(date);
4212 int NewVersion = int.Parse(version);
4213 int s = DateTime.Compare(NewDate, ReleaseDate);
4215 int currentVersion = Assembly.GetExecutingAssembly().GetName().Version.Minor;
4216 if (NewVersion > currentVersion)
4218 isFullUpdate = true;
4220 else
4222 isFullUpdate = false;
4224 //DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
4225 if (s == 1) //NewDate is later than ReleaseDate
4227 return true;
4229 else
4231 return false;
4234 return false;
4237 private void CheckUpdateButton_Click(object sender, EventArgs e)
4239 if (Util.IsConnectInternet())
4241 WebRequest request = WebRequest.Create("http://mtbftest.sinaapp.com/version.php");
4242 request.Credentials = CredentialCache.DefaultCredentials;
4243 // Get the response.
4244 request.BeginGetResponse(new AsyncCallback(OnResponse), request);
4246 else
4248 ShowErrorMessage("这台电脑似乎没有联网呢~");
4252 protected void OnResponse(IAsyncResult ar)
4254 WebRequest wrq = (WebRequest)ar.AsyncState;
4255 WebResponse wrs = wrq.EndGetResponse(ar);
4256 // read the response ...
4257 Stream dataStream = wrs.GetResponseStream();
4258 // Open the stream using a StreamReader for easy access.
4259 StreamReader reader = new StreamReader(dataStream);
4260 // Read the content.
4261 string responseFromServer = reader.ReadToEnd();
4262 Regex dateReg = new Regex(@"Date20\S+Date");
4263 Regex VersionReg = new Regex(@"Version\d+Version");
4264 Match dateMatch = dateReg.Match(responseFromServer);
4265 Match versionMatch = VersionReg.Match(responseFromServer);
4266 DateTime NewDate = DateTime.Parse("1990-03-08");
4267 bool isFullUpdate = false;
4268 if (dateMatch.Success)
4270 string date = dateMatch.Value.Replace("Date", "");
4271 string version = versionMatch.Value.Replace("Version", "");
4272 NewDate = DateTime.Parse(date);
4273 int NewVersion = int.Parse(version);
4274 int s = DateTime.Compare(NewDate, ReleaseDate);
4276 int currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Minor;
4277 if (NewVersion > currentVersion)
4279 isFullUpdate = true;
4281 else
4283 isFullUpdate = false;
4285 //DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
4286 if (s == 1) //NewDate is later than ReleaseDate
4288 if (isFullUpdate)
4290 DialogResult dr = ShowQuestion(string.Format("新版已于{0}发布,是否前往官网下载?", NewDate.ToString("yyyy-M-d")), "喜大普奔");
4291 if (dr == DialogResult.Yes)
4293 Process.Start("http://www.maruko.in/");
4296 else
4298 DialogResult dr = ShowQuestion(string.Format("新版已于{0}发布,是否自动升级?(文件约1.5MB)", NewDate.ToString("yyyy-M-d")), "喜大普奔");
4299 if (dr == DialogResult.Yes)
4301 FormUpdater formUpdater = new FormUpdater(startpath, date);
4302 formUpdater.ShowDialog(this);
4306 else
4308 ShowInfoMessage("已经是最新版了喵!");
4311 else
4313 ShowInfoMessage("啊咧~似乎未能获取版本信息,请点击软件主页按钮查看最新版本。");
4317 #endregion CheckUpdate
4319 private void x264ShutdownCheckBox_CheckedChanged(object sender, EventArgs e)
4321 shutdownState = x264ShutdownCheckBox.Checked;
4324 private void TrayModeCheckBox_CheckedChanged(object sender, EventArgs e)
4326 trayMode = TrayModeCheckBox.Checked;
4329 private void ReleaseDatelabel_DoubleClick(object sender, EventArgs e)
4331 SplashForm sf = new SplashForm();
4332 sf.Owner = this;
4333 sf.Show();
4336 private void AudioCopyCheckBox_CheckedChanged(object sender, EventArgs e)
4338 OnePicAudioBitrateNum.Enabled = !AudioCopyCheckBox.Checked;
4341 private void HelpTextBox_LinkClicked(object sender, LinkClickedEventArgs e)
4343 Process.Start(e.LinkText);
4346 private void labelAudio_Click(object sender, EventArgs e)
4348 tabControl.SelectedIndex = 1;
4351 private void SetupAVSPlayerButton_Click(object sender, EventArgs e)
4353 openFileDialog1.Filter = "程序(*.exe)|*.exe|所有文件(*.*)|*.*";
4354 DialogResult result = openFileDialog1.ShowDialog();
4355 if (result == DialogResult.OK)
4357 SetupPlayerTextBox.Text = openFileDialog1.FileName;
4361 private void AVSAddFilterButton_Click(object sender, EventArgs e)
4363 string vsfilterDLLPath = Path.Combine(workPath, @"avs\plugins\" + AVSFilterComboBox.Text);
4364 string text = "LoadPlugin(\"" + vsfilterDLLPath + "\")" + "\r\n";
4365 AVSScriptTextBox.Text = text + AVSScriptTextBox.Text;
4368 private void AudioJoinButton_Click(object sender, EventArgs e)
4370 if (AudioListBox.Items.Count == 0)
4372 ShowErrorMessage("请输入文件!");
4373 return;
4375 else if (AudioOutputTextBox.Text == "")
4377 ShowErrorMessage("请选择输出文件");
4378 return;
4380 StringBuilder sb = new StringBuilder();
4381 ffmpeg = "";
4382 string ext = Path.GetExtension(AudioListBox.Items[0].ToString());
4383 string finish = Util.ChangeExt(AudioOutputTextBox.Text, ext);
4384 for (int i = 0; i < this.AudioListBox.Items.Count; i++)
4386 if (Path.GetExtension(AudioListBox.Items[i].ToString()) != ext)
4388 ShowErrorMessage("只允许合并相同格式文件。");
4389 return;
4391 sb.AppendLine("file '" + AudioListBox.Items[i].ToString() + "'");
4392 File.WriteAllText("concat.txt", sb.ToString());
4393 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -f concat -i concat.txt -y -c copy " + finish;
4395 ffmpeg += "\r\ncmd";
4396 batpath = workPath + "\\concat.bat";
4397 File.WriteAllText(batpath, ffmpeg, Encoding.Default);
4398 LogRecord(aac);
4399 Process.Start(batpath);
4402 #region TabControl
4404 private void tabControl_DragOver(object sender, DragEventArgs e)
4406 if (e.Data.GetDataPresent(DataFormats.FileDrop))
4408 e.Effect = DragDropEffects.All;
4409 Point pt = new Point(e.X + 2, e.Y + 2);
4410 pt = PointToClient(pt);
4411 int pi = GetTabPageByTab(pt);
4412 if (pi != -1)
4414 tabControl.SelectedIndex = pi;
4417 else e.Effect = DragDropEffects.None;
4420 /// <summary>
4421 /// Finds the TabPage whose tab is contains the given point.
4422 /// </summary>
4423 /// <param name="pt">The point (given in client coordinates) to look for a TabPage.</param>
4424 /// <returns>The TabPage whose tab is at the given point (null if there isn't one).</returns>
4425 private int GetTabPageByTab(Point pt)
4427 TabPage tp = null;
4428 int pageIndex = -1;
4429 for (int i = 0; i < tabControl.TabPages.Count; i++)
4431 Rectangle a = tabControl.GetTabRect(i);
4433 if (tabControl.GetTabRect(i).Contains(pt))
4435 tp = tabControl.TabPages[i];
4436 pageIndex = i;
4437 break;
4440 return pageIndex;
4443 private void MainForm_KeyDown(object sender, KeyEventArgs e)
4445 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D1)
4447 tabControl.SelectedIndex = 0;
4449 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D2)
4451 tabControl.SelectedIndex = 1;
4453 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D3)
4455 tabControl.SelectedIndex = 2;
4457 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D4)
4459 tabControl.SelectedIndex = 3;
4461 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D5)
4463 tabControl.SelectedIndex = 4;
4465 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D6)
4467 tabControl.SelectedIndex = 5;
4469 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D7)
4471 tabControl.SelectedIndex = 6;
4473 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D8)
4475 tabControl.SelectedIndex = 7;
4477 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D9)
4479 tabControl.SelectedIndex = 8;
4483 #endregion TabControl
4485 private void gmkvextractguibButton_Click(object sender, EventArgs e)
4487 string path = workPath + "\\gMKVExtractGUI.exe";
4488 if (File.Exists(path))
4489 Process.Start(path);
4490 else
4491 ShowErrorMessage("请检查\r\n\r\n" + path + "\r\n\r\n是否存在", "未找到程序!");
4494 private void FeedbackButton_Click(object sender, EventArgs e)
4496 FeedbackForm ff = new FeedbackForm();
4497 ff.ShowDialog();
4500 private void x264SubTextBox_DoubleClick(object sender, EventArgs e)
4502 x264SubTextBox.Clear();
4505 private void RotateButton_Click(object sender, EventArgs e)
4507 if (namevideo4 == "")
4509 ShowErrorMessage("请选择视频文件");
4511 else if (nameout5 == "")
4513 ShowErrorMessage("请选择输出文件");
4515 else
4517 clip = string.Format(@"""{0}\ffmpeg.exe"" -i ""{1}"" -vf ""transpose={2}"" -y ""{3}""",
4518 workPath, namevideo4, TransposeComboBox.SelectedIndex, nameout5) + Environment.NewLine + "cmd";
4519 batpath = workPath + "\\clip.bat";
4520 File.WriteAllText(batpath, clip, Encoding.Default);
4521 Process.Start(batpath);
4525 private void AudioPresetComboBox_SelectedIndexChanged(object sender, EventArgs e)
4527 XElement x = xdoc.Element("root").Element("Audio").Element("AudioEncoder").Element(AudioEncoderComboBox.Text).Elements()
4528 .Where(_ => _.Attribute("Name").Value == AudioPresetComboBox.Text).First();
4529 AudioCustomParameterTextBox.Text = x.Value;
4532 private void lbAuto_DrawItem(object sender, DrawItemEventArgs e)
4534 if (e.Index < 0 || e.Index >= 65535)
4535 return;
4537 e.DrawBackground();
4538 SolidBrush BlueBrush = new SolidBrush(Color.Blue);
4539 SolidBrush BlackBrush = new SolidBrush(Color.Black);
4540 Color vColor = Color.Black;
4541 string input = lbAuto.Items[e.Index].ToString();
4542 if (!string.IsNullOrEmpty(GetSubtitlePath(input)))
4544 e.Graphics.DrawString(Convert.ToString(lbAuto.Items[e.Index]), e.Font, BlueBrush, e.Bounds);
4546 else
4548 e.Graphics.DrawString(Convert.ToString(lbAuto.Items[e.Index]), e.Font, BlackBrush, e.Bounds);
4552 private string GetSubtitlePath(string videoPath)
4554 string sub = "";
4555 string splang = "";
4556 string[] subExt = { ".ass", ".ssa", ".srt" };
4557 if (x264BatchSubSpecialLanguage.Text != "none")
4558 splang = "." + x264BatchSubSpecialLanguage.Text;
4559 foreach (string ext in subExt)
4561 if (File.Exists(videoPath.Remove(videoPath.LastIndexOf(".")) + splang + ext))
4563 sub = videoPath.Remove(videoPath.LastIndexOf(".")) + splang + ext;
4564 break;
4567 return sub;
4570 private void x264ExeComboBox_SelectedIndexChanged(object sender, EventArgs e)
4572 if (x264ExeComboBox.SelectedIndex == -1)
4573 return;
4575 if (x264ExeComboBox.SelectedItem.ToString().ToLower().Contains("x265"))
4577 x264SubTextBox.Text = string.Empty;
4578 x264SubTextBox.Enabled = false;
4579 x264SubBtn.Enabled = false;
4580 x264BatchSubCheckBox.Enabled = false;
4581 x264BatchSubSpecialLanguage.Enabled = false;
4582 x264DemuxerComboBox.Enabled = false;
4583 VideoBatchFormatComboBox.Text = "mp4";
4584 VideoBatchFormatComboBox.Enabled = false;
4586 else
4588 x264SubTextBox.Enabled = true;
4589 x264SubBtn.Enabled = true;
4590 x264BatchSubCheckBox.Enabled = true;
4591 x264BatchSubSpecialLanguage.Enabled = true;
4592 x264DemuxerComboBox.Enabled = true;
4593 VideoBatchFormatComboBox.Enabled = true;
4597 #region Form
4599 public String GetCurrentDirectory()
4601 return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
4604 public static void ShowErrorMessage(String argMessage)
4606 MessageBox.Show(argMessage, "错误!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
4609 public static void ShowErrorMessage(String argMessage, String argTitle)
4611 MessageBox.Show(argMessage, argTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
4614 public static void ShowWarningMessage(String argMessage)
4616 MessageBox.Show(argMessage, "警告!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
4619 public static void ShowWarningMessage(String argMessage, String argTitle)
4621 MessageBox.Show(argMessage, argTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
4624 public static void ShowInfoMessage(String argMessage)
4626 MessageBox.Show(argMessage, "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
4629 public static void ShowInfoMessage(String argMessage, String argTitle)
4631 MessageBox.Show(argMessage, argTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
4634 public static DialogResult ShowQuestion(String argQuestion, String argTitle)
4636 return MessageBox.Show(argQuestion, argTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
4639 #endregion
4641 private void audioDeleteBt_Click(object sender, EventArgs e)
4643 if (ShowQuestion("确定要删除这条预设参数?", "提示") == DialogResult.Yes)
4647 var xls = xdoc.Element("root").Element("Audio").Element("AudioEncoder").Element(AudioEncoderComboBox.Text).Elements();
4648 foreach (var item in xls)
4650 if (item.Attribute("Name").Value == AudioPresetComboBox.Text)
4651 item.Remove();
4653 xdoc.Save("preset.xml");
4654 LoadAudioPreset();
4656 catch (Exception ex)
4658 ShowErrorMessage("删除失败! Reason: " + ex.Message);
4663 private void audioAddBt_Click(object sender, EventArgs e)
4667 string aPresetName = InputBox.Show("请输入这个预设名称", "请为预置配置命名", "新预置名称");
4668 if (!string.IsNullOrEmpty(aPresetName))
4670 var xl = xdoc.Element("root").Element("Audio").Element("AudioEncoder").Element(AudioEncoderComboBox.Text);
4671 XElement xelnew = new XElement("Parameter", AudioCustomParameterTextBox.Text,
4672 new XAttribute("Name", aPresetName));
4673 foreach (var item in xl.Elements())
4675 if (item.Attribute("Name").Value == aPresetName)
4677 ShowErrorMessage("预设名称已经存在", "预设名称重复");
4678 return;
4681 xl.Add(xelnew);
4682 xdoc.Save("preset.xml");
4683 LoadAudioPreset();
4684 AudioPresetComboBox.SelectedIndex = AudioPresetComboBox.FindString(aPresetName);
4687 catch (Exception ex)
4689 ShowErrorMessage("添加失败! Reason: " + ex.Message);
4693 private void x265CheckBox_Click(object sender, EventArgs e)
4695 if (ShowQuestion("你必须重新启动小丸工具箱才能使设置的生效 是否现在重新启动?", "需要重新启动") == DialogResult.Yes)
4696 Application.Restart();