Change UI.
[marukotoolbox.git] / mp4box / MainForm.cs
blobd46bb1b284d84ab19ec11aa2154d37eb04cf3d7c
1 using System.Collections.Generic;
2 using System.ComponentModel;
3 using System.Data;
4 using System.Drawing;
5 using System.Text;
6 using System.Windows.Forms;
7 using System.IO;
8 using System.Diagnostics;
9 using MediaInfoLib;
10 using System.Runtime.InteropServices;
11 using System.Text.RegularExpressions;
12 using System;
13 using ControlExs;
14 using System.Globalization;
15 using System.Threading;
16 using System.Configuration;
17 using System.Drawing.Imaging;
18 using System.Net;
19 namespace mp4box
21 public partial class MainForm : Form
24 public string workPath = "!undefined";
25 public bool shutdownState = false;
26 public bool trayMode = false;
28 #region Private Members Declaration
30 StringBuilder avsBuilder = new StringBuilder(1000);
31 string syspath = Environment.GetFolderPath(Environment.SpecialFolder.System).Remove(1);
32 int indexofsource;
33 int indexoftarget;
34 byte mode = 1;
35 string clip = "";
36 string MIvideo = "";
37 string namevideo = "";
38 string namevideo2 = "";
39 //string namevideo3 = "";
40 string namevideo4 = "";
41 string namevideo5 = "";
42 string namevideo6 = "";
43 string nameaudio = "";
44 string nameaudio2 = "";
45 string nameaudio3 = "";
46 string namevideo8 = "";
47 string namevideo9 = "video";
48 string nameout;
49 string nameout2;
50 string nameout3;
51 //string nameout4;
52 string nameout5;
53 string nameout6;
54 string nameout9;
55 string namesub;
56 string namesub2 = "";
57 string namesub9 = "subtitle";
58 string MItext = "把视频文件拖到这里";
59 string mkvextract;
60 string mkvmerge;
61 string mux;
62 string x264;
63 string ffmpeg;
64 string neroaac;
65 string aac;
66 string aextract;
67 string vextract;
68 string batpath;
69 string auto;
70 string startpath;
71 string avs = "";
72 string tempavspath = "";
73 string tempPic = "";
74 DateTime ReleaseDate = DateTime.Parse("2014-4-14");
76 #endregion
78 #region CPU Porocessors Number
80 [StructLayout(LayoutKind.Sequential)]
81 public struct SYSTEM_INFO
83 public uint dwOemId;
84 public uint dwPageSize;
85 public uint lpMinimumApplicationAddress;
86 public uint lpMaximumApplicationAddress;
87 public uint dwActiveProcessorMask;
88 public uint dwNumberOfProcessors;
89 public uint dwProcessorType;
90 public uint dwAllocationGranularity;
91 public uint dwProcessorLevel;
92 public uint dwProcessorRevision;
95 [DllImport("kernel32")]
96 static extern void GetSystemInfo(ref SYSTEM_INFO pSI);
98 #endregion
100 public MainForm()
102 InitializeComponent();
104 public string MediaInfo(string VideoName)
106 string info = "无视频信息";
107 if (File.Exists(VideoName))
109 MediaInfo MI = new MediaInfo();
110 MI.Open(VideoName);
111 //全局
112 string container = MI.Get(StreamKind.General, 0, "Format");
113 string bitrate = MI.Get(StreamKind.General, 0, "BitRate/String");
114 string duration = MI.Get(StreamKind.General, 0, "Duration/String1");
115 string fileSize = MI.Get(StreamKind.General, 0, "FileSize/String");
116 //视频
117 string vid = MI.Get(StreamKind.Video, 0, "ID");
118 string video = MI.Get(StreamKind.Video, 0, "Format");
119 string vBitRate = MI.Get(StreamKind.Video, 0, "BitRate/String");
120 string vSize = MI.Get(StreamKind.Video, 0, "StreamSize/String");
121 string width = MI.Get(StreamKind.Video, 0, "Width");
122 string height = MI.Get(StreamKind.Video, 0, "Height");
123 string risplayAspectRatio = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio/String");
124 string risplayAspectRatio2 = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio");
125 string frameRate = MI.Get(StreamKind.Video, 0, "FrameRate/String");
126 string bitDepth = MI.Get(StreamKind.Video, 0, "BitDepth/String");
127 string pixelAspectRatio = MI.Get(StreamKind.Video, 0, "PixelAspectRatio");
128 string encodedLibrary = MI.Get(StreamKind.Video, 0, "Encoded_Library");
129 string encodeTime = MI.Get(StreamKind.Video, 0, "Encoded_Date");
130 string codecProfile = MI.Get(StreamKind.Video, 0, "Codec_Profile");
131 string frameCount = MI.Get(StreamKind.Video, 0, "FrameCount");
134 //音频
135 string aid = MI.Get(StreamKind.Audio, 0, "ID");
136 string audio = MI.Get(StreamKind.Audio, 0, "Format");
137 string aBitRate = MI.Get(StreamKind.Audio, 0, "BitRate/String");
138 string samplingRate = MI.Get(StreamKind.Audio, 0, "SamplingRate/String");
139 string channel = MI.Get(StreamKind.Audio, 0, "Channel(s)");
140 string aSize = MI.Get(StreamKind.Audio, 0, "StreamSize/String");
141 info = Path.GetFileName(VideoName) + "\r\n" +
142 "容器:" + container + "\r\n" +
143 "总码率:" + bitrate + "\r\n" +
144 "大小:" + fileSize + "\r\n" +
145 "时长:" + duration + "\r\n" +
146 "\r\n" +
147 "视频(" + vid + "):" + video + "\r\n" +
148 "码率:" + vBitRate + "\r\n" +
149 "大小:" + vSize + "\r\n" +
150 "分辨率:" + width + "x" + height + "\r\n" +
151 "宽高比:" + risplayAspectRatio + "(" + risplayAspectRatio2 + ")" + "\r\n" +
152 "帧率:" + frameRate + "\r\n" +
153 "位深度:" + bitDepth + "\r\n" +
154 "像素宽高比:" + pixelAspectRatio + "\r\n" +
155 "编码库:" + encodedLibrary + "\r\n" +
156 "Profile:" + codecProfile + "\r\n" +
157 "编码时间:" + encodeTime + "\r\n" +
158 "总帧数:" + frameCount + "\r\n" +
160 "\r\n" +
161 "音频(" + aid + "):" + audio + "\r\n" +
162 "大小:" + aSize + "\r\n" +
163 "码率:" + aBitRate + "\r\n" +
164 "采样率:" + samplingRate + "\r\n" +
165 "声道数:" + channel + "\r\n";
166 MI.Close();
168 return info;
170 public string AddExt(string name, string ext)
172 string finish = name.Remove(name.LastIndexOf("."));
173 finish += ext;
174 return finish;
176 public string muxbat(string input1, string input2, string fps, string output)
178 mux = "\"" + workPath + "\\mp4box.exe\" -fps " + fps + " -add " + input1 + " -add " + input2 + " -new \"" + output + "\"";
179 return mux;
181 public string muxbat(string input1, string input2, string output)
183 mux = "\"" + workPath + "\\mp4box.exe\" -add " + input1 + " -add " + input2 + " -new \"" + output + "\"";
184 return mux;
186 public string x264bat(string input, string output)
188 switch (mode)
190 case 1:
191 if (x264HeightNum.Value == 0 || x264WidthNum.Value == 0 || MaintainResolutionCheckBox.Checked)
193 x264 = "\"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " --crf " + x264CRFNum.Value + " --preset 8 --demuxer " + x264DemuxerComboBox.Text + " -r 3 -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 -o \"" + output + "\" \"" + input + "\"\r\n";
195 else
197 x264 = "\"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " --crf " + x264CRFNum.Value + " --preset 8 --demuxer " + x264DemuxerComboBox.Text + " -r 3 -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 --vf resize:" + x264WidthNum.Value + "," + x264HeightNum.Value + ",,,,lanczos -o \"" + output + "\" \"" + input + "\"\r\n";
199 break;
200 case 2:
201 if (x264HeightNum.Value == 0 || x264WidthNum.Value == 0 || MaintainResolutionCheckBox.Checked)
203 x264 = "\"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " -p1 --stats \"tmp.stat\" --preset 8 --demuxer " + x264DemuxerComboBox.Text + " -r 3 -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 -o NUL \"" + input + "\" && \"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " -p2 --stats \"tmp.stat\" -B " + x264BitrateNum.Value + " --preset 8 --demuxer " + x264DemuxerComboBox.Text + " -r 3 -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 -o \"" + output + "\" \"" + input + "\"\r\n";
205 else
207 x264 = "\"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " -p1 --stats \"tmp.stat\" --preset 8 --demuxer " + x264DemuxerComboBox.Text + " -r 3 -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 --vf resize:" + x264WidthNum.Value + "," + x264HeightNum.Value + ",,,,lanczos -o NUL \"" + input + "\" && \"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " -p2 --stats \"tmp.stat\" -B " + x264BitrateNum.Value + " --preset 8 --demuxer " + x264DemuxerComboBox.Text + " -r 3 -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 --vf resize:" + x264WidthNum.Value + "," + x264HeightNum.Value + ",,,,lanczos -o \"" + output + "\" \"" + input + "\"\r\n";
209 break;
210 case 0:
211 x264 = "\"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " " + x264CustomParameterTextBox.Text + " --demuxer " + x264DemuxerComboBox.Text + " -o \"" + output + "\" \"" + input + "\"\r\n";
212 break;
215 return x264;
217 //public string x264bat(string input, string output)
219 // switch (mode)
220 // {
221 // case 1:
222 // if (numheight.Value == 0 || numwidth.Value == 0)
223 // {
224 // x264 = "\"" + workpath + "\\x264.exe\" --crf " + numcrf.Value + " --preset 8 -r 3 -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 -o \"" + output + "\" \"" + input + "\"\r\n";
225 // }
226 // else
227 // {
228 // x264 = "\"" + workpath + "\\x264.exe\" --crf " + numcrf.Value + " --preset 8 -r 3 -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 --vf resize:" + numwidth.Value + "," + numheight.Value + ",,,,lanczos -o \"" + output + "\" \"" + input + "\"\r\n";
229 // }
230 // break;
231 // case 2:
232 // if (numheight.Value == 0 || numwidth.Value == 0)
233 // {
234 // x264 = "\"" + workpath + "\\x264.exe\" -p1 --stats \"tmp.stat\" --preset 8 -r 3 -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 -o NUL \"" + input + "\" && \"" + workpath + "\\x264.exe\" -p2 --stats \"tmp.stat\" -B " + numrate.Value + " --preset 8 -r 3 -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 -o \"" + output + "\" \"" + input + "\"\r\n";
235 // }
236 // else
237 // {
238 // x264 = "\"" + workpath + "\\x264.exe\" -p1 --stats \"tmp.stat\" --preset 8 -r 3 -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 --vf resize:" + numwidth.Value + "," + numheight.Value + ",,,,lanczos -o NUL \"" + input + "\" && \"" + workpath + "\\x264.exe\" -p2 --stats \"tmp.stat\" -B " + numrate.Value + " --preset 8 -r 3 -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 --vf resize:" + numwidth.Value + "," + numheight.Value + ",,,,lanczos -o \"" + output + "\" \"" + input + "\"\r\n";
239 // }
240 // break;
241 // case 0:
242 // x264 = "\"" + workpath + "\\x264.exe\" " + txth264.Text + " -o \"" + output + "\" \"" + input + "\"\r\n";
243 // break;
244 // }
245 // return x264;
247 public string timeminus(int h1, int m1, int s1, int h2, int m2, int s2)
249 int h = 0;
250 int m = 0;
251 int s = 0;
252 s = s2 - s1;
253 if (s < 0)
255 m = -1;
256 s = s + 60;
258 m = m + m2 - m1;
259 if (m < 0)
261 h = -1;
262 m = m + 60;
264 h = h + h2 - h1;
265 return h.ToString() + ":" + m.ToString() + ":" + s.ToString();
267 public string timeplus(int h1, int m1, int s1, int h2, int m2, int s2)
269 int h = 0;
270 int m = 0;
271 int s = 0;
272 s = s1 + s2;
273 if (s >= 60)
275 m = 1;
276 s = s - 60;
278 m = m + m1 + m2;
279 if (m >= 60)
281 h = 1;
282 m = m - 60;
284 h = h + h1 + h2;
285 return h.ToString() + ":" + m.ToString() + ":" + s.ToString();
287 public string audiobat(string input, string output)
289 int AACbr = 1024 * Convert.ToInt32(AudioBitrateComboBox.Text);
290 string br = AACbr.ToString();
291 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + input + "\" -f wav temp.wav";
292 switch (AudioEncoderComboBox.SelectedIndex)
294 case 0:
295 if (AudioBitrateRadioButton.Checked)
297 neroaac = "\"" + workPath + "\\neroAacEnc.exe\" -ignorelength -lc -br " + br + " -if \"temp.wav\" -of \"" + output + "\"";
299 if (AudioCustomizeRadioButton.Checked)
301 neroaac = "\"" + workPath + "\\neroAacEnc.exe\" " + AudioCustomParameterTextBox.Text.ToString() + " -if \"temp.wav\" -of \"" + output + "\"";
303 break;
304 case 1:
305 if (AudioBitrateRadioButton.Checked)
307 neroaac = "\"" + workPath + "\\qaac.exe\" -q 2 -c " + AudioBitrateComboBox.Text + " \"temp.wav\" -o \"" + output + "\"";
309 if (AudioCustomizeRadioButton.Checked)
311 neroaac = "\"" + workPath + "\\qaac.exe\" " + AudioCustomParameterTextBox.Text.ToString() + " \"temp.wav\" -o \"" + output + "\"";
313 break;
314 case 2:
315 if (Path.GetExtension(output) == ".aac")
316 output = AddExt(output, ".wav");
317 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + input + "\" -f wav \"" + output + "\"";
318 neroaac = "";
320 break;
321 default:
322 break;
324 aac = ffmpeg + "\r\n" + neroaac + "\r\n";
325 return aac;
327 public void oneAuto(string video, string output)
329 x264 = x264bat(video, "temp.mp4");
330 x264 = x264.Replace("\r\n", "");
331 if (x264SubTextBox.Text != "")
333 if (x264.IndexOf("--vf") == -1)
335 x264 += " --vf subtitles --sub \"" + namesub2 + "\"";
337 else
339 Regex r = new Regex("--vf\\s\\S*");
340 Match m = r.Match(x264);
341 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles");
342 x264 += " --sub \"" + namesub2 + "\"";
345 x264 += " --acodec none\r\n";
346 //audio
347 //如果是avs
348 if (video.Substring(video.LastIndexOf(".") + 1) == "avs")
350 aextract = "\r\n";
351 //string nameavs = namevideo3;
352 //int a, b;
353 //StreamReader sr = new StreamReader(namevideo3, System.Text.Encoding.Default);
354 //string str = sr.ReadToEnd();
355 //a = str.IndexOf("DirectShowSource(\"");
356 //if (a == -1)
358 // a = str.IndexOf("FFVideoSource(\"");
359 // b = str.IndexOf("\"", a + 15);
360 // namevideo3 = str.Substring(a + 15, b - a - 15);
362 //else
364 // b = str.IndexOf("\"", a + 18);
365 // namevideo3 = str.Substring(a + 18, b - a - 18);
367 //if (namevideo3.IndexOf(":") != 1)
369 // namevideo3 = nameavs.Substring(0, nameavs.LastIndexOf("\\") + 1) + namevideo3;
372 else
374 aextract = audiobat(video, "temp.aac");
376 //mux
377 mux = muxbat("temp.mp4", "temp.aac", cbFPS.Text, output);
378 //if (cbDelTmp.Checked == false)
380 // auto = aextract + x264 + mux + " \r\ndel temp.aac\r\ndel temp.mp4\r\ndel temp.wav\r\n";
382 //else
384 auto = aextract + x264 + mux + " \r\n\r\n";
386 if (x264FLVCheckBox.Checked == true)
388 string flvfile = AddExt(output, "_FLV.flv");
389 auto += "\r\n\"" + workPath + "\\ffmpeg.exe\" -i \"" + output + "\" -c copy -f flv \"" + flvfile + "\" \r\n";
391 //if (x264ShutdownCheckBox.Checked)
393 // auto += "\r\n" + syspath + ":\\Windows\\System32\\shutdown -f -s -t 60\r\n";
395 //auto += "cmd";
397 public void batchAuto()
399 int i;
400 auto = "";
401 for (i = 0; i < this.lbAuto.Items.Count; i++)
403 x264 = x264bat(lbAuto.Items[i].ToString(), "temp.mp4");
404 x264 = x264.Replace("\r\n", "");
405 //判断是否内嵌字幕
406 string sub = "";
407 string asssub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".ass";
408 string ssasub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".ssa";
409 string srtsub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".srt";
410 if (x264BatchSubCheckBox.Checked)
412 if (File.Exists(asssub))
414 sub = asssub;
416 else if (File.Exists(ssasub))
418 sub = ssasub;
420 else if (File.Exists(srtsub))
422 sub = srtsub;
424 if (sub != "")
426 if (x264.IndexOf("--vf") == -1)
428 x264 += " --vf subtitles --sub \"" + sub + "\"";
430 else
432 Regex r = new Regex("--vf\\s\\S*");
433 Match m = r.Match(x264);
434 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles");
435 x264 += " --sub \"" + sub + "\"";
439 x264 += " --acodec none\r\n";
440 //audio
441 //如果是avs
442 if (lbAuto.Items[i].ToString().Substring(lbAuto.Items[i].ToString().LastIndexOf(".") + 1) == "avs")
444 aextract = "\r\n";
445 //string tempvideoname;
446 //int a, b;
447 //StreamReader sr = new StreamReader(lbAuto.Items[i].ToString(), System.Text.Encoding.Default);
448 //string str = sr.ReadToEnd();
449 //a = str.IndexOf("DirectShowSource(\"");
450 //if (a == -1)
452 // a = str.IndexOf("FFVideoSource(\"");
453 // b = str.IndexOf("\"", a + 15);
454 // tempvideoname = str.Substring(a + 15, b - a - 15);
456 //else
458 // b = str.IndexOf("\"", a + 18);
459 // tempvideoname = str.Substring(a + 18, b - a - 18);
461 //if (tempvideoname.IndexOf(":") != 1)
463 // tempvideoname = lbAuto.Items[i].ToString().Substring(0, lbAuto.Items[i].ToString().LastIndexOf("\\") + 1) + tempvideoname;
465 //aextract = audiobat(tempvideoname, "temp.aac");
466 //ffmpeg = "\"" + workpath + "\\ffmpeg.exe\" -y -i \"" + tempvideoname + "\" -f wav temp.wav";
468 else //如果不是avs
470 aextract = audiobat(lbAuto.Items[i].ToString(), "temp.aac");
472 //mux
473 string finish;
474 if (Directory.Exists(x264PathTextBox.Text))
475 finish = x264PathTextBox.Text + "\\" + Path.GetFileNameWithoutExtension(lbAuto.Items[i].ToString()) + "_onekeybatch.mp4";
476 else
477 finish = AddExt(lbAuto.Items[i].ToString(), "_onekeybatch.mp4");
478 mux = muxbat("temp.mp4", "temp.aac", finish);
479 //mux = "\"" + workpath + "\\mp4box.exe\" -add temp.mp4 -add temp.aac -new \"" + finish + "\"";
480 auto += aextract + x264 + mux + " \r\ndel temp.aac\r\ndel temp.mp4\r\ndel temp.wav\r\n";
481 //auto += aextract + x264 + mux + " \r\ndel temp.aac\r\ndel temp.mp4\r\ndel temp.wav\r\n@echo off&&echo MsgBox \"Finish!\",64,\"Maruko Toolbox\" >> msg.vbs &&call msg.vbs &&del msg.vbs\r\ncmd";
484 //if (x264ShutdownCheckBox.Checked)
486 // auto += "\r\n" + syspath + ":\\Windows\\System32\\shutdown -f -s -t 60";
489 public void batchAuto2()
491 int i;
492 auto = "";
493 for (i = 0; i < this.lbAuto.Items.Count; i++)
495 string sub = "";
496 string asssub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".ass";
497 string ssasub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".ssa";
498 string srtsub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".srt";
499 string finish;
500 if (Directory.Exists(x264PathTextBox.Text))
501 finish = x264PathTextBox.Text + "\\" + Path.GetFileNameWithoutExtension(lbAuto.Items[i].ToString()) + "_batch.mp4";
502 else
503 finish = AddExt(lbAuto.Items[i].ToString(), "_Batch.mp4");
504 x264 = x264bat(lbAuto.Items[i].ToString(), finish).Replace("\r\n", "");
505 //判断是否内嵌字幕
506 if (x264BatchSubCheckBox.Checked)
508 if (File.Exists(asssub))
510 sub = asssub;
512 else if (File.Exists(ssasub))
514 sub = ssasub;
516 else if (File.Exists(srtsub))
518 sub = srtsub;
520 if (sub != "")
522 if (x264.IndexOf("--vf") == -1)
524 x264 += " --vf subtitles --sub \"" + sub + "\"";
526 else
528 Regex r = new Regex("--vf\\s\\S*");
529 Match m = r.Match(x264);
530 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles");
531 x264 += " --sub \"" + sub + "\"";
535 switch (x264AudioModeComboBox.SelectedIndex)
537 case 1: x264 += " --acodec none"; break;
538 case 2: x264 += " --acodec copy"; break;
539 case 3: x264 += " --audiofile \"" + x264AudioParameterTextBox.Text + "\""; break;
540 case 4: x264 += " --acodec qtaac " + x264AudioParameterTextBox.Text; break;
541 case 5: x264 += " --acodec faac " + x264AudioParameterTextBox.Text; break;
542 //case 6: x264 += " --acodec libaacplus " + x264AudioParameterTextBox.Text; break;
543 case 0: break;
544 default: ; break;
546 if (cbFPS2.Text != "auto")
548 switch (cbFPS2.Text)
550 case "23.976": x264 += " --fps 24000/1001"; break;
551 case "24": x264 += " --fps 24"; break;
552 case "25": x264 += " --fps 25"; break;
553 case "29.970": x264 += " --fps 30000/1001"; break;
554 case "30": x264 += " --fps 30"; break;
555 case "50": x264 += " --fps 50"; break;
556 case "59.940": x264 += " --fps 60000/1001"; break;
557 case "60": x264 += " --fps 60"; break;
558 default: x264 += " --fps " + cbFPS2.Text; break;
561 auto = auto + "\r\n" + x264;
564 //if (x264ShutdownCheckBox.Checked)
566 // auto += "\r\n" + syspath + ":\\Windows\\System32\\shutdown -f -s -t 60";
568 //auto += "\r\n@echo off&&echo MsgBox \"Finish!\",64,\"Maruko Toolbox\" >> msg.vbs &&call msg.vbs &&del msg.vbs\r\ncmd";
569 auto += "\r\n";
571 private void btnaudio_Click(object sender, EventArgs e)
573 openFileDialog1.Filter = "音频(*.aac;*.mp3;*.mp4)|*.aac;*.mp3;*.mp4|所有文件(*.*)|*.*";
574 DialogResult result = openFileDialog1.ShowDialog();
575 if (result == DialogResult.OK)
577 nameaudio = openFileDialog1.FileName;
578 txtaudio.Text = nameaudio;
581 private void btnvideo_Click(object sender, EventArgs e)
583 openFileDialog1.Filter = "所有文件(*.*)|*.*";
584 DialogResult result = openFileDialog1.ShowDialog();
585 if (result == DialogResult.OK)
587 namevideo = openFileDialog1.FileName;
588 txtvideo.Text = namevideo;
591 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
594 private void btnout_Click(object sender, EventArgs e)
596 SaveFileDialog savefile = new SaveFileDialog();
597 savefile.Filter = "视频(*.mp4)|*.mp4";
598 DialogResult result = savefile.ShowDialog();
599 if (result == DialogResult.OK)
601 nameout = savefile.FileName;
602 txtout.Text = nameout;
605 private void btnmux_Click(object sender, EventArgs e)
607 if (namevideo == "")
609 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
610 return;
612 //else if (nameaudio == "")
614 // MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
616 if (nameout == "")
618 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
619 return;
621 if (cbFPS.Text == "auto")
624 mux = "\"" + workPath + "\\mp4box.exe\" -add \"" + namevideo + "\" -add \"" + nameaudio + "\" -new \"" + nameout + "\" \r\n cmd";
626 else
628 mux = "\"" + workPath + "\\mp4box.exe\" -fps " + cbFPS.Text + " -add \"" + namevideo + "\" -add \"" + nameaudio + "\" -new \"" + nameout + "\" \r\n cmd";
631 if (nameaudio == "") //如果没有音频流
633 mux = mux.Replace("-add \"\"", "");
636 batpath = workPath + "\\mux.bat";
637 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
638 LogRecord(mux);
639 Process.Start(batpath);
641 private void btnaextract_Click(object sender, EventArgs e)
643 if (namevideo == "")
645 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
647 else
649 aextract = "\"" + workPath + "\\mp4box.exe\" -raw 2 \"" + namevideo + "\"";
650 batpath = workPath + "\\aextract.bat";
651 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
652 LogRecord(aextract);
653 System.Diagnostics.Process.Start(batpath);
656 private void button1_Click(object sender, EventArgs e)
658 MessageBox.Show(String.Format(" \r\n有任何建议或疑问可以通过以下方式联系小丸。\nQQ:57655408\n微博:weibo.com/xiaowan3\n百度贴吧ID:小丸到达\n\n\t\t\t发布日期:2012年10月17日\n\t\t\t- ( ゜- ゜)つロ 乾杯~"), "关于", MessageBoxButtons.OK, MessageBoxIcon.Information);
660 private void btnvextract_Click(object sender, EventArgs e)
662 if (namevideo == "")
664 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
666 else
668 vextract = "\"" + workPath + "\\mp4box.exe\" -raw 1 \"" + namevideo + "\"";
669 batpath = workPath + "\\vextract.bat";
670 File.WriteAllText(batpath, vextract, UnicodeEncoding.Default);
671 LogRecord(vextract);
672 System.Diagnostics.Process.Start(batpath);
675 private void txtvideo_TextChanged(object sender, EventArgs e)
677 if (File.Exists(txtvideo.Text.ToString()))
679 namevideo = txtvideo.Text;
680 txtout.Text = AddExt(txtvideo.Text, "_Mux.mp4");
683 private void txtaudio_TextChanged(object sender, EventArgs e)
685 nameaudio = txtaudio.Text;
687 private void txtout_TextChanged(object sender, EventArgs e)
689 nameout = txtout.Text;
691 private void btnout4_Click(object sender, EventArgs e)
693 if (namevideo2 == "")
695 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
697 else if (nameout2 == "")
699 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
701 else
703 //x264
704 oneAuto(namevideo2, nameout2);
705 batpath = workPath + "\\auto.bat";
706 LogRecord(auto);
707 WorkingForm wf = new WorkingForm(auto);
708 wf.Owner = this;
709 wf.Show();
710 //File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
711 //System.Diagnostics.Process.Start(batpath);
715 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
718 #region Delete Temp Files
720 if (SetupDeleteTempFileCheckBox.Checked && !workPath.Equals("!undefined"))
722 List<string> deleteFileList = new List<string>();
724 string systemDisk = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 3);
725 string systemTempPath = systemDisk + @"windows\temp";
727 //Delete all BAT files
728 DirectoryInfo theFolder = new DirectoryInfo(workPath);
729 foreach (FileInfo NextFile in theFolder.GetFiles())
731 if (NextFile.Extension.Equals(".bat"))
732 deleteFileList.Add(NextFile.FullName);
735 //string[] deletedfiles = { tempPic, "msg.vbs", tempavspath, "temp.avs", "clip.bat", "aextract.bat", "vextract.bat",
736 // "x264.bat", "aac.bat", "auto.bat", "mux.bat", "flv.bat", "mkvmerge.bat", "mkvextract.bat", "tmp.stat.mbtree", "tmp.stat" };
737 string[] deletedfiles = { "temp.wav", "temp.aac", "temp.mp4", tempPic, tempavspath, workPath + "msg.vbs", workPath + "tmp.stat.mbtree", workPath + "tmp.stat" };
738 deleteFileList.AddRange(deletedfiles);
740 foreach (string file in deleteFileList)
742 File.Delete(file);
745 #endregion
747 #region Save Settings
748 Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
749 cfa.AppSettings.Settings["x264CRF"].Value = x264CRFNum.Value.ToString();
750 cfa.AppSettings.Settings["x264Bitrate"].Value = x264BitrateNum.Value.ToString();
751 cfa.AppSettings.Settings["x264AudioParameter"].Value = x264AudioParameterTextBox.Text;
752 cfa.AppSettings.Settings["x264AudioMode"].Value = x264AudioModeComboBox.SelectedIndex.ToString();
753 cfa.AppSettings.Settings["x264Exe"].Value = x264ExeComboBox.SelectedIndex.ToString();
754 cfa.AppSettings.Settings["x264Demuxer"].Value = x264DemuxerComboBox.SelectedIndex.ToString();
755 cfa.AppSettings.Settings["x264Width"].Value = x264WidthNum.Value.ToString();
756 cfa.AppSettings.Settings["x264Height"].Value = x264HeightNum.Value.ToString();
757 cfa.AppSettings.Settings["x264CustomParameter"].Value = x264CustomParameterTextBox.Text;
758 cfa.AppSettings.Settings["x264Priority"].Value = x264PriorityComboBox.SelectedIndex.ToString();
759 cfa.AppSettings.Settings["AVSScript"].Value = AVSScriptTextBox.Text;
760 cfa.AppSettings.Settings["AudioEncoder"].Value = AudioEncoderComboBox.SelectedIndex.ToString();
761 cfa.AppSettings.Settings["AudioCustomParameter"].Value = AudioCustomParameterTextBox.Text;
762 cfa.AppSettings.Settings["AudioParameter"].Value = AudioBitrateComboBox.Text;
763 cfa.AppSettings.Settings["OnePicAudioBitrate"].Value = OnePicAudioBitrateNum.Value.ToString();
764 cfa.AppSettings.Settings["OnePicFPS"].Value = OnePicFPSNum.Value.ToString();
765 cfa.AppSettings.Settings["OnePicCRF"].Value = OnePicCRFNum.Value.ToString();
766 cfa.AppSettings.Settings["BlackFPS"].Value = BlackFPSNum.Value.ToString();
767 cfa.AppSettings.Settings["BlackCRF"].Value = BlackCRFNum.Value.ToString();
768 cfa.AppSettings.Settings["BlackBitrate"].Value = BlackBitrateNum.Value.ToString();
769 cfa.AppSettings.Settings["SetupDeleteTempFile"].Value = SetupDeleteTempFileCheckBox.Checked.ToString();
770 cfa.AppSettings.Settings["TrayMode"].Value = TrayModeCheckBox.Checked.ToString();
771 cfa.AppSettings.Settings["LanguageIndex"].Value = languageComboBox.SelectedIndex.ToString();
772 cfa.AppSettings.Settings["SplashScreen"].Value = SplashScreenCheckBox.Checked.ToString();
773 cfa.AppSettings.Settings["x264Threads"].Value = x264ThreadsComboBox.SelectedIndex.ToString();
775 cfa.Save();
776 ConfigurationManager.RefreshSection("appSettings"); // 刷新命名节,在下次检索它时将从磁盘重新读取它。记住应用程序要刷新节点
777 #endregion
780 private void txtvideo4_TextChanged(object sender, EventArgs e)
782 if (File.Exists(txtvideo4.Text.ToString()))
784 namevideo4 = txtvideo4.Text;
785 //string finish = namevideo4.Insert(namevideo4.LastIndexOf(".")-1,"");
786 //string ext = namevideo4.Substring(namevideo4.LastIndexOf(".") + 1, 3);
787 //finish += "_clip." + ext;
788 string finish = namevideo4.Insert(namevideo4.LastIndexOf("."), "_clip");
789 txtout5.Text = finish;
792 private void txtout5_TextChanged(object sender, EventArgs e)
794 nameout5 = txtout5.Text;
796 private void btnvideo4_Click(object sender, EventArgs e)
798 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
799 DialogResult result = openFileDialog1.ShowDialog();
800 if (result == DialogResult.OK)
802 namevideo4 = openFileDialog1.FileName;
803 txtvideo4.Text = namevideo4;
806 private void btnout5_Click(object sender, EventArgs e)
808 SaveFileDialog savefile = new SaveFileDialog();
809 savefile.Filter = "视频(*.*)|*.*";
810 DialogResult result = savefile.ShowDialog();
811 if (result == DialogResult.OK)
813 nameout5 = savefile.FileName;
814 txtout5.Text = nameout5;
818 public static bool IsWindowsVistaOrNewer
820 get { return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 6); }
824 /// <summary>
825 /// 还原默认参数
826 /// </summary>
827 private void InitParameter()
829 x264CRFNum.Value = 24;
830 x264BitrateNum.Value = 800;
831 x264AudioParameterTextBox.Text = "--abitrate 128";
832 x264AudioModeComboBox.SelectedIndex = 5;
833 x264DemuxerComboBox.SelectedIndex = 2;
834 x264WidthNum.Value = 0;
835 x264HeightNum.Value = 0;
836 x264CustomParameterTextBox.Text = "";
837 x264PriorityComboBox.SelectedIndex = 2;
838 AudioEncoderComboBox.SelectedIndex = 0;
839 AudioCustomParameterTextBox.Text = "";
840 AudioBitrateComboBox.Text = "128";
841 OnePicAudioBitrateNum.Value = 128;
842 OnePicFPSNum.Value = 1;
843 OnePicCRFNum.Value = 24;
844 AVSScriptTextBox.Text = "";
845 BlackFPSNum.Value = 1;
846 BlackCRFNum.Value = 51;
847 BlackBitrateNum.Value = 900;
848 SetupDeleteTempFileCheckBox.Checked = true;
854 private void Form1_Load(object sender, EventArgs e)
856 var modulename = Process.GetCurrentProcess().MainModule.ModuleName;
857 var procesname = Path.GetFileNameWithoutExtension(modulename);
858 Process[] processes = Process.GetProcessesByName(procesname);
859 if (processes.Length > 1)
861 MessageBox.Show("你已经打开了一个小丸工具箱喔!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
862 this.Close();
865 SYSTEM_INFO pSI = new SYSTEM_INFO();
866 GetSystemInfo(ref pSI);
867 int processorNumber = (int)pSI.dwNumberOfProcessors;
869 for (int i = 1; i <= 32; i++)
871 x264ThreadsComboBox.Items.Add(i.ToString());
873 //Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-TW");
874 //use YAHEI in VistaOrNewer
875 //if (IsWindowsVistaOrNewer)
877 // FontFamily myFontFamily = new FontFamily("微软雅黑"); //采用哪种字体
878 // Font myFont = new Font(myFontFamily, 9, FontStyle.Regular); //字是那种字体,显示的风格
879 // this.Font = myFont;
882 //define workpath
883 startpath = System.Windows.Forms.Application.StartupPath;
884 workPath = startpath + "\\tools";
885 if (!Directory.Exists(workPath))
886 Directory.CreateDirectory(workPath);
887 //string diskSymbol = startpath.Substring(0, 1);
889 string systemDisk = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 3);
890 string systemTempPath = systemDisk + @"windows\temp";
891 tempavspath = systemTempPath + "\\temp.avs";
892 tempPic = systemTempPath + "\\marukotemp.jpg";
893 InitParameter();
895 DirectoryInfo folder = new DirectoryInfo(workPath);
896 foreach (FileInfo FileName in folder.GetFiles())
898 if (FileName.Name.Contains("x264") && Path.GetExtension(FileName.Name) == ".exe")
900 x264ExeComboBox.Items.Add(FileName.Name);
904 ReleaseDatelabel.Text = ReleaseDate.ToString("yyyy-M-d");
906 //load Help Text
907 if (File.Exists(startpath + "\\help.txt"))
909 StreamReader sr = new StreamReader(startpath + "\\help.txt", System.Text.Encoding.UTF8);
910 HelpTextBox.Text = sr.ReadToEnd();
911 sr.Close();
915 //load settings
916 x264CRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264CRF"]);
917 x264BitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Bitrate"]);
918 x264AudioParameterTextBox.Text = ConfigurationManager.AppSettings["x264AudioParameter"];
919 x264AudioModeComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264AudioMode"]);
920 x264ExeComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Exe"]);
921 x264DemuxerComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Demuxer"]);
922 x264WidthNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Width"]);
923 x264HeightNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Height"]);
924 x264CustomParameterTextBox.Text = ConfigurationManager.AppSettings["x264CustomParameter"];
925 x264PriorityComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Priority"]);
926 AVSScriptTextBox.Text = ConfigurationManager.AppSettings["AVSScript"];
927 AudioEncoderComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["AudioEncoder"]);
928 AudioCustomParameterTextBox.Text = ConfigurationManager.AppSettings["AudioCustomParameter"];
929 AudioBitrateComboBox.Text = ConfigurationManager.AppSettings["AudioBitrate"];
930 OnePicAudioBitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicAudioBitrate"]);
931 OnePicFPSNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicFPS"]);
932 OnePicCRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicCRF"]);
933 BlackFPSNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackFPS"]);
934 BlackCRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackCRF"]);
935 BlackBitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackBitrate"]);
936 SetupDeleteTempFileCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["SetupDeleteTempFile"]);
937 x264ThreadsComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Threads"]);
938 TrayModeCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["TrayMode"]);
939 SplashScreenCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["SplashScreen"]);
941 if (x264ExeComboBox.SelectedIndex == -1)
943 x264ExeComboBox.SelectedIndex = x264ExeComboBox.Items.IndexOf("x264_32_tMod-8bit-420.exe");
946 if (int.Parse(ConfigurationManager.AppSettings["LanguageIndex"]) == -1) //First Startup
948 string culture = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
949 switch (culture)
951 case "zh-CN":
952 languageComboBox.SelectedIndex = 0;
953 break;
954 case "zh-SG":
955 languageComboBox.SelectedIndex = 0;
956 break;
957 case "zh-TW":
958 languageComboBox.SelectedIndex = 1;
959 break;
960 case "zh-HK ":
961 languageComboBox.SelectedIndex = 1;
962 break;
963 case "zh-MO":
964 languageComboBox.SelectedIndex = 1;
965 break;
966 case "en-US":
967 languageComboBox.SelectedIndex = 2;
968 break;
969 case "ja-JP":
970 languageComboBox.SelectedIndex = 3;
971 break;
972 default:
973 break;
976 else
977 languageComboBox.SelectedIndex = int.Parse(ConfigurationManager.AppSettings["LanguageIndex"]);
979 catch (Exception)
981 throw;
983 //create directory
984 string preset = workPath + "\\preset";
985 if (!Directory.Exists(preset))
986 Directory.CreateDirectory(preset);
987 DirectoryInfo TheFolder = new DirectoryInfo(preset);
988 foreach (FileInfo FileName in TheFolder.GetFiles())
990 cbX264.Items.Add(FileName.Name.Replace(".txt", ""));
995 private void button2_Click(object sender, EventArgs e)
997 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
998 DialogResult result = openFileDialog1.ShowDialog();
999 if (result == DialogResult.OK)
1001 namevideo6 = openFileDialog1.FileName;
1002 txtvideo6.Text = namevideo6;
1005 private void label16_Click(object sender, EventArgs e)
1008 private void button3_Click(object sender, EventArgs e)
1010 if (namevideo6 == "")
1012 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1014 else
1016 mkvextract = workPath + "\\ mkvextract.exe tracks \"" + namevideo6 + "\" 1:video.h264 2:audio.aac";
1017 batpath = workPath + "\\mkvextract.bat";
1018 File.WriteAllText(batpath, mkvextract, UnicodeEncoding.Default);
1019 System.Diagnostics.Process.Start(batpath);
1022 private void button4_Click(object sender, EventArgs e)
1024 openFileDialog1.Filter = "视频(*.mp4)|*.mp4|所有文件(*.*)|*.*";
1025 DialogResult result = openFileDialog1.ShowDialog();
1026 if (result == DialogResult.OK)
1028 namevideo5 = openFileDialog1.FileName;
1029 txtvideo5.Text = namevideo5;
1032 private void button5_Click(object sender, EventArgs e)
1034 openFileDialog1.Filter = "音频(*.mp3)|*.mp3|音频(*.aac)|*.aac|所有文件(*.*)|*.*";
1035 DialogResult result = openFileDialog1.ShowDialog();
1036 if (result == DialogResult.OK)
1038 nameaudio3 = openFileDialog1.FileName;
1039 txtaudio3.Text = nameaudio3;
1042 private void button6_Click(object sender, EventArgs e)
1044 SaveFileDialog savefile = new SaveFileDialog();
1045 savefile.Filter = "视频(*.mkv)|*.mkv";
1046 DialogResult result = savefile.ShowDialog();
1047 if (result == DialogResult.OK)
1049 nameout6 = savefile.FileName;
1050 txtout6.Text = nameout6;
1053 private void button7_Click(object sender, EventArgs e)
1055 if (namevideo5 == "")
1057 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1059 else if (nameaudio3 == "")
1061 MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1063 else if (nameout6 == "")
1065 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1067 else
1069 mkvmerge = workPath + "\\mkvmerge.exe -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\"";
1070 batpath = workPath + "\\mkvmerge.bat";
1071 File.WriteAllText(batpath, mkvmerge, UnicodeEncoding.Default);
1072 System.Diagnostics.Process.Start(batpath);
1076 private void button2_Click_1(object sender, EventArgs e)
1078 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1079 DialogResult result = openFileDialog1.ShowDialog();
1080 if (result == DialogResult.OK)
1082 namevideo5 = openFileDialog1.FileName;
1083 txtvideo5.Text = namevideo5;
1086 private void button6_Click_1(object sender, EventArgs e)
1088 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
1089 DialogResult result = openFileDialog1.ShowDialog();
1090 if (result == DialogResult.OK)
1092 namevideo6 = openFileDialog1.FileName;
1093 txtvideo6.Text = namevideo6;
1096 private void button7_Click_1(object sender, EventArgs e)
1098 if (namevideo5 == "" && nameaudio3 == "")
1100 MessageBox.Show("请选择文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1102 else
1104 if (txtaudio3.Text != "" && txtsub.Text != "")
1106 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\" \"" + namesub + "\"";
1108 if (txtaudio3.Text == "" && txtsub.Text == "")
1110 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\"";
1112 if (txtaudio3.Text != "" && txtsub.Text == "")
1114 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\"";
1116 if (txtaudio3.Text == "" && txtsub.Text != "")
1118 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + namesub + "\"";
1120 mkvmerge += "\r\ncmd";
1121 batpath = workPath + "\\mkvmerge.bat";
1122 File.WriteAllText(batpath, mkvmerge, UnicodeEncoding.Default);
1123 LogRecord(mkvmerge);
1124 System.Diagnostics.Process.Start(batpath);
1127 private void button4_Click_1(object sender, EventArgs e)
1129 SaveFileDialog savefile = new SaveFileDialog();
1130 savefile.Filter = "视频(*.mkv)|*.mkv";
1131 DialogResult result = savefile.ShowDialog();
1132 if (result == DialogResult.OK)
1134 nameout6 = savefile.FileName;
1135 txtout6.Text = nameout6;
1138 private void button3_Click_1(object sender, EventArgs e)
1140 openFileDialog1.Filter = "音频(*.mp3;*.aac)|*.mp3;*.aac|所有文件(*.*)|*.*";
1141 DialogResult result = openFileDialog1.ShowDialog();
1142 if (result == DialogResult.OK)
1144 nameaudio3 = openFileDialog1.FileName;
1145 txtaudio3.Text = nameaudio3;
1148 private void button5_Click_1(object sender, EventArgs e)
1150 openFileDialog1.Filter = "ASS字幕(*.ass;*.srt)|*.ass;*.srt|所有文件(*.*)|*.*";
1151 DialogResult result = openFileDialog1.ShowDialog();
1152 if (result == DialogResult.OK)
1154 namesub = openFileDialog1.FileName;
1155 txtsub.Text = namesub;
1158 private void button8_Click(object sender, EventArgs e)
1160 if (namevideo6 == "")
1162 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1164 else
1166 int i = namevideo6.IndexOf(".mkv");
1167 string mkvname = namevideo6.Remove(i);
1168 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 1:\"" + mkvname + "_video.h264\" 2:\"" + mkvname + "_audio.aac\"";
1169 batpath = workPath + "\\mkvextract.bat";
1170 File.WriteAllText(batpath, mkvextract, UnicodeEncoding.Default);
1171 System.Diagnostics.Process.Start(batpath);
1174 private void txtvideo5_TextChanged(object sender, EventArgs e)
1176 if (File.Exists(txtvideo5.Text.ToString()))
1178 namevideo5 = txtvideo5.Text;
1179 string finish = namevideo5.Remove(namevideo5.LastIndexOf("."));
1180 finish += "_mkv封装.mkv";
1181 txtout6.Text = finish;
1184 private void txtaudio3_TextChanged(object sender, EventArgs e)
1186 nameaudio3 = txtaudio3.Text;
1188 private void txtsub_TextChanged(object sender, EventArgs e)
1190 namesub = txtsub.Text;
1192 private void txtout6_TextChanged_1(object sender, EventArgs e)
1194 nameout6 = txtout6.Text;
1196 private void txtvideo6_TextChanged(object sender, EventArgs e)
1198 namevideo6 = txtvideo6.Text;
1201 private void btnAutoAdd_Click(object sender, EventArgs e)
1203 openFileDialog1.Multiselect = true;
1204 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1205 DialogResult result = openFileDialog1.ShowDialog();
1206 if (result == DialogResult.OK)
1208 lbAuto.Items.AddRange(openFileDialog1.FileNames);
1211 private void btnAutoDel_Click(object sender, EventArgs e)
1213 if (lbAuto.Items.Count > 0)
1215 if (lbAuto.SelectedItems.Count > 0)
1217 int index = lbAuto.SelectedIndex;
1218 lbAuto.Items.RemoveAt(lbAuto.SelectedIndex);
1219 if (index == lbAuto.Items.Count)
1221 lbAuto.SelectedIndex = index - 1;
1223 if (index >= 0 && index < lbAuto.Items.Count && lbAuto.Items.Count > 0)
1225 lbAuto.SelectedIndex = index;
1230 private void btnAutoClear_Click(object sender, EventArgs e)
1232 lbAuto.Items.Clear();
1234 private void lbAuto_DragDrop(object sender, DragEventArgs e)
1236 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
1238 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
1239 foreach (String s in files)
1241 (sender as ListBox).Items.Add(s);
1244 ListBox listbox = (ListBox)sender;
1245 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
1246 if (indexoftarget != ListBox.NoMatches)
1248 string temp = listbox.Items[indexoftarget].ToString();
1249 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
1250 listbox.Items[indexofsource] = temp;
1251 listbox.SelectedIndex = indexoftarget;
1254 private void lbAuto_DragEnter(object sender, DragEventArgs e)
1256 //if (e.Data.GetDataPresent(DataFormats.FileDrop))
1257 // e.Effect = DragDropEffects.All;
1258 //else e.Effect = DragDropEffects.None;
1260 private void lbAuto_DragOver(object sender, DragEventArgs e)
1262 //拖动源和放置的目的地一定是一个ListBox
1263 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lbAuto))
1265 e.Effect = DragDropEffects.Move;
1267 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
1269 e.Effect = DragDropEffects.Link;
1271 else e.Effect = DragDropEffects.None;
1273 private void lbAuto_MouseDown(object sender, MouseEventArgs e)
1275 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
1276 if (indexofsource != ListBox.NoMatches)
1278 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
1281 private void btnBatchAuto_Click(object sender, EventArgs e)
1283 if (lbAuto.Items.Count != 0)
1285 batchAuto2();
1286 batpath = workPath + "\\auto.bat";
1287 LogRecord(auto);
1288 WorkingForm wf = new WorkingForm(auto, lbAuto.Items.Count);
1289 wf.Owner = this;
1290 wf.Show();
1292 //File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
1293 //System.Diagnostics.Process.Start(batpath);
1295 else MessageBox.Show("请输入视频!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1297 private void lbffmpeg_MouseDown(object sender, MouseEventArgs e)
1299 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
1300 if (indexofsource != ListBox.NoMatches)
1302 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
1305 private void lbffmpeg_DragDrop(object sender, DragEventArgs e)
1307 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
1309 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
1310 foreach (String s in files)
1312 (sender as ListBox).Items.Add(s);
1315 ListBox listbox = (ListBox)sender;
1316 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
1317 if (indexoftarget != ListBox.NoMatches)
1319 string temp = listbox.Items[indexoftarget].ToString();
1320 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
1321 listbox.Items[indexofsource] = temp;
1322 listbox.SelectedIndex = indexoftarget;
1325 private void lbffmpeg_DragOver(object sender, DragEventArgs e)
1327 //拖动源和放置的目的地一定是一个ListBox
1328 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lbffmpeg))
1330 e.Effect = DragDropEffects.Move;
1332 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
1334 e.Effect = DragDropEffects.Link;
1336 else e.Effect = DragDropEffects.None;
1338 private void btnffmpegAdd_Click(object sender, EventArgs e)
1340 openFileDialog1.Multiselect = true;
1341 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1342 DialogResult result = openFileDialog1.ShowDialog();
1343 if (result == DialogResult.OK)
1345 lbffmpeg.Items.AddRange(openFileDialog1.FileNames);
1348 private void btnffmpegDel_Click(object sender, EventArgs e)
1350 if (lbffmpeg.Items.Count > 0)
1352 if (lbffmpeg.SelectedItems.Count > 0)
1354 int index = lbffmpeg.SelectedIndex;
1355 lbffmpeg.Items.RemoveAt(lbffmpeg.SelectedIndex);
1356 if (index == lbffmpeg.Items.Count)
1358 lbffmpeg.SelectedIndex = index - 1;
1360 if (index >= 0 && index < lbffmpeg.Items.Count && lbffmpeg.Items.Count > 0)
1362 lbffmpeg.SelectedIndex = index;
1367 private void btnffmpegClear_Click(object sender, EventArgs e)
1369 lbffmpeg.Items.Clear();
1371 private void btnBatchFLV_Click(object sender, EventArgs e)
1373 if (lbffmpeg.Items.Count != 0)
1375 string finish;
1376 int i;
1377 ffmpeg = "";
1378 for (i = 0; i < this.lbffmpeg.Items.Count; i++)
1380 finish = lbffmpeg.Items[i].ToString().Remove(lbffmpeg.Items[i].ToString().LastIndexOf(".")) + "_FLV封装.flv";
1381 ffmpeg += "\"" + workPath + "\\ffmpeg.exe\" -i \"" + lbffmpeg.Items[i].ToString() + "\" -c copy -f flv \"" + finish + "\" \r\n";
1383 ffmpeg += "\r\ncmd";
1384 batpath = workPath + "\\flv.bat";
1385 File.WriteAllText(batpath, ffmpeg, UnicodeEncoding.Default);
1386 LogRecord(ffmpeg);
1387 System.Diagnostics.Process.Start(batpath);
1388 //lbffmpeg.Items.Clear();
1390 else MessageBox.Show("请输入视频!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1392 private void btnBatchMP4_Click(object sender, EventArgs e)
1394 if (lbffmpeg.Items.Count != 0)
1396 string finish;
1397 int i;
1398 ffmpeg = "";
1399 for (i = 0; i < this.lbffmpeg.Items.Count; i++)
1401 finish = lbffmpeg.Items[i].ToString().Remove(lbffmpeg.Items[i].ToString().LastIndexOf(".")) + "_MP4封装.mp4";
1402 ffmpeg += "\"" + workPath + "\\ffmpeg.exe\" -i \"" + lbffmpeg.Items[i].ToString() + "\" -c copy -f mp4 \"" + finish + "\" \r\n";
1404 ffmpeg += "\r\ncmd";
1405 batpath = workPath + "\\flv.bat";
1406 File.WriteAllText(batpath, ffmpeg, UnicodeEncoding.Default);
1407 LogRecord(ffmpeg);
1408 System.Diagnostics.Process.Start(batpath);
1409 //lbffmpeg.Items.Clear();
1411 else MessageBox.Show("请输入视频!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1413 private void txtvideo8_TextChanged(object sender, EventArgs e)
1415 namevideo8 = txtvideo8.Text;
1417 private void btnvextract8_Click(object sender, EventArgs e)
1419 if (namevideo8 == "")
1421 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1423 else
1425 vextract = "\"" + workPath + "\\FLVExtractCL.exe\" -v \"" + namevideo8 + "\"";
1426 batpath = workPath + "\\vextract.bat";
1427 File.WriteAllText(batpath, vextract, UnicodeEncoding.Default);
1428 LogRecord(vextract);
1429 System.Diagnostics.Process.Start(batpath);
1432 private void btnaextract8_Click(object sender, EventArgs e)
1434 if (namevideo8 == "")
1436 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1438 else
1440 aextract = "\"" + workPath + "\\FLVExtractCL.exe\" -a \"" + namevideo8 + "\"";
1441 batpath = workPath + "\\aextract.bat";
1442 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
1443 LogRecord(aextract);
1444 System.Diagnostics.Process.Start(batpath);
1447 private void btnvideo8_Click(object sender, EventArgs e)
1449 openFileDialog1.Filter = "视频(*.flv;*.hlv)|*.flv;*.hlv";
1450 DialogResult result = openFileDialog1.ShowDialog();
1451 if (result == DialogResult.OK)
1453 namevideo8 = openFileDialog1.FileName;
1454 txtvideo8.Text = namevideo;
1457 private void btnpreview9_Click(object sender, EventArgs e)
1459 if (AVSScriptTextBox.Text != "")
1461 string filepath = workPath + "\\temp.avs";
1462 File.WriteAllText(filepath, AVSScriptTextBox.Text.ToString(), UnicodeEncoding.Default);
1463 PreviewForm form2 = new PreviewForm();
1464 form2.Show();
1465 form2.axWindowsMediaPlayer1.URL = filepath;
1467 else
1469 MessageBox.Show("请输入正确的AVS脚本!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1472 private void txtout_MouseDoubleClick(object sender, MouseEventArgs e)
1474 if (File.Exists(txtout.Text.ToString()))
1476 System.Diagnostics.Process.Start(txtout.Text.ToString());
1479 private void txtout3_MouseDoubleClick(object sender, MouseEventArgs e)
1481 if (File.Exists(txtout3.Text.ToString()))
1483 System.Diagnostics.Process.Start(txtout3.Text.ToString());
1486 private void txtout6_MouseDoubleClick(object sender, MouseEventArgs e)
1488 if (File.Exists(txtout6.Text.ToString()))
1490 System.Diagnostics.Process.Start(txtout6.Text.ToString());
1493 private void txtout9_MouseDoubleClick(object sender, MouseEventArgs e)
1495 if (File.Exists(txtout9.Text.ToString()))
1497 System.Diagnostics.Process.Start(txtout9.Text.ToString());
1500 private void txtvideo9_TextChanged(object sender, EventArgs e)
1502 if (File.Exists(txtvideo9.Text.ToString()))
1504 namevideo9 = txtvideo9.Text;
1505 string finish = namevideo9.Remove(namevideo9.LastIndexOf("."));
1506 finish += "_AVS压制.mp4";
1507 txtout9.Text = finish;
1508 GenerateAVS();
1510 //if (txtvideo9.Text != "")
1512 // if (txtAVS.Text != "")
1513 // {
1514 // txtAVS.Text = txtAVS.Text.Replace(prevideo9, txtvideo9.Text);
1515 // }
1516 // else
1517 // {
1518 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1519 // foreach (FileInfo FileName in TheFolder.GetFiles())
1520 // {
1521 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1522 // }
1523 // avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\n" + "TextSub(\"" + namesub9 + "\")\r\n";
1524 // txtAVS.Text = avs;
1525 // avs = "";
1526 // }
1527 // prevideo9 = txtvideo9.Text;
1530 private void txtsub9_TextChanged(object sender, EventArgs e)
1532 namesub9 = txtsub9.Text;
1533 GenerateAVS();
1534 //if (txtAVS.Text != "")
1536 // txtAVS.Text=txtAVS.Text.Replace(namesub9, txtsub9.Text);
1537 // namesub9 = txtsub9.Text;
1539 //else
1541 // namesub9 = txtsub9.Text;
1542 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1543 // foreach (FileInfo FileName in TheFolder.GetFiles())
1544 // {
1545 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1546 // }
1547 // avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\n" + "TextSub(\"" + namesub9 + "\")\r\n";
1548 // txtAVS.Text = avs;
1549 // avs = "";
1552 private void txtout9_TextChanged(object sender, EventArgs e)
1554 nameout9 = txtout9.Text;
1556 private void btnAVS9_Click(object sender, EventArgs e)
1558 if (String.IsNullOrEmpty(nameout9))
1560 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1562 else
1564 string filepath = tempavspath;
1565 //string filepath = workpath + "\\temp.avs";
1566 File.WriteAllText(filepath, AVSScriptTextBox.Text, UnicodeEncoding.Default);
1567 x264 = x264bat(filepath, nameout9).Replace("\r\n", "");
1568 x264 += " --acodec none\r\n";
1569 batpath = workPath + "\\x264.bat";
1570 File.WriteAllText(batpath, x264, UnicodeEncoding.Default);
1571 LogRecord(x264);
1572 System.Diagnostics.Process.Start(batpath);
1575 private void btnout9_Click(object sender, EventArgs e)
1577 SaveFileDialog savefile = new SaveFileDialog();
1578 savefile.Filter = "视频(*.mp4)|*.mp4";
1579 DialogResult result = savefile.ShowDialog();
1580 if (result == DialogResult.OK)
1582 txtout9.Text = nameout9 = savefile.FileName;
1585 private void btnAVSone_Click(object sender, EventArgs e)
1587 if (String.IsNullOrEmpty(nameout9))
1589 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1591 else
1593 string filepath = workPath + "\\temp.avs";
1594 File.WriteAllText(filepath, AVSScriptTextBox.Text, UnicodeEncoding.Default);
1595 x264 = x264bat(filepath, "temp.mp4").Replace("\r\n", "");
1596 x264 += " --acodec none\r\n";
1597 //audio
1598 aextract = audiobat(namevideo9, "temp.aac");
1599 //mux
1600 mux = muxbat("temp.mp4", "temp.aac", "23.976", nameout9);
1601 //if (cbDelTmp.Checked == false)
1603 // auto = aextract + x264 + "\r\n" + mux + " \r\ndel temp.aac\r\ndel temp.mp4\r\ndel temp.wav\r\ncmd ";
1605 //else
1607 auto = aextract + x264 + "\r\n" + mux + " \r\ncmd";
1609 batpath = workPath + "\\auto.bat";
1610 File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
1611 System.Diagnostics.Process.Start(batpath);
1614 private void button6_Click_2(object sender, EventArgs e)
1616 //if (Directory.Exists("avsfilter"))
1618 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1619 // foreach (FileInfo FileName in TheFolder.GetFiles())
1620 // {
1621 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1622 // }
1624 avs += "LoadPlugin(\"avsfilter\\VSFilter.DLL\")\r\n";
1625 avs += string.Format("\r\nDirectShowSource(\"{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);
1626 //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";
1627 AVSScriptTextBox.Text = avs;
1628 avs = "";
1630 private void txth264_TextChanged(object sender, EventArgs e)
1633 private void txtvideo_MouseDoubleClick(object sender, MouseEventArgs e)
1635 if (File.Exists(txtvideo.Text.ToString()))
1637 System.Diagnostics.Process.Start(txtvideo.Text.ToString());
1640 private void txtvideo4_MouseDoubleClick(object sender, MouseEventArgs e)
1642 if (File.Exists(txtvideo4.Text.ToString()))
1644 System.Diagnostics.Process.Start(txtvideo4.Text.ToString());
1647 private void txtout5_MouseDoubleClick(object sender, MouseEventArgs e)
1649 if (File.Exists(txtout5.Text.ToString()))
1651 System.Diagnostics.Process.Start(txtout5.Text.ToString());
1654 private void txtvideo8_MouseDoubleClick(object sender, MouseEventArgs e)
1656 if (File.Exists(txtvideo8.Text.ToString()))
1658 System.Diagnostics.Process.Start(txtvideo8.Text.ToString());
1661 private void txtvideo9_MouseDoubleClick(object sender, MouseEventArgs e)
1663 if (File.Exists(txtvideo9.Text.ToString()))
1665 System.Diagnostics.Process.Start(txtvideo9.Text.ToString());
1668 private void txtvideo6_MouseDoubleClick(object sender, MouseEventArgs e)
1670 if (File.Exists(txtvideo6.Text.ToString()))
1672 System.Diagnostics.Process.Start(txtvideo6.Text.ToString());
1675 private void txtvideo5_MouseDoubleClick(object sender, MouseEventArgs e)
1677 if (File.Exists(txtvideo5.Text.ToString()))
1679 System.Diagnostics.Process.Start(txtvideo5.Text.ToString());
1682 private void txtaudio3_MouseDoubleClick(object sender, MouseEventArgs e)
1684 if (File.Exists(txtaudio3.Text.ToString()))
1686 System.Diagnostics.Process.Start(txtaudio3.Text.ToString());
1689 private void timer1_Tick(object sender, EventArgs e)
1691 Process[] processes = Process.GetProcesses();
1692 for (int i = 0; i < processes.GetLength(0); i++)
1694 //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
1695 if (processes[i].ProcessName.Equals(Path.GetFileNameWithoutExtension(x264ExeComboBox.Text)))
1697 switch (x264PriorityComboBox.SelectedIndex)
1699 case 0: processes[i].PriorityClass = ProcessPriorityClass.Idle; break;
1700 case 1: processes[i].PriorityClass = ProcessPriorityClass.BelowNormal; break;
1701 case 2: processes[i].PriorityClass = ProcessPriorityClass.Normal; break;
1702 case 3: processes[i].PriorityClass = ProcessPriorityClass.AboveNormal; break;
1703 case 4: processes[i].PriorityClass = ProcessPriorityClass.High; break;
1704 case 5: processes[i].PriorityClass = ProcessPriorityClass.RealTime; break;
1709 private void btnsub9_Click(object sender, EventArgs e)
1711 openFileDialog1.Filter = "ASS字幕(*.ass;*.ssa)|*.ass;*.ssa|所有文件(*.*)|*.*";
1712 DialogResult result = openFileDialog1.ShowDialog();
1713 if (result == DialogResult.OK)
1715 namesub9 = openFileDialog1.FileName;
1716 txtsub9.Text = namesub9;
1719 private void btnvideo9_Click(object sender, EventArgs e)
1721 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
1722 DialogResult result = openFileDialog1.ShowDialog();
1723 if (result == DialogResult.OK)
1725 namevideo9 = openFileDialog1.FileName;
1726 txtvideo9.Text = namevideo9;
1729 private void button9_Click(object sender, EventArgs e)
1731 AVSScriptTextBox.Clear();
1733 private void btnClip_Click(object sender, EventArgs e)
1735 if (namevideo4 == "")
1737 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1739 else if (nameout5 == "")
1741 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1743 else
1745 int h1 = int.Parse(maskb.Text.ToString().Substring(0, 2));
1746 int m1 = int.Parse(maskb.Text.ToString().Substring(3, 2));
1747 int s1 = int.Parse(maskb.Text.ToString().Substring(6, 2));
1748 int h2 = int.Parse(maske.Text.ToString().Substring(0, 2));
1749 int m2 = int.Parse(maske.Text.ToString().Substring(3, 2));
1750 int s2 = int.Parse(maske.Text.ToString().Substring(6, 2));
1751 clip = "\"" + workPath + "\\ffmpeg.exe\" -ss " + maskb.Text.ToString() + " -t " + timeminus(h1, m1, s1, h2, m2, s2) + " -i \"" + namevideo4 + "\" -c copy \"" + nameout5 + "\" \r\ncmd";
1752 batpath = workPath + "\\clip.bat";
1753 File.WriteAllText(batpath, clip, UnicodeEncoding.Default);
1754 Process.Start(batpath);
1757 private void cbX264_SelectedIndexChanged(object sender, EventArgs e)
1759 StreamReader sr = new StreamReader(workPath + "\\preset\\" + cbX264.Text + ".txt", System.Text.Encoding.Default);
1760 x264CustomParameterTextBox.Text = sr.ReadToEnd();
1761 sr.Close();
1763 private void cbFPS_SelectedIndexChanged(object sender, EventArgs e)
1766 private void btnMIopen_Click(object sender, EventArgs e)
1768 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
1769 DialogResult result = openFileDialog1.ShowDialog();
1770 if (result == DialogResult.OK)
1772 MIvideo = openFileDialog1.FileName;
1773 MediaInfoTextBox.Text = MediaInfo(MIvideo);
1776 private void btnMIplay_Click(object sender, EventArgs e)
1778 Process.Start(MIvideo);
1780 private void btnMIcopy_Click(object sender, EventArgs e)
1782 Clipboard.SetText(MItext);
1784 private void btnvideo7_Click(object sender, EventArgs e)
1786 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
1787 DialogResult result = openFileDialog1.ShowDialog();
1788 if (result == DialogResult.OK)
1790 namevideo6 = openFileDialog1.FileName;
1791 txtvideo6.Text = namevideo6;
1794 private void btnextract7_Click(object sender, EventArgs e)
1796 if (namevideo6 == "")
1798 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1800 else
1802 int i = namevideo6.IndexOf(".");
1803 string mkvname = namevideo6.Remove(i);
1804 QQButton btn = (QQButton)sender;
1805 switch (btn.Name)
1807 case "MkvExtract1Button":
1808 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 1:\"" + mkvname + "_audio.aac\"";
1809 break;
1810 case "MkvExtract2Button":
1811 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 2:\"" + mkvname + "_track2\"";
1812 break;
1813 case "MkvExtract3Button":
1814 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 3:\"" + mkvname + "_track3\"";
1815 break;
1816 case "MkvExtract4Button":
1817 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 4:\"" + mkvname + "_track4\"";
1818 break;
1819 case "btnextract7":
1820 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 0:\"" + mkvname + "_video.h264\"";
1821 break;
1823 batpath = workPath + "\\mkvextract.bat";
1824 File.WriteAllText(batpath, mkvextract, UnicodeEncoding.Default);
1825 LogRecord(mkvextract);
1826 System.Diagnostics.Process.Start(batpath);
1829 private void txtMI_TextChanged(object sender, EventArgs e)
1831 MItext = MediaInfoTextBox.Text;
1833 private void txtAVScreate_Click(object sender, EventArgs e)
1836 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
1838 System.Diagnostics.Process.Start("http://www.nmm-hd.org/newbbs/viewtopic.php?f=8&t=219");
1840 private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
1842 System.Diagnostics.Process.Start("http://www.sosg.net/read.php?tid=480646");
1844 private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
1846 System.Diagnostics.Process.Start("http://pan.baidu.com/share/link?shareid=4513&uk=4094576855");
1848 private void btnaextract2_Click(object sender, EventArgs e)
1850 if (namevideo == "")
1852 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1854 else
1856 aextract = "\"" + workPath + "\\mp4box.exe\" -raw 3 \"" + namevideo + "\"";
1857 batpath = workPath + "\\aextract.bat";
1858 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
1859 LogRecord(aextract);
1860 System.Diagnostics.Process.Start(batpath);
1863 private void btnaextract3_Click(object sender, EventArgs e)
1865 if (namevideo == "")
1867 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1869 else
1871 aextract = "\"" + workPath + "\\mp4box.exe\" -raw 4 \"" + namevideo + "\"";
1872 batpath = workPath + "\\aextract.bat";
1873 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
1874 LogRecord(aextract);
1875 System.Diagnostics.Process.Start(batpath);
1878 private void txtvideo6_TextChanged_1(object sender, EventArgs e)
1880 if (File.Exists(txtvideo6.Text.ToString()))
1882 namevideo6 = txtvideo6.Text;
1885 #region 帮助页面
1886 private void AboutBtn_Click(object sender, EventArgs e)
1888 DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
1889 QQMessageBox.Show(
1890 this,
1891 "小丸工具箱 2014版\r\n主页:http://maruko.appinn.me/ \r\n编译日期:" + CompileDate.ToString(),
1892 "关于",
1893 QQMessageBoxIcon.Information,
1894 QQMessageBoxButtons.OK);
1896 private void HomePageBtn_Click(object sender, EventArgs e)
1898 System.Diagnostics.Process.Start("http://maruko.appinn.me/");
1900 #endregion
1901 #region 视频页面
1902 private void x264OneBatchButton_Click(object sender, EventArgs e)
1904 if (lbAuto.Items.Count != 0)
1906 batchAuto();
1907 batpath = workPath + "\\auto.bat";
1908 LogRecord(auto);
1909 WorkingForm wf = new WorkingForm(auto);
1910 wf.Owner = this;
1911 wf.Show();
1913 //File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
1914 //System.Diagnostics.Process.Start(batpath);
1916 else MessageBox.Show("请输入视频!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1918 private void x264VideoBtn_Click(object sender, EventArgs e)
1921 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv;*.avi;*.wmv;*.mpg;*.avs)|*.mp4;*.flv;*.mkv;*.avi;*.wmv;*.mpg;*.avs|所有文件(*.*)|*.*";
1922 DialogResult result = openFileDialog1.ShowDialog();
1923 if (result == DialogResult.OK)
1925 namevideo2 = openFileDialog1.FileName;
1926 x264VideoTextBox.Text = namevideo2;
1929 private void x264OutBtn_Click(object sender, EventArgs e)
1931 SaveFileDialog savefile = new SaveFileDialog();
1932 savefile.Filter = "视频(*.mp4)|*.mp4";
1933 DialogResult result = savefile.ShowDialog();
1934 if (result == DialogResult.OK)
1936 nameout2 = savefile.FileName;
1937 x264OutTextBox.Text = nameout2;
1940 private void x264SubBtn_Click(object sender, EventArgs e)
1942 openFileDialog1.Filter = "ASS字幕(*.ass;*.ssa)|*.ass;*.ssa|所有文件(*.*)|*.*";
1943 DialogResult result = openFileDialog1.ShowDialog();
1944 if (result == DialogResult.OK)
1946 namesub2 = openFileDialog1.FileName;
1947 x264SubTextBox.Text = namesub2;
1950 private void x264StartBtn_Click(object sender, EventArgs e)
1952 if (namevideo2 == "")
1954 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1956 else if (nameout2 == "")
1958 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1960 else
1962 //如果是AVS复制到C盘根目录
1963 if (Path.GetExtension(x264VideoTextBox.Text) == ".avs")
1965 //if (File.Exists(tempavspath)) File.Delete(tempavspath);
1966 File.Copy(x264VideoTextBox.Text, tempavspath, true);
1967 namevideo2 = tempavspath;
1969 x264 = x264bat(namevideo2, nameout2).Replace("\r\n", "");
1970 if (x264SubTextBox.Text != "")
1972 if (x264.IndexOf("--vf") == -1)
1974 x264 += " --vf subtitles --sub \"" + namesub2 + "\"";
1976 else
1978 Regex r = new Regex("--vf\\s\\S*");
1979 Match m = r.Match(x264);
1980 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles");
1981 x264 += " --sub \"" + namesub2 + "\"";
1984 switch (x264AudioModeComboBox.SelectedIndex)
1986 case 1: x264 += " --acodec none"; break;
1987 case 2: x264 += " --acodec copy"; break;
1988 case 3: x264 += " --audiofile \"" + x264AudioParameterTextBox.Text + "\""; break;
1989 case 4: x264 += " --acodec qtaac " + x264AudioParameterTextBox.Text; break;
1990 case 5: x264 += " --acodec faac " + x264AudioParameterTextBox.Text; break;
1991 //case 6: x264 += " --acodec libaacplus " + x264AudioParameterTextBox.Text; break;
1992 case 0: break;
1993 default: ; break;
1995 if (cbFPS2.Text != "auto")
1997 switch (cbFPS2.Text)
1999 case "23.976": x264 += " --fps 24000/1001"; break;
2000 case "24": x264 += " --fps 24"; break;
2001 case "25": x264 += " --fps 25"; break;
2002 case "29.970": x264 += " --fps 30000/1001"; break;
2003 case "30": x264 += " --fps 30"; break;
2004 case "50": x264 += " --fps 50"; break;
2005 case "59.940": x264 += " --fps 60000/1001"; break;
2006 case "60": x264 += " --fps 60"; break;
2007 default: x264 += " --fps " + cbFPS2.Text; break;
2010 if (x264SeekNumericUpDown.Value != 0)
2012 x264 += " --seek " + x264SeekNumericUpDown.Value.ToString();
2014 if (x264FramesNumericUpDown.Value != 0)
2016 x264 += " --frames " + x264FramesNumericUpDown.Value.ToString();
2018 x264 += "\r\n";
2019 if (x264FLVCheckBox.Checked == true)
2021 string flvfile = AddExt(nameout2, "_FLV.flv");
2022 x264 += "\r\n\"" + workPath + "\\ffmpeg.exe\" -i \"" + nameout2 + "\" -c copy -f flv \"" + flvfile + "\" \r\n";
2025 //if (x264ShutdownCheckBox.Checked)
2027 // x264 += "\r\n" + syspath + ":\\Windows\\System32\\shutdown -f -s -t 60";
2030 LogRecord(x264);
2031 WorkingForm wf = new WorkingForm(x264);
2032 wf.Owner = this;
2033 wf.Show();
2035 //x264 += "\r\ncmd";
2036 //batpath = workpath + "\\x264.bat";
2037 //File.WriteAllText(batpath, x264, UnicodeEncoding.Default);
2038 //System.Diagnostics.Process.Start(batpath);
2041 private void x264AddPresetBtn_Click(object sender, EventArgs e)
2043 //create directory
2044 string preset = workPath + "\\preset";
2045 if (!Directory.Exists(preset)) Directory.CreateDirectory(preset);
2046 //add file
2047 aextract = "\"" + workPath + "\\FLVExtractCL.exe\" -a \"" + namevideo8 + "\"";
2048 batpath = workPath + "\\preset\\" + PresetNameTextBox.Text + ".txt";
2049 File.WriteAllText(batpath, x264CustomParameterTextBox.Text, UnicodeEncoding.Default);
2050 //refresh combobox
2051 cbX264.Items.Clear();
2052 if (Directory.Exists(workPath + "\\preset"))
2054 DirectoryInfo TheFolder = new DirectoryInfo("preset");
2055 foreach (FileInfo FileName in TheFolder.GetFiles())
2057 cbX264.Items.Add(FileName.Name.Replace(".txt", ""));
2060 if (cbX264.Items.Count > 0) cbX264.SelectedIndex = 0;
2062 private void x264DeletePresetBtn_Click(object sender, EventArgs e)
2064 if (MessageBox.Show("确定要删除这条预设参数?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
2066 string name = batpath = workPath + "\\preset\\" + cbX264.Text + ".txt";
2067 File.Delete(name);
2068 cbX264.Items.Clear();
2069 if (Directory.Exists(workPath + "\\preset"))
2071 DirectoryInfo TheFolder = new DirectoryInfo("preset");
2072 foreach (FileInfo FileName in TheFolder.GetFiles())
2074 cbX264.Items.Add(FileName.Name.Replace(".txt", ""));
2077 if (cbX264.Items.Count > 0) cbX264.SelectedIndex = 0;
2080 private void x264Mode2RadioButton_CheckedChanged(object sender, EventArgs e)
2082 mode = 2;
2083 lbrate.Visible = true;
2084 x264BitrateNum.Visible = true;
2085 label12.Visible = true;
2086 cbFPS2.Visible = true;
2087 lbFPS2.Visible = true;
2088 lbwidth.Visible = true;
2089 lbheight.Visible = true;
2090 x264WidthNum.Visible = true;
2091 x264HeightNum.Visible = true;
2092 MaintainResolutionCheckBox.Visible = true;
2093 lbcrf.Visible = false;
2094 x264CRFNum.Visible = false;
2095 label4.Visible = false;
2096 x264CustomParameterTextBox.Visible = false;
2097 cbX264.Visible = false;
2098 x264AddPresetBtn.Visible = false;
2099 x264DeletePresetBtn.Visible = false;
2100 PresetNameTextBox.Visible = false;
2102 private void x264Mode3RadioButton_CheckedChanged(object sender, EventArgs e)
2104 mode = 0;
2105 label4.Visible = true;
2106 x264CustomParameterTextBox.Visible = true;
2107 cbX264.Visible = true;
2108 x264AddPresetBtn.Visible = true;
2109 x264DeletePresetBtn.Visible = true;
2110 PresetNameTextBox.Visible = true;
2111 lbwidth.Visible = false;
2112 lbheight.Visible = false;
2113 x264WidthNum.Visible = false;
2114 x264HeightNum.Visible = false;
2115 MaintainResolutionCheckBox.Visible = false;
2116 lbrate.Visible = false;
2117 x264BitrateNum.Visible = false;
2118 label12.Visible = false;
2119 lbcrf.Visible = false;
2120 x264CRFNum.Visible = false;
2121 cbFPS2.Visible = false;
2122 lbFPS2.Visible = false;
2124 private void x264Mode1RadioButton_CheckedChanged(object sender, EventArgs e)
2126 mode = 1;
2127 lbcrf.Visible = true;
2128 x264CRFNum.Visible = true;
2129 cbFPS2.Visible = true;
2130 lbFPS2.Visible = true;
2131 lbwidth.Visible = true;
2132 lbheight.Visible = true;
2133 x264WidthNum.Visible = true;
2134 x264HeightNum.Visible = true;
2135 MaintainResolutionCheckBox.Visible = true;
2136 lbrate.Visible = false;
2137 x264BitrateNum.Visible = false;
2138 label12.Visible = false;
2139 label4.Visible = false;
2140 x264CustomParameterTextBox.Visible = false;
2141 cbX264.Visible = false;
2142 x264AddPresetBtn.Visible = false;
2143 x264DeletePresetBtn.Visible = false;
2144 PresetNameTextBox.Visible = false;
2146 private void x264AudioModeComboBox_SelectedIndexChanged(object sender, EventArgs e)
2148 if (x264AudioModeComboBox.SelectedIndex != -1)
2150 switch (x264AudioModeComboBox.SelectedIndex)
2152 case 1:
2153 x264AudioParameterTextBox.Text = "";
2154 break;
2155 case 2:
2156 x264AudioParameterTextBox.Text = "";
2157 x264AudioParameterTextBox.EmptyTextTip = "可能失败,如出错请用FAAC";
2158 break;
2159 case 3:
2160 x264AudioParameterTextBox.Text = "";
2161 x264AudioParameterTextBox.EmptyTextTip = "把音频文件拖到这里";
2162 break;
2163 case 4:
2164 x264AudioParameterTextBox.Text = "--abitrate 128";
2165 break;
2166 case 5:
2167 x264AudioParameterTextBox.Text = "--abitrate 128";
2168 break;
2169 case 6:
2170 x264AudioParameterTextBox.Text = "";
2171 break;
2172 case 0:
2173 x264AudioParameterTextBox.Text = "";
2174 break;
2175 default:
2176 break;
2180 private void x264PriorityComboBox_SelectedIndexChanged(object sender, EventArgs e)
2182 string processName = x264ExeComboBox.Text;
2183 processName = processName.Replace(".exe", "");
2184 Process[] processes = Process.GetProcesses();
2185 //if (x264PriorityComboBox.SelectedIndex == 4 || x264PriorityComboBox.SelectedIndex == 5)
2187 // if (MessageBox.Show("优先级那么高的话会严重影响其他进程的运行速度,\r\n是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
2188 // {
2189 // x264PriorityComboBox.SelectedIndex = 2;
2190 // }
2192 //遍历电脑中的进程
2193 for (int i = 0; i < processes.GetLength(0); i++)
2195 //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
2196 if (processes[i].ProcessName.Equals(processName))
2198 switch (x264PriorityComboBox.SelectedIndex)
2200 case 0: processes[i].PriorityClass = ProcessPriorityClass.Idle; break;
2201 case 1: processes[i].PriorityClass = ProcessPriorityClass.BelowNormal; break;
2202 case 2: processes[i].PriorityClass = ProcessPriorityClass.Normal; break;
2203 case 3: processes[i].PriorityClass = ProcessPriorityClass.AboveNormal; break;
2204 case 4: processes[i].PriorityClass = ProcessPriorityClass.High; break;
2205 case 5: processes[i].PriorityClass = ProcessPriorityClass.RealTime; break;
2210 private void x264VideoTextBox_TextChanged(object sender, EventArgs e)
2212 string path = x264VideoTextBox.Text;
2213 if (File.Exists(path))
2215 namevideo2 = path;
2216 x264OutTextBox.Text = AddExt(path, "_x264.mp4");
2217 //txtsub2.Text = AddExt(path, ".ass");
2220 private void x264OutTextBox_TextChanged(object sender, EventArgs e)
2222 nameout2 = x264OutTextBox.Text;
2224 private void x264SubTextBox_TextChanged(object sender, EventArgs e)
2226 namesub2 = x264SubTextBox.Text;
2228 private void x264BatchClearBtn_Click(object sender, EventArgs e)
2230 lbAuto.Items.Clear();
2232 private void x264BatchDeleteBtn_Click(object sender, EventArgs e)
2234 if (lbAuto.Items.Count > 0)
2236 if (lbAuto.SelectedItems.Count > 0)
2238 int index = lbAuto.SelectedIndex;
2239 lbAuto.Items.RemoveAt(lbAuto.SelectedIndex);
2240 if (index == lbAuto.Items.Count)
2242 lbAuto.SelectedIndex = index - 1;
2244 if (index >= 0 && index < lbAuto.Items.Count && lbAuto.Items.Count > 0)
2246 lbAuto.SelectedIndex = index;
2251 private void x264BatchAddBtn_Click(object sender, EventArgs e)
2253 openFileDialog1.Multiselect = true;
2254 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2255 DialogResult result = openFileDialog1.ShowDialog();
2256 if (result == DialogResult.OK)
2258 lbAuto.Items.AddRange(openFileDialog1.FileNames);
2261 #endregion
2262 #region 音频界面
2263 private void AudioEncoderComboBox_SelectedIndexChanged(object sender, EventArgs e)
2265 if (AudioEncoderComboBox.SelectedIndex == 2)
2267 if (File.Exists(txtaudio2.Text))
2268 txtout3.Text = AddExt(txtaudio2.Text, "_WAV.wav");
2269 AudioBitrateComboBox.Enabled = false;
2270 AudioBitrateRadioButton.Enabled = false;
2271 AudioCustomizeRadioButton.Enabled = false;
2273 else
2275 if (File.Exists(txtaudio2.Text))
2276 txtout3.Text = AddExt(txtaudio2.Text, "_AAC.aac");
2277 AudioBitrateComboBox.Enabled = true;
2278 AudioBitrateRadioButton.Enabled = true;
2279 AudioCustomizeRadioButton.Enabled = true;
2282 private void AudioListBox_DragDrop(object sender, DragEventArgs e)
2284 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
2286 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
2287 foreach (String s in files)
2289 (sender as ListBox).Items.Add(s);
2292 ListBox listbox = (ListBox)sender;
2293 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
2294 if (indexoftarget != ListBox.NoMatches)
2296 string temp = listbox.Items[indexoftarget].ToString();
2297 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
2298 listbox.Items[indexofsource] = temp;
2299 listbox.SelectedIndex = indexoftarget;
2302 private void AudioListBox_DragOver(object sender, DragEventArgs e)
2304 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lbAuto))
2306 e.Effect = DragDropEffects.Move;
2308 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
2310 e.Effect = DragDropEffects.Link;
2312 else e.Effect = DragDropEffects.None;
2314 private void AudioListBox_MouseDown(object sender, MouseEventArgs e)
2316 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
2317 if (indexofsource != ListBox.NoMatches)
2319 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
2322 private void AudioBatchButton_Click(object sender, EventArgs e)
2324 if (AudioListBox.Items.Count != 0)
2326 string finish;
2327 aac = "";
2328 for (int i = 0; i < this.AudioListBox.Items.Count; i++)
2330 if (AudioEncoderComboBox.SelectedIndex == 2)
2331 finish = AddExt(AudioListBox.Items[i].ToString(), "_WAV.wav");
2332 else
2333 finish = AddExt(AudioListBox.Items[i].ToString(), "_AAC.aac");
2334 aac += audiobat(AudioListBox.Items[i].ToString(), finish);
2335 aac += "\r\n";
2337 aac += "\r\ncmd";
2338 batpath = workPath + "\\aac.bat";
2339 File.WriteAllText(batpath, aac, UnicodeEncoding.Default);
2340 LogRecord(aac);
2341 System.Diagnostics.Process.Start(batpath);
2343 else MessageBox.Show("请输入文件!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2345 private void btnaudio2_Click(object sender, EventArgs e)
2347 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2348 DialogResult result = openFileDialog1.ShowDialog();
2349 if (result == DialogResult.OK)
2351 nameaudio2 = openFileDialog1.FileName;
2352 txtaudio2.Text = nameaudio2;
2355 private void btnout3_Click(object sender, EventArgs e)
2357 SaveFileDialog savefile = new SaveFileDialog();
2358 savefile.Filter = "音频(*.aac)|*.aac";
2359 DialogResult result = savefile.ShowDialog();
2360 if (result == DialogResult.OK)
2362 nameout3 = savefile.FileName;
2363 txtout3.Text = nameout3;
2366 private void btnaac_Click(object sender, EventArgs e)
2368 if (nameaudio2 == "")
2370 MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2372 else if (nameout3 == "")
2374 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2376 else
2378 //ffmpeg = "\"" + workpath + "\\ffmpeg.exe\" -y -i \"" + nameaudio2 + "\" -f wav temp.wav";
2379 //int AACbr = 1024 * Convert.ToInt32(numq.Value.ToString());
2380 //string br = AACbr.ToString();
2381 //neroaac = "\"" + workpath + "\\neroAacEnc.exe\" -ignorelength -lc -br " + br + " -if \"temp.wav\" -of \"" + nameout3 + "\"";
2382 //aac = ffmpeg + "&&" + neroaac + "\r\ncmd";
2383 batpath = workPath + "\\aac.bat";
2384 File.WriteAllText(batpath, audiobat(nameaudio2, nameout3), UnicodeEncoding.Default);
2385 LogRecord(audiobat(nameaudio2, nameout3));
2386 System.Diagnostics.Process.Start(batpath);
2389 private void txtaudio2_TextChanged(object sender, EventArgs e)
2391 if (File.Exists(txtaudio2.Text.ToString()))
2393 nameaudio2 = txtaudio2.Text;
2394 if (AudioEncoderComboBox.SelectedIndex == 2)
2395 txtout3.Text = AddExt(txtaudio2.Text, "_WAV.wav");
2396 else
2397 txtout3.Text = AddExt(txtaudio2.Text, "_AAC.aac");
2400 private void txtout3_TextChanged(object sender, EventArgs e)
2402 nameout3 = txtout3.Text;
2404 private void txtaudio2_MouseDoubleClick(object sender, MouseEventArgs e)
2406 if (File.Exists(txtaudio2.Text.ToString()))
2408 System.Diagnostics.Process.Start(txtaudio2.Text.ToString());
2411 private void radioButton5_CheckedChanged(object sender, EventArgs e)
2413 lbaacrate.Visible = false;
2414 lbaackbps.Visible = false;
2415 AudioBitrateComboBox.Visible = false;
2416 AudioCustomParameterTextBox.Visible = true;
2418 private void radioButton4_CheckedChanged(object sender, EventArgs e)
2420 lbaacrate.Visible = true;
2421 lbaackbps.Visible = true;
2422 AudioBitrateComboBox.Visible = true;
2423 AudioCustomParameterTextBox.Visible = false;
2425 private void AudioAddButton_Click(object sender, EventArgs e)
2427 openFileDialog1.Multiselect = true;
2428 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2429 DialogResult result = openFileDialog1.ShowDialog();
2430 if (result == DialogResult.OK)
2432 AudioListBox.Items.AddRange(openFileDialog1.FileNames);
2435 private void AudioDeleteButton_Click(object sender, EventArgs e)
2437 if (AudioListBox.Items.Count > 0)
2439 if (AudioListBox.SelectedItems.Count > 0)
2441 int index = AudioListBox.SelectedIndex;
2442 AudioListBox.Items.RemoveAt(AudioListBox.SelectedIndex);
2443 if (index == AudioListBox.Items.Count)
2445 AudioListBox.SelectedIndex = index - 1;
2447 if (index >= 0 && index < AudioListBox.Items.Count && AudioListBox.Items.Count > 0)
2449 AudioListBox.SelectedIndex = index;
2454 private void AudioClearButton_Click(object sender, EventArgs e)
2456 AudioListBox.Items.Clear();
2458 #endregion
2459 #region AVS页面
2460 private void GenerateAVS()
2462 //if (Directory.Exists("avsfilter"))
2464 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
2465 // foreach (FileInfo FileName in TheFolder.GetFiles())
2466 // {
2467 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
2468 // }
2470 avsBuilder.Remove(0, avsBuilder.Length);
2471 avsBuilder.AppendLine("LoadPlugin(\"avsfilter\\VSFilter.DLL\")");
2472 if (UndotCheckBox.Checked) avsBuilder.AppendLine("LoadPlugin(\"avsfilter\\UnDot.DLL\")");
2473 avsBuilder.AppendLine("DirectShowSource(\"" + namevideo9 + "\")");
2474 avsBuilder.AppendLine("ConvertToYV12()");
2475 if (UndotCheckBox.Checked)
2476 avsBuilder.AppendLine("Undot()");
2477 if (TweakCheckBox.Checked)
2478 avsBuilder.AppendLine("Tweak(" + TweakChromaNumericUpDown.Value.ToString() + ", " + TweakSaturationNumericUpDown.Value.ToString() + ", " + TweakBrightnessNumericUpDown.Value.ToString() + ", " + TweakContrastNumericUpDown.Value.ToString() + ")");
2479 if (LevelsCheckBox.Checked)
2480 avsBuilder.AppendLine("Levels(0," + LevelsNumericUpDown.Value.ToString() + ",255,0,255)");
2481 if (LanczosResizeCheckBox.Checked)
2482 avsBuilder.AppendLine("LanczosResize(" + AVSWidthNumericUpDown.Value.ToString() + "," + AVSHeightNumericUpDown.Value.ToString() + ")");
2483 if (SharpenCheckBox.Checked)
2484 avsBuilder.AppendLine("Sharpen(" + SharpenNumericUpDown.Value.ToString() + ")");
2485 if (CropCheckBox.Checked)
2486 avsBuilder.AppendLine("Crop(" + AVSCropTextBox.Text + ")");
2487 if (AddBordersCheckBox.Checked)
2488 avsBuilder.AppendLine("AddBorders(" + AddBorders1NumericUpDown.Value.ToString() + "," + AddBorders2NumericUpDown.Value.ToString() + "," + AddBorders3NumericUpDown.Value.ToString() + "," + AddBorders4NumericUpDown.Value.ToString() + ")");
2489 if (!string.IsNullOrEmpty(txtsub9.Text))
2491 if (Path.GetExtension(namesub9) == ".idx")
2492 avsBuilder.AppendLine("vobsub(\"" + namesub9 + "\")");
2493 else
2494 avsBuilder.AppendLine("TextSub(\"" + namesub9 + "\")");
2496 if (TrimCheckBox.Checked)
2497 avsBuilder.AppendLine("Trim(" + TrimStartNumericUpDown.Value.ToString() + "," + TrimEndNumericUpDown.Value.ToString() + ")");
2498 AVSScriptTextBox.Text = avsBuilder.ToString();
2500 #region 更改AVS
2501 private void TweakCheckBox_CheckedChanged(object sender, EventArgs e)
2503 GenerateAVS();
2505 private void LanczosResizeCheckBox_CheckedChanged(object sender, EventArgs e)
2507 GenerateAVS();
2509 private void AddBordersCheckBox_CheckedChanged(object sender, EventArgs e)
2511 GenerateAVS();
2513 private void CropCheckBox_CheckedChanged(object sender, EventArgs e)
2515 GenerateAVS();
2517 private void TrimCheckBox_CheckedChanged(object sender, EventArgs e)
2519 GenerateAVS();
2521 private void LevelsCheckBox_CheckedChanged(object sender, EventArgs e)
2523 GenerateAVS();
2525 private void SharpenCheckBox_CheckedChanged(object sender, EventArgs e)
2527 GenerateAVS();
2529 private void UndotCheckBox_CheckedChanged(object sender, EventArgs e)
2531 GenerateAVS();
2533 private void TweakChromaNumericUpDown_ValueChanged(object sender, EventArgs e)
2535 GenerateAVS();
2537 private void TweakSaturationNumericUpDown_ValueChanged(object sender, EventArgs e)
2539 GenerateAVS();
2541 private void TweakBrightnessNumericUpDown_ValueChanged(object sender, EventArgs e)
2543 GenerateAVS();
2545 private void TweakContrastNumericUpDown_ValueChanged(object sender, EventArgs e)
2547 GenerateAVS();
2549 private void AVSWidthNumericUpDown_ValueChanged(object sender, EventArgs e)
2551 GenerateAVS();
2553 private void AVSHeightNumericUpDown_ValueChanged(object sender, EventArgs e)
2555 GenerateAVS();
2557 private void AddBorders1NumericUpDown_ValueChanged(object sender, EventArgs e)
2559 GenerateAVS();
2561 private void AddBorders2NumericUpDown_ValueChanged(object sender, EventArgs e)
2563 GenerateAVS();
2565 private void AddBorders3NumericUpDown_ValueChanged(object sender, EventArgs e)
2567 GenerateAVS();
2569 private void AddBorders4NumericUpDown_ValueChanged(object sender, EventArgs e)
2571 GenerateAVS();
2573 private void AVSCropTextBox_TextChanged(object sender, EventArgs e)
2575 GenerateAVS();
2577 private void TrimStartNumericUpDown_ValueChanged(object sender, EventArgs e)
2579 GenerateAVS();
2581 private void TrimEndNumericUpDown_ValueChanged(object sender, EventArgs e)
2583 GenerateAVS();
2585 private void LevelsNumericUpDown_ValueChanged(object sender, EventArgs e)
2587 GenerateAVS();
2589 private void SharpenNumericUpDown_ValueChanged(object sender, EventArgs e)
2591 GenerateAVS();
2594 #endregion
2595 #endregion
2596 private void ExtractMP4Button_Click(object sender, EventArgs e)
2598 openFileDialog1.Filter = "视频(*.mp4)|*.mp4|所有文件(*.*)|*.*";
2599 DialogResult result = openFileDialog1.ShowDialog();
2600 if (result == DialogResult.OK)
2602 namevideo = openFileDialog1.FileName;
2603 ExtractMP4TextBox.Text = namevideo;
2606 private void txtAVS_TextChanged(object sender, EventArgs e)
2608 Match m = Regex.Match(AVSScriptTextBox.Text, "ource\\(\"[a-zA-Z]:\\\\.+\\.\\w+\"");
2609 if (m.Success)
2611 string str = m.ToString();
2612 str = str.Replace("ource(\"", "");
2613 str = str.Replace("\"", "");
2614 str = AddExt(str, "_AVS.mp4");
2615 txtout9.Text = str;
2618 public void Log(string path)
2620 ProcessStartInfo start = new ProcessStartInfo(path);//设置运行的命令行文件问ping.exe文件,这个文件系统会自己找到
2621 //如果是其它exe文件,则有可能需要指定详细路径,如运行winRar.exe
2622 start.CreateNoWindow = false;//不显示dos命令行窗口
2623 start.RedirectStandardOutput = true;//
2624 start.RedirectStandardInput = true;//
2625 start.UseShellExecute = false;//是否指定操作系统外壳进程启动程序
2626 Process p = Process.Start(start);
2627 StreamReader reader = p.StandardOutput;//截取输出流
2628 string line = reader.ReadLine();//每次读取一行
2629 StringBuilder log = new StringBuilder(2000);
2630 while (!reader.EndOfStream)
2632 log.Append(line + "\r\n");
2633 line = reader.ReadLine();
2635 p.WaitForExit();//等待程序执行完退出进程
2636 File.WriteAllText(startpath + "\\log.txt", log.ToString(), UnicodeEncoding.Default);
2637 p.Close();//关闭进程
2638 reader.Close();//关闭流
2640 public void LogRecord(string log)
2642 File.AppendAllText(startpath + "\\log.txt", "===========" + DateTime.Now.ToString() + "===========\r\n" + log + "\r\n\r\n", UnicodeEncoding.Default);
2644 private void DeleteLogButton_Click(object sender, EventArgs e)
2646 if (File.Exists(startpath + "\\log.txt"))
2648 File.Delete(startpath + "\\log.txt");
2649 MessageBox.Show("已经删除日志文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
2651 else MessageBox.Show("没有找到日志文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2653 private void ViewLogButton_Click(object sender, EventArgs e)
2655 if (File.Exists(startpath + "\\log.txt"))
2657 System.Diagnostics.Process.Start(startpath + "\\log.txt");
2659 else MessageBox.Show("没有找到日志文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2661 private void x264PathButton_Click(object sender, EventArgs e)
2663 FolderBrowserDialog fbd = new FolderBrowserDialog();
2664 fbd.ShowDialog();
2665 x264PathTextBox.Text = fbd.SelectedPath;
2667 private void ExtractMP4TextBox_TextChanged(object sender, EventArgs e)
2669 namevideo = ExtractMP4TextBox.Text;
2671 private void MaintainResolutionCheckBox_CheckedChanged(object sender, EventArgs e)
2673 if (MaintainResolutionCheckBox.Checked)
2675 x264WidthNum.Value = 0;
2676 x264HeightNum.Value = 0;
2677 x264WidthNum.Enabled = false;
2678 x264HeightNum.Enabled = false;
2680 else
2682 x264WidthNum.Enabled = true;
2683 x264HeightNum.Enabled = true;
2686 #region globalization
2687 public static void SetLang(string lang, Form form, Type formType)
2689 System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
2690 if (form != null)
2692 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(formType);
2693 resources.ApplyResources(form, "$this");
2694 AppLang(form, resources);
2697 private static void AppLang(Control control, System.ComponentModel.ComponentResourceManager resources)
2699 foreach (Control c in control.Controls)
2701 resources.ApplyResources(c, c.Name);
2702 AppLang(c, resources);
2705 private void languageComboBox_SelectedIndexChanged(object sender, EventArgs e)
2707 StreamReader sr;
2708 x264Mode1RadioButton.Checked = true;
2709 AudioBitrateRadioButton.Checked = true;
2710 switch (languageComboBox.SelectedIndex)
2712 case 0:
2713 SetLang("zh-CN", this, typeof(MainForm));
2714 x264PriorityComboBox.Items.Clear();
2715 x264PriorityComboBox.Items.AddRange(new string[] { "低", "低于标准", "普通", "高于标准", "高", "实时" });
2716 x264PriorityComboBox.SelectedIndex = 2;
2717 x264VideoTextBox.EmptyTextTip = "可以把文件拖曳到这里";
2718 //x264OutTextBox.EmptyTextTip = "宽度和高度全为0即不改变分辨率";
2719 x264PathTextBox.EmptyTextTip = "字幕文件和视频文件在同一目录下且同名";
2720 //txtvideo3.EmptyTextTip = "音频参数在音频选项卡设定";
2721 ExtractMP4TextBox.EmptyTextTip = "抽取的视频或音频在原视频目录下";
2722 txtvideo8.EmptyTextTip = "抽取的视频或音频在原视频目录下";
2723 txtvideo6.EmptyTextTip = "抽取的视频或音频在原视频目录下";
2724 //load Help Text
2725 if (File.Exists(startpath + "\\help.txt"))
2727 sr = new StreamReader(startpath + "\\help.txt", System.Text.Encoding.UTF8);
2728 HelpTextBox.Text = sr.ReadToEnd();
2729 sr.Close();
2731 break;
2732 case 1:
2733 SetLang("zh-TW", this, typeof(MainForm));
2734 x264PriorityComboBox.Items.Clear();
2735 x264PriorityComboBox.Items.AddRange(new string[] { "低", "在標準以下", "標準", "在標準以上", "高", "即時" });
2736 x264PriorityComboBox.SelectedIndex = 2;
2737 x264VideoTextBox.EmptyTextTip = "可以把文件拖曳到這裡";
2738 //x264OutTextBox.EmptyTextTip = "寬度和高度全為0即不改變解析度";
2739 x264PathTextBox.EmptyTextTip = "字幕和視頻在同一資料夾下且同名";
2740 //txtvideo3.EmptyTextTip = "音頻參數需在音頻選項卡设定";
2741 ExtractMP4TextBox.EmptyTextTip = "新檔案生成在原資料夾";
2742 txtvideo8.EmptyTextTip = "新檔案生成在原資料夾";
2743 txtvideo6.EmptyTextTip = "新檔案生成在原資料夾";
2744 //load Help Text
2745 if (File.Exists(startpath + "\\help_zh_tw.txt"))
2747 sr = new StreamReader(startpath + "\\help_zh_tw.txt", System.Text.Encoding.UTF8);
2748 HelpTextBox.Text = sr.ReadToEnd();
2749 sr.Close();
2751 break;
2752 case 2:
2753 SetLang("en-US", this, typeof(MainForm));
2754 x264PriorityComboBox.Items.Clear();
2755 x264PriorityComboBox.Items.AddRange(new string[] { "Idle", "BelowNormal", "Normal", "AboveNormal", "High", "RealTime" });
2756 x264PriorityComboBox.SelectedIndex = 2;
2757 x264VideoTextBox.EmptyTextTip = "Drag file here";
2758 //x264OutTextBox.EmptyTextTip = "Both the width and height equal zero means using original resolution";
2759 x264PathTextBox.EmptyTextTip = "Subtitle and Video must be of the same name and in the same folder";
2760 //txtvideo3.EmptyTextTip = "It is necessary to set audio parameter in the Audio tab";
2761 ExtractMP4TextBox.EmptyTextTip = "New file will be created in the original folder";
2762 txtvideo8.EmptyTextTip = "New file will be created in the original folder";
2763 txtvideo6.EmptyTextTip = "New file will be created in the original folder";
2764 //load Help Text
2765 if (File.Exists(startpath + "\\help.txt"))
2767 sr = new StreamReader(startpath + "\\help.txt", System.Text.Encoding.UTF8);
2768 HelpTextBox.Text = sr.ReadToEnd();
2769 sr.Close();
2771 break;
2772 case 3:
2773 SetLang("ja-JP", this, typeof(MainForm));
2774 x264PriorityComboBox.Items.Clear();
2775 x264PriorityComboBox.Items.AddRange(new string[] { "低", "通常以下", "通常", "通常以上", "高", "リアルタイム" });
2776 x264PriorityComboBox.SelectedIndex = 2;
2777 x264VideoTextBox.EmptyTextTip = "ビデオファイルをここに引きずってください";
2778 //x264OutTextBox.EmptyTextTip = "Both the width and height equal zero means using original resolution";
2779 x264PathTextBox.EmptyTextTip = "字幕とビデオは同じ名前と同じフォルダにある必要があります";
2780 //txtvideo3.EmptyTextTip = "It is necessary to set audio parameter in the Audio tab";
2781 ExtractMP4TextBox.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
2782 txtvideo8.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
2783 txtvideo6.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
2784 break;
2785 default:
2786 SetLang("zh-CN", this, typeof(MainForm));
2787 break;
2790 #endregion
2791 public static void RunProcess(string exe, string arg)
2793 Thread thread = new Thread(() =>
2795 ProcessStartInfo psi = new ProcessStartInfo(exe, arg);
2796 psi.CreateNoWindow = true;
2797 Process p = new Process();
2798 p.StartInfo = psi;
2799 p.Start();
2800 p.WaitForExit();
2801 MessageBox.Show("ts");
2802 p.Close();
2804 thread.IsBackground = true;
2805 thread.Start();
2807 private void DonateButton_Click(object sender, EventArgs e)
2809 System.Diagnostics.Process.Start("https://me.alipay.com/marukochan");
2811 private void AVSSaveButton_Click(object sender, EventArgs e)
2813 SaveFileDialog savefile = new SaveFileDialog();
2814 savefile.Filter = "AVS(*.avs)|*.avs";
2815 DialogResult result = savefile.ShowDialog();
2816 if (result == DialogResult.OK)
2818 File.WriteAllText(savefile.FileName, AVSScriptTextBox.Text, UnicodeEncoding.Default);
2821 private void MuxReplaceAudioButton_Click(object sender, EventArgs e)
2823 if (namevideo == "")
2825 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2826 return;
2828 if (nameaudio == "")
2830 MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2831 return;
2833 if (nameout == "")
2835 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2836 return;
2838 mux = "";
2839 mux = "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + namevideo + "\" -vcodec copy -an \"" + workPath + "\\video_noaudio.mp4\" \r\n";
2840 mux += "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + workPath + "\\video_noaudio.mp4\" -i \"" + nameaudio + "\" -vcodec copy -acodec copy \"" + nameout + "\" \r\n";
2841 mux += "del \"" + workPath + "\\video_noaudio.mp4\" \r\n";
2842 batpath = workPath + "\\mux.bat";
2843 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
2844 LogRecord(mux);
2845 Process.Start(batpath);
2847 private void cbx264file_SelectedIndexChanged(object sender, EventArgs e)
2849 if (x264ExeComboBox.Text.Contains("all"))
2851 x264AudioModeComboBox.Items.Clear();
2852 x264AudioModeComboBox.Items.Add("默认");
2853 x264AudioModeComboBox.Items.Add("无音频流");
2854 x264AudioModeComboBox.Items.Add("复制音频流");
2855 x264AudioModeComboBox.Items.Add("外置音频流");
2856 x264AudioModeComboBox.SelectedIndex = 1;
2858 else
2860 x264AudioModeComboBox.Items.Clear();
2861 x264AudioModeComboBox.Items.Add("默认");
2862 x264AudioModeComboBox.Items.Add("无音频流");
2863 x264AudioModeComboBox.Items.Add("复制音频流");
2864 x264AudioModeComboBox.Items.Add("外置音频流");
2865 x264AudioModeComboBox.Items.Add("QTAAC");
2866 x264AudioModeComboBox.Items.Add("FAAC");
2867 x264AudioModeComboBox.SelectedIndex = 5;
2871 #region 一图流
2873 private void AudioPicButton_Click(object sender, EventArgs e)
2875 openFileDialog1.Filter = "图片(*.jpg;*.jpeg;*.png;*.bmp;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件(*.*)|*.*";
2876 DialogResult result = openFileDialog1.ShowDialog();
2877 if (result == DialogResult.OK)
2879 AudioPicTextBox.Text = openFileDialog1.FileName;
2882 private void AudioPicAudioButton_Click(object sender, EventArgs e)
2884 openFileDialog1.Filter = "音频(*.aac;*.mp3;*.mp4;*.wav)|*.aac;*.mp3;*.mp4;*.wav|所有文件(*.*)|*.*";
2885 DialogResult result = openFileDialog1.ShowDialog();
2886 if (result == DialogResult.OK)
2888 AudioPicAudioTextBox.Text = openFileDialog1.FileName;
2891 private void AudioOnePicOutputButton_Click(object sender, EventArgs e)
2893 SaveFileDialog savefile = new SaveFileDialog();
2894 savefile.Filter = "MP4视频(*.mp4)|*.mp4|FLV视频(*.flv)|*.flv";
2895 savefile.FileName = "Single";
2896 DialogResult result = savefile.ShowDialog();
2897 if (result == DialogResult.OK)
2899 AudioOnePicOutputTextBox.Text = savefile.FileName;
2902 public int SecondsFromHHMMSS(string hhmmss)
2904 int hh = int.Parse(hhmmss.Substring(0, 2));
2905 int mm = int.Parse(hhmmss.Substring(3, 2));
2906 int ss = int.Parse(hhmmss.Substring(6, 2));
2907 return hh * 3600 + mm * 60 + ss;
2909 private void AudioOnePicButton_Click(object sender, EventArgs e)
2911 if (!File.Exists(AudioPicTextBox.Text))
2913 MessageBox.Show("请选择图片文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2915 else if (!File.Exists(AudioPicAudioTextBox.Text))
2917 MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2919 else if (AudioOnePicOutputTextBox.Text == "")
2921 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2923 else
2925 System.Drawing.Image img = System.Drawing.Image.FromFile(AudioPicTextBox.Text);
2926 int sourceWidth = img.Width;
2927 int sourceHeight = img.Height;
2928 if (img.Width % 2 != 0 || img.Height % 2 != 0)
2930 MessageBox.Show("图片的长和宽必须是偶数。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2931 img.Dispose();
2932 return;
2934 if (img.RawFormat.Equals(ImageFormat.Jpeg))
2936 File.Copy(AudioPicTextBox.Text, tempPic, true);
2938 else
2940 System.Drawing.Imaging.Encoder ImageEncoder = System.Drawing.Imaging.Encoder.Quality;
2941 EncoderParameter ep = new EncoderParameter(ImageEncoder, 100L);
2942 EncoderParameters eps = new EncoderParameters(1);
2943 ImageCodecInfo ImageCoderType = getImageCoderInfo("image/jpeg");
2944 eps.Param[0] = ep;
2945 img.Save(tempPic, ImageCoderType, eps);
2946 //img.Save(tempPic, ImageFormat.Jpeg);
2948 //获得音频时长
2949 MediaInfo MI = new MediaInfo();
2950 MI.Open(AudioPicAudioTextBox.Text);
2951 int seconds = SecondsFromHHMMSS(MI.Get(StreamKind.General, 0, "Duration/String3"));
2952 if (AudioCopyCheckBox.Checked)
2954 mux = "ffmpeg -loop 1 -r " + OnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + tempPic + "\" -vcodec libx264 -crf " + OnePicCRFNum.Value.ToString() + " -y SinglePictureVideo.mp4\r\n";
2955 mux += "ffmpeg -i SinglePictureVideo.mp4 -i \"" + AudioPicAudioTextBox.Text + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
2956 mux += "del SinglePictureVideo.mp4\r\n";
2958 else
2960 mux = "ffmpeg -i \"" + AudioPicAudioTextBox.Text + "\" -f wav - |neroaacenc -br " + OnePicAudioBitrateNum.Value.ToString() + "000 -ignorelength -if - -of audio.mp4 -lc\r\n";
2961 mux += "ffmpeg -loop 1 -crf " + OnePicCRFNum.Value.ToString() + " -r " + OnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + tempPic + "\" -vcodec libx264 -crf " + OnePicCRFNum.Value.ToString() + " -y SinglePictureVideo.mp4\r\n";
2962 mux += "ffmpeg -i SinglePictureVideo.mp4 -i audio.mp4 -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
2963 mux += "del SinglePictureVideo.mp4\r\ndel audio.mp4\r\n";
2966 string audioPath = AddExt(Path.GetFileName(AudioPicAudioTextBox.Text), "_atmp.mp4");
2967 string videoPath = AddExt(Path.GetFileName(AudioPicAudioTextBox.Text), "_vtmp.mp4");
2968 string picturePath = "c:\\" + Path.GetFileNameWithoutExtension(AudioPicTextBox.Text) + "_tmp.jpg";
2969 if (AudioCopyCheckBox.Checked)
2971 mux = "ffmpeg -loop 1 -r " + AudioOnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + picturePath + "\" -vcodec libx264 -crf 24 -y \"" + videoPath + "\"\r\n";
2972 mux += "ffmpeg -i \"" + videoPath + "\" -i \"" + AudioPicAudioTextBox.Text + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
2973 mux += "del \"" + videoPath + "\"\r\ndel \"" + picturePath + "\"\r\n";
2975 else
2977 mux = "ffmpeg -i \"" + AudioPicAudioTextBox.Text + "\" -f wav - |neroaacenc -br " + AudioOnePicAudioBitrateNum.Value.ToString() + "000 -ignorelength -if - -of \"" + audioPath + "\" -lc\r\n";
2978 mux += "ffmpeg -loop 1 -r " + AudioOnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + picturePath + "\" -vcodec libx264 -crf 24 -y \"" + videoPath + "\"\r\n";
2979 mux += "ffmpeg -i \"" + videoPath + "\" -i \"" + audioPath + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
2980 mux += "del \"" + videoPath + "\"\r\ndel \"" + audioPath + "\"\r\ndel \"" + picturePath + "\"\r\n";
2983 batpath = Path.Combine(workPath, Path.GetRandomFileName() + ".bat");
2984 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
2985 LogRecord(mux);
2986 Process.Start(batpath);
2989 private void txtMI_DragDrop(object sender, DragEventArgs e)
2991 MIvideo = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
2992 MediaInfoTextBox.Text = MediaInfo(MIvideo);
2994 private void txtMI_DragEnter(object sender, DragEventArgs e)
2996 if (e.Data.GetDataPresent(DataFormats.FileDrop))
2997 e.Effect = DragDropEffects.Link;
2998 else e.Effect = DragDropEffects.None;
3000 private void AudioPicAudioTextBox_TextChanged(object sender, EventArgs e)
3002 if (File.Exists(AudioPicAudioTextBox.Text.ToString()))
3004 AudioOnePicOutputTextBox.Text = AddExt(AudioPicAudioTextBox.Text, "_SP.flv");
3007 /// <summary>
3008 /// 获取图片编码类型信息
3009 /// </summary>
3010 /// <param name="ImageCoderType">编码类型</param>
3011 /// <returns>ImageCodecInfo</returns>
3012 private ImageCodecInfo getImageCoderInfo(string ImageCoderType)
3014 ImageCodecInfo[] coderTypeArray = ImageCodecInfo.GetImageEncoders();
3015 foreach (ImageCodecInfo coderType in coderTypeArray)
3017 if (coderType.MimeType.Equals(ImageCoderType))
3018 return coderType;
3020 return null;
3023 #endregion
3026 #region 后黑
3028 private void BlackVideoButton_Click(object sender, EventArgs e)
3030 openFileDialog1.Filter = "FLV视频(*.flv)|*.flv";
3031 DialogResult result = openFileDialog1.ShowDialog();
3032 if (result == DialogResult.OK)
3034 BlackVideoTextBox.Text = openFileDialog1.FileName;
3038 private void BlackOutputButton_Click(object sender, EventArgs e)
3040 SaveFileDialog savefile = new SaveFileDialog();
3041 savefile.Filter = "FLV视频(*.flv)|*.flv";
3042 DialogResult result = savefile.ShowDialog();
3043 if (result == DialogResult.OK)
3045 BlackOutputTextBox.Text = savefile.FileName;
3049 private void BlackPicButton_Click(object sender, EventArgs e)
3051 openFileDialog1.Filter = "图片(*.jpg;*.jpeg;*.png;*.bmp;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件(*.*)|*.*";
3052 DialogResult result = openFileDialog1.ShowDialog();
3053 if (result == DialogResult.OK)
3055 BlackPicTextBox.Text = openFileDialog1.FileName;
3059 private void BlackStartButton_Click(object sender, EventArgs e)
3061 string videoname = BlackVideoTextBox.Text;
3062 MediaInfo MI = new MediaInfo();
3063 MI.Open(videoname);
3064 double videobitrate = double.Parse(MI.Get(StreamKind.General, 0, "BitRate"));
3065 double targetBitrate = (double)BlackBitrateNum.Value;
3067 //验证
3068 if (!File.Exists(BlackVideoTextBox.Text) || Path.GetExtension(BlackVideoTextBox.Text) != ".flv")
3070 MessageBox.Show("请选择FLV视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3071 return;
3073 if (!File.Exists(BlackPicTextBox.Text) && BlackNoPicCheckBox.Checked == false)
3075 MessageBox.Show("请选择图片文件或勾选使用黑屏", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3076 return;
3078 if (BlackOutputTextBox.Text == "")
3080 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3081 return;
3084 if (videobitrate < 1000000)
3086 MessageBox.Show("此视频不需要后黑。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
3087 return;
3089 if (videobitrate > 2500000)
3091 MessageBox.Show("此视频码率过大,请先压制再后黑。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
3092 return;
3096 //处理图片
3097 int videoWidth = int.Parse(MI.Get(StreamKind.Video, 0, "Width"));
3098 int videoHeight = int.Parse(MI.Get(StreamKind.Video, 0, "Height"));
3099 if (BlackNoPicCheckBox.Checked)
3101 Bitmap bm = new Bitmap(videoWidth, videoHeight);
3102 Graphics g = Graphics.FromImage(bm);
3103 //g.FillRectangle(Brushes.White, new Rectangle(0, 0, 800, 600));
3104 g.Clear(Color.Black);
3105 bm.Save(tempPic, ImageFormat.Jpeg);
3106 g.Dispose();
3107 bm.Dispose();
3109 else
3111 System.Drawing.Image img = System.Drawing.Image.FromFile(BlackPicTextBox.Text);
3112 int sourceWidth = img.Width;
3113 int sourceHeight = img.Height;
3114 if (img.Width % 2 != 0 || img.Height % 2 != 0)
3116 MessageBox.Show("图片的长和宽必须都是偶数。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3117 img.Dispose();
3118 return;
3120 if (img.Width != videoWidth || img.Height != videoHeight)
3122 MessageBox.Show("图片的长和宽和视频不一致。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3123 img.Dispose();
3124 return;
3126 if (img.RawFormat.Equals(ImageFormat.Jpeg))
3128 File.Copy(BlackPicTextBox.Text, tempPic, true);
3130 else
3132 System.Drawing.Imaging.Encoder ImageEncoder = System.Drawing.Imaging.Encoder.Quality;
3133 EncoderParameter ep = new EncoderParameter(ImageEncoder, 100L);
3134 EncoderParameters eps = new EncoderParameters(1);
3135 ImageCodecInfo ImageCoderType = getImageCoderInfo("image/jpeg");
3136 eps.Param[0] = ep;
3137 img.Save(tempPic, ImageCoderType, eps);
3138 //img.Save(tempPic, ImageFormat.Jpeg);
3141 int blackSecond = 300;
3142 //计算后黑时长
3143 if (BlackSecondComboBox.Text == "auto")
3145 int seconds = SecondsFromHHMMSS(MI.Get(StreamKind.General, 0, "Duration/String3"));
3146 double s = videobitrate / 1000.0 * (double)seconds / targetBitrate - (double)seconds;
3147 blackSecond = (int)s;
3148 BlackSecondComboBox.Text = blackSecond.ToString();
3150 else
3152 blackSecond = int.Parse(Regex.Replace(BlackSecondComboBox.Text.ToString(), @"\D", "")); //排除除数字外的所有字符
3155 //批处理
3156 mux = "\""+ workPath + "\\ffmpeg\" -loop 1 -r " + BlackFPSNum.Value.ToString() + " -t " + blackSecond.ToString() + " -f image2 -i \"" + tempPic + "\" -vcodec libx264 -crf " + BlackCRFNum.Value.ToString() + " -y black.flv\r\n";
3157 mux += string.Format("\"{0}\\flvbind\" \"{1}\" \"{2}\" black.flv\r\n", workPath, BlackOutputTextBox.Text, BlackVideoTextBox.Text);
3158 mux += "del black.flv\r\n";
3160 batpath = Path.Combine(workPath, Path.GetRandomFileName() + ".bat");
3161 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
3162 LogRecord(mux);
3163 Process.Start(batpath);
3166 private void BlackVideoTextBox_TextChanged(object sender, EventArgs e)
3168 string path = BlackVideoTextBox.Text;
3169 if (File.Exists(path))
3171 BlackOutputTextBox.Text = AddExt(path, "_black.flv");
3174 #endregion
3176 private void BlackNoPicCheckBox_CheckedChanged(object sender, EventArgs e)
3178 BlackPicTextBox.Enabled = !BlackNoPicCheckBox.Checked;
3179 BlackPicButton.Enabled = !BlackNoPicCheckBox.Checked;
3182 private void BlackSecondComboBox_SelectedIndexChanged(object sender, EventArgs e)
3184 if (BlackSecondComboBox.Text != "auto")
3186 BlackBitrateNum.Enabled = false;
3188 else
3190 BlackBitrateNum.Enabled = true;
3194 private void SetDefaultButton_Click(object sender, EventArgs e)
3196 InitParameter();
3199 //Ctrl+A 可以全选文本
3200 private void MediaInfoTextBox_KeyDown(object sender, KeyEventArgs e)
3202 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
3204 ((TextBox)sender).SelectAll();
3208 private void AVSScriptTextBox_KeyDown(object sender, KeyEventArgs e)
3210 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
3212 ((TextBox)sender).SelectAll();
3216 private void x264CustomParameterTextBox_KeyDown(object sender, KeyEventArgs e)
3218 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
3220 ((TextBox)sender).SelectAll();
3224 private void CheckUpdateButton_Click(object sender, EventArgs e)
3226 WebRequest request = WebRequest.Create("http://hi.baidu.com/xiaowanmaruko/item/119203f757097c603c148502");
3227 request.Credentials = CredentialCache.DefaultCredentials;
3228 // Get the response.
3229 request.BeginGetResponse(new AsyncCallback(OnResponse), request);
3232 protected void OnResponse(IAsyncResult ar)
3234 WebRequest wrq = (WebRequest)ar.AsyncState;
3235 WebResponse wrs = wrq.EndGetResponse(ar);
3236 // read the response ...
3237 Stream dataStream = wrs.GetResponseStream();
3238 // Open the stream using a StreamReader for easy access.
3239 StreamReader reader = new StreamReader(dataStream);
3240 // Read the content.
3241 string responseFromServer = reader.ReadToEnd();
3242 Regex reg = new Regex(@"Maruko20\S+Maruko");
3243 Match m = reg.Match(responseFromServer);
3244 if (m.Success)
3246 string a = m.Value.Replace("Maruko", "");
3247 DateTime NewDate = DateTime.Parse(a);
3248 //DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
3249 int s = DateTime.Compare(NewDate, ReleaseDate);
3250 if (s == 1) //NewDate is later than ReleaseDate
3252 DialogResult dr = MessageBox.Show(string.Format("新鲜小丸已于{0}上架,主人不来尝一口咩?", NewDate.ToString("yyyy-M-d")), "Info", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
3253 if (dr == DialogResult.Yes)
3255 Process.Start("http://maruko.appinn.me");
3257 else
3259 return;
3262 else
3264 MessageBox.Show("喵~伦家已经是最新版啦!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
3269 private void x264ShutdownCheckBox_CheckedChanged(object sender, EventArgs e)
3271 shutdownState = x264ShutdownCheckBox.Checked;
3274 private void TrayModeCheckBox_CheckedChanged(object sender, EventArgs e)
3276 trayMode = TrayModeCheckBox.Checked;
3279 private void ReleaseDatelabel_DoubleClick(object sender, EventArgs e)
3281 SplashForm sf = new SplashForm();
3282 sf.Owner = this;
3283 sf.Show();