Add "Cancel Shutdown" Button in WorkingForm. when use UpdateProgressBar(), devide...
[marukotoolbox.git] / mp4box / MainForm.cs
blob48dbc4d39ec81d981bccb02c547f39f5213305d7
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
23 StringBuilder avsBuilder = new StringBuilder(1000);
24 string syspath = Environment.GetFolderPath(Environment.SpecialFolder.System).Remove(1);
25 int indexofsource;
26 int indexoftarget;
27 byte mode = 1;
28 string clip = "";
29 string MIvideo = "";
30 string namevideo = "";
31 string namevideo2 = "";
32 //string namevideo3 = "";
33 string namevideo4 = "";
34 string namevideo5 = "";
35 string namevideo6 = "";
36 string nameaudio = "";
37 string nameaudio2 = "";
38 string nameaudio3 = "";
39 string namevideo8 = "";
40 string namevideo9 = "video";
41 string nameout;
42 string nameout2;
43 string nameout3;
44 //string nameout4;
45 string nameout5;
46 string nameout6;
47 string nameout9;
48 string namesub;
49 string namesub2 = "";
50 string namesub9 = "subtitle";
51 string MItext = "把视频文件拖到这里";
52 string mkvextract;
53 string mkvmerge;
54 string mux;
55 string x264;
56 string ffmpeg;
57 string neroaac;
58 string aac;
59 string aextract;
60 string vextract;
61 string batpath;
62 string auto;
63 string startpath;
64 string workpath = "!undefined";
65 string avs = "";
66 string tempavspath = "";
67 string tempPic = "";
68 DateTime ReleaseDate = DateTime.Parse("2014-4-14");
70 public bool shutdownState = false;
72 [StructLayout(LayoutKind.Sequential)]
73 public struct MARGINS
75 public int Left;
76 public int Right;
77 public int Top;
78 public int Bottom;
80 [DllImport("dwmapi.dll", PreserveSig = false)]
81 static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
82 [DllImport("dwmapi.dll", PreserveSig = false)]
83 static extern bool DwmIsCompositionEnabled();
84 public MainForm()
86 InitializeComponent();
88 public string MediaInfo(string VideoName)
90 string info = "无视频信息";
91 if (File.Exists(VideoName))
93 MediaInfo MI = new MediaInfo();
94 MI.Open(VideoName);
95 //全局
96 string container = MI.Get(StreamKind.General, 0, "Format");
97 string bitrate = MI.Get(StreamKind.General, 0, "BitRate/String");
98 string duration = MI.Get(StreamKind.General, 0, "Duration/String1");
99 string fileSize = MI.Get(StreamKind.General, 0, "FileSize/String");
100 //视频
101 string vid = MI.Get(StreamKind.Video, 0, "ID");
102 string video = MI.Get(StreamKind.Video, 0, "Format");
103 string vBitRate = MI.Get(StreamKind.Video, 0, "BitRate/String");
104 string vSize = MI.Get(StreamKind.Video, 0, "StreamSize/String");
105 string width = MI.Get(StreamKind.Video, 0, "Width");
106 string height = MI.Get(StreamKind.Video, 0, "Height");
107 string risplayAspectRatio = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio/String");
108 string risplayAspectRatio2 = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio");
109 string frameRate = MI.Get(StreamKind.Video, 0, "FrameRate/String");
110 string bitDepth = MI.Get(StreamKind.Video, 0, "BitDepth/String");
111 string pixelAspectRatio = MI.Get(StreamKind.Video, 0, "PixelAspectRatio");
112 string encodedLibrary = MI.Get(StreamKind.Video, 0, "Encoded_Library");
113 string encodeTime = MI.Get(StreamKind.Video, 0, "Encoded_Date");
114 string codecProfile = MI.Get(StreamKind.Video, 0, "Codec_Profile");
115 string frameCount = MI.Get(StreamKind.Video, 0, "FrameCount");
117 //音频
118 string aid = MI.Get(StreamKind.Audio, 0, "ID");
119 string audio = MI.Get(StreamKind.Audio, 0, "Format");
120 string aBitRate = MI.Get(StreamKind.Audio, 0, "BitRate/String");
121 string samplingRate = MI.Get(StreamKind.Audio, 0, "SamplingRate/String");
122 string channel = MI.Get(StreamKind.Audio, 0, "Channel(s)");
123 string aSize = MI.Get(StreamKind.Audio, 0, "StreamSize/String");
124 info = Path.GetFileName(VideoName) + "\r\n" +
125 "容器:" + container + "\r\n" +
126 "总码率:" + bitrate + "\r\n" +
127 "大小:" + fileSize + "\r\n" +
128 "时长:" + duration + "\r\n" +
129 "\r\n" +
130 "视频(" + vid + "):" + video + "\r\n" +
131 "码率:" + vBitRate + "\r\n" +
132 "大小:" + vSize + "\r\n" +
133 "分辨率:" + width + "x" + height + "\r\n" +
134 "宽高比:" + risplayAspectRatio + "(" + risplayAspectRatio2 + ")" + "\r\n" +
135 "帧率:" + frameRate + "\r\n" +
136 "位深度:" + bitDepth + "\r\n" +
137 "像素宽高比:" + pixelAspectRatio + "\r\n" +
138 "编码库:" + encodedLibrary + "\r\n" +
139 "Profile:" + codecProfile + "\r\n" +
140 "编码时间:" + encodeTime + "\r\n" +
141 "总帧数:" + frameCount + "\r\n" +
143 "\r\n" +
144 "音频(" + aid + "):" + audio + "\r\n" +
145 "大小:" + aSize + "\r\n" +
146 "码率:" + aBitRate + "\r\n" +
147 "采样率:" + samplingRate + "\r\n" +
148 "声道数:" + channel + "\r\n";
149 MI.Close();
151 return info;
153 public string AddExt(string name, string ext)
155 string finish = name.Remove(name.LastIndexOf("."));
156 finish += ext;
157 return finish;
159 public string muxbat(string input1, string input2, string fps, string output)
161 mux = "\"" + workpath + "\\mp4box.exe\" -fps " + fps + " -add " + input1 + " -add " + input2 + " -new \"" + output + "\"";
162 return mux;
164 public string muxbat(string input1, string input2, string output)
166 mux = "\"" + workpath + "\\mp4box.exe\" -add " + input1 + " -add " + input2 + " -new \"" + output + "\"";
167 return mux;
169 public string x264bat(string input, string output)
171 switch (mode)
173 case 1:
174 if (x264HeightNum.Value == 0 || x264WidthNum.Value == 0)
176 x264 = "\"" + workpath + "\\" + x264ExeComboBox.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";
178 else
180 x264 = "\"" + workpath + "\\" + x264ExeComboBox.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";
182 break;
183 case 2:
184 if (x264HeightNum.Value == 0 || x264WidthNum.Value == 0)
186 x264 = "\"" + workpath + "\\" + x264ExeComboBox.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() + "\" -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";
188 else
190 x264 = "\"" + workpath + "\\" + x264ExeComboBox.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() + "\" -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";
192 break;
193 case 0:
194 x264 = "\"" + workpath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" " + x264CustomParameterTextBox.Text + " --demuxer " + x264DemuxerComboBox.Text + " -o \"" + output + "\" \"" + input + "\"\r\n";
195 break;
197 return x264;
199 //public string x264bat(string input, string output)
201 // switch (mode)
202 // {
203 // case 1:
204 // if (numheight.Value == 0 || numwidth.Value == 0)
205 // {
206 // 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";
207 // }
208 // else
209 // {
210 // 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";
211 // }
212 // break;
213 // case 2:
214 // if (numheight.Value == 0 || numwidth.Value == 0)
215 // {
216 // 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";
217 // }
218 // else
219 // {
220 // 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";
221 // }
222 // break;
223 // case 0:
224 // x264 = "\"" + workpath + "\\x264.exe\" " + txth264.Text + " -o \"" + output + "\" \"" + input + "\"\r\n";
225 // break;
226 // }
227 // return x264;
229 public string timeminus(int h1, int m1, int s1, int h2, int m2, int s2)
231 int h = 0;
232 int m = 0;
233 int s = 0;
234 s = s2 - s1;
235 if (s < 0)
237 m = -1;
238 s = s + 60;
240 m = m + m2 - m1;
241 if (m < 0)
243 h = -1;
244 m = m + 60;
246 h = h + h2 - h1;
247 return h.ToString() + ":" + m.ToString() + ":" + s.ToString();
249 public string timeplus(int h1, int m1, int s1, int h2, int m2, int s2)
251 int h = 0;
252 int m = 0;
253 int s = 0;
254 s = s1 + s2;
255 if (s >= 60)
257 m = 1;
258 s = s - 60;
260 m = m + m1 + m2;
261 if (m >= 60)
263 h = 1;
264 m = m - 60;
266 h = h + h1 + h2;
267 return h.ToString() + ":" + m.ToString() + ":" + s.ToString();
269 public string audiobat(string input, string output)
271 int AACbr = 1024 * Convert.ToInt32(AudioBitrateComboBox.Text);
272 string br = AACbr.ToString();
273 ffmpeg = "\"" + workpath + "\\ffmpeg.exe\" -y -i \"" + input + "\" -f wav temp.wav";
274 switch (AudioEncoderComboBox.SelectedIndex)
276 case 0:
277 if (AudioBitrateRadioButton.Checked)
279 neroaac = "\"" + workpath + "\\neroAacEnc.exe\" -ignorelength -lc -br " + br + " -if \"temp.wav\" -of \"" + output + "\"";
281 if (AudioCustomizeRadioButton.Checked)
283 neroaac = "\"" + workpath + "\\neroAacEnc.exe\" " + AudioCustomParameterTextBox.Text.ToString() + " -if \"temp.wav\" -of \"" + output + "\"";
285 break;
286 case 1:
287 if (AudioBitrateRadioButton.Checked)
289 neroaac = "\"" + workpath + "\\qaac.exe\" -q 2 -c " + AudioBitrateComboBox.Text + " \"temp.wav\" -o \"" + output + "\"";
291 if (AudioCustomizeRadioButton.Checked)
293 neroaac = "\"" + workpath + "\\qaac.exe\" " + AudioCustomParameterTextBox.Text.ToString() + " \"temp.wav\" -o \"" + output + "\"";
295 break;
296 case 2:
297 if (Path.GetExtension(output) == ".aac")
298 output = AddExt(output, ".wav");
299 ffmpeg = "\"" + workpath + "\\ffmpeg.exe\" -y -i \"" + input + "\" -f wav \"" + output + "\"";
300 neroaac = "";
302 break;
303 default:
304 break;
306 aac = ffmpeg + "\r\n" + neroaac + "\r\n";
307 if (cbwavtemp.Checked == false)
309 aac += "del temp.wav\r\n";
311 return aac;
313 public void oneAuto(string video, string output)
315 x264 = x264bat(video, "temp.mp4");
316 x264 = x264.Replace("\r\n", "");
317 if (x264SubTextBox.Text != "")
319 if (x264.IndexOf("--vf") == -1)
321 x264 += " --vf subtitles --sub \"" + namesub2 + "\"";
323 else
325 Regex r = new Regex("--vf\\s\\S*");
326 Match m = r.Match(x264);
327 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles");
328 x264 += " --sub \"" + namesub2 + "\"";
331 x264 += " --acodec none\r\n";
332 //audio
333 //如果是avs
334 if (video.Substring(video.LastIndexOf(".") + 1) == "avs")
336 aextract = "\r\n";
337 //string nameavs = namevideo3;
338 //int a, b;
339 //StreamReader sr = new StreamReader(namevideo3, System.Text.Encoding.Default);
340 //string str = sr.ReadToEnd();
341 //a = str.IndexOf("DirectShowSource(\"");
342 //if (a == -1)
344 // a = str.IndexOf("FFVideoSource(\"");
345 // b = str.IndexOf("\"", a + 15);
346 // namevideo3 = str.Substring(a + 15, b - a - 15);
348 //else
350 // b = str.IndexOf("\"", a + 18);
351 // namevideo3 = str.Substring(a + 18, b - a - 18);
353 //if (namevideo3.IndexOf(":") != 1)
355 // namevideo3 = nameavs.Substring(0, nameavs.LastIndexOf("\\") + 1) + namevideo3;
358 else
360 aextract = audiobat(video, "temp.aac");
362 //mux
363 mux = muxbat("temp.mp4", "temp.aac", cbFPS.Text, output);
364 //if (cbDelTmp.Checked == false)
366 // auto = aextract + x264 + mux + " \r\ndel temp.aac\r\ndel temp.mp4\r\ndel temp.wav\r\n";
368 //else
370 auto = aextract + x264 + mux + " \r\n\r\n";
372 if (x264FLVCheckBox.Checked == true)
374 string flvfile = AddExt(output, "_FLV.flv");
375 auto += "\r\n\"" + workpath + "\\ffmpeg.exe\" -i \"" + output + "\" -c copy -f flv \"" + flvfile + "\" \r\n";
377 //if (x264ShutdownCheckBox.Checked)
379 // auto += "\r\n" + syspath + ":\\Windows\\System32\\shutdown -f -s -t 60\r\n";
381 //auto += "cmd";
383 public void batchAuto()
385 int i;
386 auto = "";
387 for (i = 0; i < this.lbAuto.Items.Count; i++)
389 x264 = x264bat(lbAuto.Items[i].ToString(), "temp.mp4");
390 x264 = x264.Replace("\r\n", "");
391 //判断是否内嵌字幕
392 string sub = "";
393 string asssub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".ass";
394 string ssasub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".ssa";
395 string srtsub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".srt";
396 if (x264BatchSubCheckBox.Checked)
398 if (File.Exists(asssub))
400 sub = asssub;
402 else if (File.Exists(ssasub))
404 sub = ssasub;
406 else if (File.Exists(srtsub))
408 sub = srtsub;
410 if (sub != "")
412 if (x264.IndexOf("--vf") == -1)
414 x264 += " --vf subtitles --sub \"" + sub + "\"";
416 else
418 Regex r = new Regex("--vf\\s\\S*");
419 Match m = r.Match(x264);
420 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles");
421 x264 += " --sub \"" + sub + "\"";
425 x264 += " --acodec none\r\n";
426 //audio
427 //如果是avs
428 if (lbAuto.Items[i].ToString().Substring(lbAuto.Items[i].ToString().LastIndexOf(".") + 1) == "avs")
430 aextract = "\r\n";
431 //string tempvideoname;
432 //int a, b;
433 //StreamReader sr = new StreamReader(lbAuto.Items[i].ToString(), System.Text.Encoding.Default);
434 //string str = sr.ReadToEnd();
435 //a = str.IndexOf("DirectShowSource(\"");
436 //if (a == -1)
438 // a = str.IndexOf("FFVideoSource(\"");
439 // b = str.IndexOf("\"", a + 15);
440 // tempvideoname = str.Substring(a + 15, b - a - 15);
442 //else
444 // b = str.IndexOf("\"", a + 18);
445 // tempvideoname = str.Substring(a + 18, b - a - 18);
447 //if (tempvideoname.IndexOf(":") != 1)
449 // tempvideoname = lbAuto.Items[i].ToString().Substring(0, lbAuto.Items[i].ToString().LastIndexOf("\\") + 1) + tempvideoname;
451 //aextract = audiobat(tempvideoname, "temp.aac");
452 //ffmpeg = "\"" + workpath + "\\ffmpeg.exe\" -y -i \"" + tempvideoname + "\" -f wav temp.wav";
454 else //如果不是avs
456 aextract = audiobat(lbAuto.Items[i].ToString(), "temp.aac");
458 //mux
459 string finish;
460 if (Directory.Exists(x264PathTextBox.Text))
461 finish = x264PathTextBox.Text + "\\" + Path.GetFileNameWithoutExtension(lbAuto.Items[i].ToString()) + "_onekeybatch.mp4";
462 else
463 finish = AddExt(lbAuto.Items[i].ToString(), "_onekeybatch.mp4");
464 mux = muxbat("temp.mp4", "temp.aac", finish);
465 //mux = "\"" + workpath + "\\mp4box.exe\" -add temp.mp4 -add temp.aac -new \"" + finish + "\"";
466 auto += aextract + x264 + mux + " \r\ndel temp.aac\r\ndel temp.mp4\r\ndel temp.wav\r\n";
467 //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";
470 //if (x264ShutdownCheckBox.Checked)
472 // auto += "\r\n" + syspath + ":\\Windows\\System32\\shutdown -f -s -t 60";
475 public void batchAuto2()
477 int i;
478 auto = "";
479 for (i = 0; i < this.lbAuto.Items.Count; i++)
481 string sub = "";
482 string asssub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".ass";
483 string ssasub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".ssa";
484 string srtsub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".srt";
485 string finish;
486 if (Directory.Exists(x264PathTextBox.Text))
487 finish = x264PathTextBox.Text + "\\" + Path.GetFileNameWithoutExtension(lbAuto.Items[i].ToString()) + "_batch.mp4";
488 else
489 finish = AddExt(lbAuto.Items[i].ToString(), "_Batch.mp4");
490 x264 = x264bat(lbAuto.Items[i].ToString(), finish).Replace("\r\n", "");
491 //判断是否内嵌字幕
492 if (x264BatchSubCheckBox.Checked)
494 if (File.Exists(asssub))
496 sub = asssub;
498 else if (File.Exists(ssasub))
500 sub = ssasub;
502 else if (File.Exists(srtsub))
504 sub = srtsub;
506 if (sub != "")
508 if (x264.IndexOf("--vf") == -1)
510 x264 += " --vf subtitles --sub \"" + sub + "\"";
512 else
514 Regex r = new Regex("--vf\\s\\S*");
515 Match m = r.Match(x264);
516 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles");
517 x264 += " --sub \"" + sub + "\"";
521 switch (x264AudioModeComboBox.SelectedIndex)
523 case 1: x264 += " --acodec none"; break;
524 case 2: x264 += " --acodec copy"; break;
525 case 3: x264 += " --audiofile \"" + x264AudioParameterTextBox.Text + "\""; break;
526 case 4: x264 += " --acodec qtaac " + x264AudioParameterTextBox.Text; break;
527 case 5: x264 += " --acodec faac " + x264AudioParameterTextBox.Text; break;
528 //case 6: x264 += " --acodec libaacplus " + x264AudioParameterTextBox.Text; break;
529 case 0: break;
530 default: ; break;
532 if (cbFPS2.Text != "auto")
534 switch (cbFPS2.Text)
536 case "23.976": x264 += " --fps 24000/1001"; break;
537 case "24": x264 += " --fps 24"; break;
538 case "25": x264 += " --fps 25"; break;
539 case "29.970": x264 += " --fps 30000/1001"; break;
540 case "30": x264 += " --fps 30"; break;
541 case "50": x264 += " --fps 50"; break;
542 case "59.940": x264 += " --fps 60000/1001"; break;
543 case "60": x264 += " --fps 60"; break;
544 default: x264 += " --fps " + cbFPS2.Text; break;
547 auto = auto + "\r\n" + x264;
550 //if (x264ShutdownCheckBox.Checked)
552 // auto += "\r\n" + syspath + ":\\Windows\\System32\\shutdown -f -s -t 60";
554 //auto += "\r\n@echo off&&echo MsgBox \"Finish!\",64,\"Maruko Toolbox\" >> msg.vbs &&call msg.vbs &&del msg.vbs\r\ncmd";
555 auto += "\r\n";
557 private void btnaudio_Click(object sender, EventArgs e)
559 openFileDialog1.Filter = "音频(*.aac;*.mp3;*.mp4)|*.aac;*.mp3;*.mp4|所有文件(*.*)|*.*";
560 DialogResult result = openFileDialog1.ShowDialog();
561 if (result == DialogResult.OK)
563 nameaudio = openFileDialog1.FileName;
564 txtaudio.Text = nameaudio;
567 private void btnvideo_Click(object sender, EventArgs e)
569 openFileDialog1.Filter = "所有文件(*.*)|*.*";
570 DialogResult result = openFileDialog1.ShowDialog();
571 if (result == DialogResult.OK)
573 namevideo = openFileDialog1.FileName;
574 txtvideo.Text = namevideo;
577 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
580 private void btnout_Click(object sender, EventArgs e)
582 SaveFileDialog savefile = new SaveFileDialog();
583 savefile.Filter = "视频(*.mp4)|*.mp4";
584 DialogResult result = savefile.ShowDialog();
585 if (result == DialogResult.OK)
587 nameout = savefile.FileName;
588 txtout.Text = nameout;
591 private void btnmux_Click(object sender, EventArgs e)
593 if (namevideo == "")
595 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
597 //else if (nameaudio == "")
599 // MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
601 else if (nameout == "")
603 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
605 else
607 if (cbFPS.Text == "auto")
609 mux = "\"" + workpath + "\\mp4box.exe\" -add \"" + namevideo + "\" -add \"" + nameaudio + "\" -new \"" + nameout + "\" \r\n cmd";
611 else
613 mux = "\"" + workpath + "\\mp4box.exe\" -fps " + cbFPS.Text + " -add \"" + namevideo + "\" -add \"" + nameaudio + "\" -new \"" + nameout + "\" \r\n cmd";
615 batpath = workpath + "\\mux.bat";
616 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
617 LogRecord(mux);
618 Process.Start(batpath);
621 private void btnaextract_Click(object sender, EventArgs e)
623 if (namevideo == "")
625 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
627 else
629 aextract = "\"" + workpath + "\\mp4box.exe\" -raw 2 \"" + namevideo + "\"";
630 batpath = workpath + "\\aextract.bat";
631 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
632 LogRecord(aextract);
633 System.Diagnostics.Process.Start(batpath);
636 private void button1_Click(object sender, EventArgs e)
638 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);
640 private void btnvextract_Click(object sender, EventArgs e)
642 if (namevideo == "")
644 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
646 else
648 vextract = "\"" + workpath + "\\mp4box.exe\" -raw 1 \"" + namevideo + "\"";
649 batpath = workpath + "\\vextract.bat";
650 File.WriteAllText(batpath, vextract, UnicodeEncoding.Default);
651 LogRecord(vextract);
652 System.Diagnostics.Process.Start(batpath);
655 private void txtvideo_TextChanged(object sender, EventArgs e)
657 if (File.Exists(txtvideo.Text.ToString()))
659 namevideo = txtvideo.Text;
660 txtout.Text = AddExt(txtvideo.Text, "_Mux.mp4");
663 private void txtaudio_TextChanged(object sender, EventArgs e)
665 nameaudio = txtaudio.Text;
667 private void txtout_TextChanged(object sender, EventArgs e)
669 nameout = txtout.Text;
671 private void btnout4_Click(object sender, EventArgs e)
673 if (namevideo2 == "")
675 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
677 else if (nameout2 == "")
679 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
681 else
683 //x264
684 oneAuto(namevideo2, nameout2);
685 batpath = workpath + "\\auto.bat";
686 LogRecord(auto);
687 WorkingForm wf = new WorkingForm(auto);
688 wf.Owner = this;
689 wf.Show();
690 //File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
691 //System.Diagnostics.Process.Start(batpath);
695 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
698 #region Delete Temp Files
700 if (SetupDeleteTempFileCheckBox.Checked && !workpath.Equals("!undefined"))
702 List<string> deleteFileList = new List<string>();
704 string systemDisk = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 3);
705 string systemTempPath = systemDisk + @"windows\temp";
707 //Delete all BAT files
708 DirectoryInfo theFolder = new DirectoryInfo(workpath);
709 foreach (FileInfo NextFile in theFolder.GetFiles())
711 if (NextFile.Extension.Equals(".bat"))
712 deleteFileList.Add(NextFile.FullName);
715 //string[] deletedfiles = { tempPic, "msg.vbs", tempavspath, "temp.avs", "clip.bat", "aextract.bat", "vextract.bat",
716 // "x264.bat", "aac.bat", "auto.bat", "mux.bat", "flv.bat", "mkvmerge.bat", "mkvextract.bat", "tmp.stat.mbtree", "tmp.stat" };
717 string[] deletedfiles = { tempPic, tempavspath, workpath + "msg.vbs", workpath + "tmp.stat.mbtree", workpath + "tmp.stat" };
718 deleteFileList.AddRange(deletedfiles);
720 foreach (string file in deleteFileList)
722 File.Delete(file);
725 #endregion
727 #region Save Settings
728 Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
729 cfa.AppSettings.Settings["x264CRF"].Value = x264CRFNum.Value.ToString();
730 cfa.AppSettings.Settings["x264Bitrate"].Value = x264BitrateNum.Value.ToString();
731 cfa.AppSettings.Settings["x264AudioParameter"].Value = x264AudioParameterTextBox.Text;
732 cfa.AppSettings.Settings["x264AudioMode"].Value = x264AudioModeComboBox.SelectedIndex.ToString();
733 cfa.AppSettings.Settings["x264Exe"].Value = x264ExeComboBox.SelectedIndex.ToString();
734 cfa.AppSettings.Settings["x264Demuxer"].Value = x264DemuxerComboBox.SelectedIndex.ToString();
735 cfa.AppSettings.Settings["x264Width"].Value = x264WidthNum.Value.ToString();
736 cfa.AppSettings.Settings["x264Height"].Value = x264HeightNum.Value.ToString();
737 cfa.AppSettings.Settings["x264CustomParameter"].Value = x264CustomParameterTextBox.Text;
738 cfa.AppSettings.Settings["x264Priority"].Value = x264PriorityComboBox.SelectedIndex.ToString();
739 cfa.AppSettings.Settings["AVSScript"].Value = AVSScriptTextBox.Text;
740 cfa.AppSettings.Settings["AudioEncoder"].Value = AudioEncoderComboBox.SelectedIndex.ToString();
741 cfa.AppSettings.Settings["AudioCustomParameter"].Value = AudioCustomParameterTextBox.Text;
742 cfa.AppSettings.Settings["AudioParameter"].Value = AudioBitrateComboBox.Text;
743 cfa.AppSettings.Settings["OnePicAudioBitrate"].Value = OnePicAudioBitrateNum.Value.ToString();
744 cfa.AppSettings.Settings["OnePicFPS"].Value = OnePicFPSNum.Value.ToString();
745 cfa.AppSettings.Settings["OnePicCRF"].Value = OnePicCRFNum.Value.ToString();
746 cfa.AppSettings.Settings["BlackFPS"].Value = BlackFPSNum.Value.ToString();
747 cfa.AppSettings.Settings["BlackCRF"].Value = BlackCRFNum.Value.ToString();
748 cfa.AppSettings.Settings["BlackBitrate"].Value = BlackBitrateNum.Value.ToString();
749 cfa.AppSettings.Settings["SetupDeleteTempFile"].Value = SetupDeleteTempFileCheckBox.Checked.ToString();
750 cfa.AppSettings.Settings["LanguageIndex"].Value = languageComboBox.SelectedIndex.ToString();
752 cfa.Save();
753 ConfigurationManager.RefreshSection("appSettings"); // 刷新命名节,在下次检索它时将从磁盘重新读取它。记住应用程序要刷新节点
754 #endregion
757 private void txtvideo4_TextChanged(object sender, EventArgs e)
759 if (File.Exists(txtvideo4.Text.ToString()))
761 namevideo4 = txtvideo4.Text;
762 //string finish = namevideo4.Insert(namevideo4.LastIndexOf(".")-1,"");
763 //string ext = namevideo4.Substring(namevideo4.LastIndexOf(".") + 1, 3);
764 //finish += "_clip." + ext;
765 string finish = namevideo4.Insert(namevideo4.LastIndexOf("."), "_clip");
766 txtout5.Text = finish;
769 private void txtout5_TextChanged(object sender, EventArgs e)
771 nameout5 = txtout5.Text;
773 private void btnvideo4_Click(object sender, EventArgs e)
775 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
776 DialogResult result = openFileDialog1.ShowDialog();
777 if (result == DialogResult.OK)
779 namevideo4 = openFileDialog1.FileName;
780 txtvideo4.Text = namevideo4;
783 private void btnout5_Click(object sender, EventArgs e)
785 SaveFileDialog savefile = new SaveFileDialog();
786 savefile.Filter = "视频(*.*)|*.*";
787 DialogResult result = savefile.ShowDialog();
788 if (result == DialogResult.OK)
790 nameout5 = savefile.FileName;
791 txtout5.Text = nameout5;
795 public static bool IsWindowsVistaOrNewer
797 get { return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 6); }
801 /// <summary>
802 /// 还原默认参数
803 /// </summary>
804 private void InitParameter()
806 x264CRFNum.Value = 24;
807 x264BitrateNum.Value = 800;
808 x264AudioParameterTextBox.Text = "--abitrate 128";
809 x264AudioModeComboBox.SelectedIndex = 5;
810 x264DemuxerComboBox.SelectedIndex = 2;
811 x264WidthNum.Value = 0;
812 x264HeightNum.Value = 0;
813 x264CustomParameterTextBox.Text = "";
814 x264PriorityComboBox.SelectedIndex = 2;
815 AudioEncoderComboBox.SelectedIndex = 0;
816 AudioCustomParameterTextBox.Text = "";
817 AudioBitrateComboBox.Text = "128";
818 OnePicAudioBitrateNum.Value = 128;
819 OnePicFPSNum.Value = 1;
820 OnePicCRFNum.Value = 24;
821 AVSScriptTextBox.Text = "";
822 BlackFPSNum.Value = 1;
823 BlackCRFNum.Value = 51;
824 BlackBitrateNum.Value = 900;
825 SetupDeleteTempFileCheckBox.Checked = true;
830 private void Form1_Load(object sender, EventArgs e)
832 var modulename = Process.GetCurrentProcess().MainModule.ModuleName;
833 var procesname = Path.GetFileNameWithoutExtension(modulename);
834 Process[] processes = Process.GetProcessesByName(procesname);
835 if (processes.Length > 1)
837 MessageBox.Show("你已经打开了一个小丸工具箱喔!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
838 this.Close();
840 //Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-TW");
841 //use YAHEI in VistaOrNewer
842 //if (IsWindowsVistaOrNewer)
844 // FontFamily myFontFamily = new FontFamily("微软雅黑"); //采用哪种字体
845 // Font myFont = new Font(myFontFamily, 9, FontStyle.Regular); //字是那种字体,显示的风格
846 // this.Font = myFont;
849 //define workpath
850 startpath = System.Windows.Forms.Application.StartupPath;
851 workpath = startpath + "\\tools";
852 if (!Directory.Exists(workpath))
853 Directory.CreateDirectory(workpath);
854 //string diskSymbol = startpath.Substring(0, 1);
856 string systemDisk = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 3);
857 string systemTempPath = systemDisk + @"windows\temp";
858 tempavspath = systemTempPath + "\\temp.avs";
859 tempPic = systemTempPath + "\\marukotemp.jpg";
860 InitParameter();
862 DirectoryInfo folder = new DirectoryInfo(workpath);
863 foreach (FileInfo FileName in folder.GetFiles())
865 if (FileName.Name.Contains("x264") && Path.GetExtension(FileName.Name) == ".exe")
867 x264ExeComboBox.Items.Add(FileName.Name);
871 ReleaseDatelabel.Text = ReleaseDate.ToString("yyyy-M-d");
873 //load Help Text
874 if (File.Exists(startpath + "\\help.txt"))
876 StreamReader sr = new StreamReader(startpath + "\\help.txt", System.Text.Encoding.UTF8);
877 HelpTextBox.Text = sr.ReadToEnd();
878 sr.Close();
882 //load settings
883 x264CRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264CRF"]);
884 x264BitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Bitrate"]);
885 x264AudioParameterTextBox.Text = ConfigurationManager.AppSettings["x264AudioParameter"];
886 x264AudioModeComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264AudioMode"]);
887 x264ExeComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Exe"]);
888 x264DemuxerComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Demuxer"]);
889 x264WidthNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Width"]);
890 x264HeightNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Height"]);
891 x264CustomParameterTextBox.Text = ConfigurationManager.AppSettings["x264CustomParameter"];
892 x264PriorityComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Priority"]);
893 AVSScriptTextBox.Text = ConfigurationManager.AppSettings["AVSScript"];
894 AudioEncoderComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["AudioEncoder"]);
895 AudioCustomParameterTextBox.Text = ConfigurationManager.AppSettings["AudioCustomParameter"];
896 AudioBitrateComboBox.Text = ConfigurationManager.AppSettings["AudioBitrate"];
897 OnePicAudioBitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicAudioBitrate"]);
898 OnePicFPSNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicFPS"]);
899 OnePicCRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicCRF"]);
900 BlackFPSNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackFPS"]);
901 BlackCRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackCRF"]);
902 BlackBitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackBitrate"]);
903 SetupDeleteTempFileCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["SetupDeleteTempFile"]);
905 if (x264ExeComboBox.SelectedIndex == -1)
907 x264ExeComboBox.SelectedIndex = x264ExeComboBox.Items.IndexOf("x264_32_tMod-8bit-420.exe");
910 if (int.Parse(ConfigurationManager.AppSettings["LanguageIndex"]) == -1) //First Startup
912 string culture = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
913 switch (culture)
915 case "zh-CN":
916 languageComboBox.SelectedIndex = 0;
917 break;
918 case "zh-SG":
919 languageComboBox.SelectedIndex = 0;
920 break;
921 case "zh-TW":
922 languageComboBox.SelectedIndex = 1;
923 break;
924 case "zh-HK ":
925 languageComboBox.SelectedIndex = 1;
926 break;
927 case "zh-MO":
928 languageComboBox.SelectedIndex = 1;
929 break;
930 case "en-US":
931 languageComboBox.SelectedIndex = 2;
932 break;
933 case "ja-JP":
934 languageComboBox.SelectedIndex = 3;
935 break;
936 default:
937 break;
940 else
941 languageComboBox.SelectedIndex = int.Parse(ConfigurationManager.AppSettings["LanguageIndex"]);
943 catch (Exception)
945 throw;
947 //create directory
948 string preset = workpath + "\\preset";
949 if (!Directory.Exists(preset))
950 Directory.CreateDirectory(preset);
951 DirectoryInfo TheFolder = new DirectoryInfo(preset);
952 foreach (FileInfo FileName in TheFolder.GetFiles())
954 cbX264.Items.Add(FileName.Name.Replace(".txt", ""));
959 private void button2_Click(object sender, EventArgs e)
961 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
962 DialogResult result = openFileDialog1.ShowDialog();
963 if (result == DialogResult.OK)
965 namevideo6 = openFileDialog1.FileName;
966 txtvideo6.Text = namevideo6;
969 private void label16_Click(object sender, EventArgs e)
972 private void button3_Click(object sender, EventArgs e)
974 if (namevideo6 == "")
976 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
978 else
980 mkvextract = workpath + "\\ mkvextract.exe tracks \"" + namevideo6 + "\" 1:video.h264 2:audio.aac";
981 batpath = workpath + "\\mkvextract.bat";
982 File.WriteAllText(batpath, mkvextract, UnicodeEncoding.Default);
983 System.Diagnostics.Process.Start(batpath);
986 private void button4_Click(object sender, EventArgs e)
988 openFileDialog1.Filter = "视频(*.mp4)|*.mp4|所有文件(*.*)|*.*";
989 DialogResult result = openFileDialog1.ShowDialog();
990 if (result == DialogResult.OK)
992 namevideo5 = openFileDialog1.FileName;
993 txtvideo5.Text = namevideo5;
996 private void button5_Click(object sender, EventArgs e)
998 openFileDialog1.Filter = "音频(*.mp3)|*.mp3|音频(*.aac)|*.aac|所有文件(*.*)|*.*";
999 DialogResult result = openFileDialog1.ShowDialog();
1000 if (result == DialogResult.OK)
1002 nameaudio3 = openFileDialog1.FileName;
1003 txtaudio3.Text = nameaudio3;
1006 private void button6_Click(object sender, EventArgs e)
1008 SaveFileDialog savefile = new SaveFileDialog();
1009 savefile.Filter = "视频(*.mkv)|*.mkv";
1010 DialogResult result = savefile.ShowDialog();
1011 if (result == DialogResult.OK)
1013 nameout6 = savefile.FileName;
1014 txtout6.Text = nameout6;
1017 private void button7_Click(object sender, EventArgs e)
1019 if (namevideo5 == "")
1021 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1023 else if (nameaudio3 == "")
1025 MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1027 else if (nameout6 == "")
1029 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1031 else
1033 mkvmerge = workpath + "\\mkvmerge.exe -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\"";
1034 batpath = workpath + "\\mkvmerge.bat";
1035 File.WriteAllText(batpath, mkvmerge, UnicodeEncoding.Default);
1036 System.Diagnostics.Process.Start(batpath);
1040 private void button2_Click_1(object sender, EventArgs e)
1042 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1043 DialogResult result = openFileDialog1.ShowDialog();
1044 if (result == DialogResult.OK)
1046 namevideo5 = openFileDialog1.FileName;
1047 txtvideo5.Text = namevideo5;
1050 private void button6_Click_1(object sender, EventArgs e)
1052 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
1053 DialogResult result = openFileDialog1.ShowDialog();
1054 if (result == DialogResult.OK)
1056 namevideo6 = openFileDialog1.FileName;
1057 txtvideo6.Text = namevideo6;
1060 private void button7_Click_1(object sender, EventArgs e)
1062 if (namevideo5 == "" && nameaudio3 == "")
1064 MessageBox.Show("请选择文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1066 else
1068 if (txtaudio3.Text != "" && txtsub.Text != "")
1070 mkvmerge = "\"" + workpath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\" \"" + namesub + "\"";
1072 if (txtaudio3.Text == "" && txtsub.Text == "")
1074 mkvmerge = "\"" + workpath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\"";
1076 if (txtaudio3.Text != "" && txtsub.Text == "")
1078 mkvmerge = "\"" + workpath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\"";
1080 if (txtaudio3.Text == "" && txtsub.Text != "")
1082 mkvmerge = "\"" + workpath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + namesub + "\"";
1084 mkvmerge += "\r\ncmd";
1085 batpath = workpath + "\\mkvmerge.bat";
1086 File.WriteAllText(batpath, mkvmerge, UnicodeEncoding.Default);
1087 LogRecord(mkvmerge);
1088 System.Diagnostics.Process.Start(batpath);
1091 private void button4_Click_1(object sender, EventArgs e)
1093 SaveFileDialog savefile = new SaveFileDialog();
1094 savefile.Filter = "视频(*.mkv)|*.mkv";
1095 DialogResult result = savefile.ShowDialog();
1096 if (result == DialogResult.OK)
1098 nameout6 = savefile.FileName;
1099 txtout6.Text = nameout6;
1102 private void button3_Click_1(object sender, EventArgs e)
1104 openFileDialog1.Filter = "音频(*.mp3;*.aac)|*.mp3;*.aac|所有文件(*.*)|*.*";
1105 DialogResult result = openFileDialog1.ShowDialog();
1106 if (result == DialogResult.OK)
1108 nameaudio3 = openFileDialog1.FileName;
1109 txtaudio3.Text = nameaudio3;
1112 private void button5_Click_1(object sender, EventArgs e)
1114 openFileDialog1.Filter = "ASS字幕(*.ass;*.srt)|*.ass;*.srt|所有文件(*.*)|*.*";
1115 DialogResult result = openFileDialog1.ShowDialog();
1116 if (result == DialogResult.OK)
1118 namesub = openFileDialog1.FileName;
1119 txtsub.Text = namesub;
1122 private void button8_Click(object sender, EventArgs e)
1124 if (namevideo6 == "")
1126 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1128 else
1130 int i = namevideo6.IndexOf(".mkv");
1131 string mkvname = namevideo6.Remove(i);
1132 mkvextract = "\"" + workpath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 1:\"" + mkvname + "_video.h264\" 2:\"" + mkvname + "_audio.aac\"";
1133 batpath = workpath + "\\mkvextract.bat";
1134 File.WriteAllText(batpath, mkvextract, UnicodeEncoding.Default);
1135 System.Diagnostics.Process.Start(batpath);
1138 private void txtvideo5_TextChanged(object sender, EventArgs e)
1140 if (File.Exists(txtvideo5.Text.ToString()))
1142 namevideo5 = txtvideo5.Text;
1143 string finish = namevideo5.Remove(namevideo5.LastIndexOf("."));
1144 finish += "_mkv封装.mkv";
1145 txtout6.Text = finish;
1148 private void txtaudio3_TextChanged(object sender, EventArgs e)
1150 nameaudio3 = txtaudio3.Text;
1152 private void txtsub_TextChanged(object sender, EventArgs e)
1154 namesub = txtsub.Text;
1156 private void txtout6_TextChanged_1(object sender, EventArgs e)
1158 nameout6 = txtout6.Text;
1160 private void txtvideo6_TextChanged(object sender, EventArgs e)
1162 namevideo6 = txtvideo6.Text;
1165 private void btnAutoAdd_Click(object sender, EventArgs e)
1167 openFileDialog1.Multiselect = true;
1168 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1169 DialogResult result = openFileDialog1.ShowDialog();
1170 if (result == DialogResult.OK)
1172 lbAuto.Items.AddRange(openFileDialog1.FileNames);
1175 private void btnAutoDel_Click(object sender, EventArgs e)
1177 if (lbAuto.Items.Count > 0)
1179 if (lbAuto.SelectedItems.Count > 0)
1181 int index = lbAuto.SelectedIndex;
1182 lbAuto.Items.RemoveAt(lbAuto.SelectedIndex);
1183 if (index == lbAuto.Items.Count)
1185 lbAuto.SelectedIndex = index - 1;
1187 if (index >= 0 && index < lbAuto.Items.Count && lbAuto.Items.Count > 0)
1189 lbAuto.SelectedIndex = index;
1194 private void btnAutoClear_Click(object sender, EventArgs e)
1196 lbAuto.Items.Clear();
1198 private void lbAuto_DragDrop(object sender, DragEventArgs e)
1200 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
1202 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
1203 foreach (String s in files)
1205 (sender as ListBox).Items.Add(s);
1208 ListBox listbox = (ListBox)sender;
1209 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
1210 if (indexoftarget != ListBox.NoMatches)
1212 string temp = listbox.Items[indexoftarget].ToString();
1213 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
1214 listbox.Items[indexofsource] = temp;
1215 listbox.SelectedIndex = indexoftarget;
1218 private void lbAuto_DragEnter(object sender, DragEventArgs e)
1220 //if (e.Data.GetDataPresent(DataFormats.FileDrop))
1221 // e.Effect = DragDropEffects.All;
1222 //else e.Effect = DragDropEffects.None;
1224 private void lbAuto_DragOver(object sender, DragEventArgs e)
1226 //拖动源和放置的目的地一定是一个ListBox
1227 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lbAuto))
1229 e.Effect = DragDropEffects.Move;
1231 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
1233 e.Effect = DragDropEffects.Link;
1235 else e.Effect = DragDropEffects.None;
1237 private void lbAuto_MouseDown(object sender, MouseEventArgs e)
1239 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
1240 if (indexofsource != ListBox.NoMatches)
1242 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
1245 private void btnBatchAuto_Click(object sender, EventArgs e)
1247 if (lbAuto.Items.Count != 0)
1249 batchAuto2();
1250 batpath = workpath + "\\auto.bat";
1251 LogRecord(auto);
1252 WorkingForm wf = new WorkingForm(auto, lbAuto.Items.Count);
1253 wf.Owner = this;
1254 wf.Show();
1256 //File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
1257 //System.Diagnostics.Process.Start(batpath);
1259 else MessageBox.Show("请输入视频!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1261 private void lbffmpeg_MouseDown(object sender, MouseEventArgs e)
1263 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
1264 if (indexofsource != ListBox.NoMatches)
1266 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
1269 private void lbffmpeg_DragDrop(object sender, DragEventArgs e)
1271 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
1273 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
1274 foreach (String s in files)
1276 (sender as ListBox).Items.Add(s);
1279 ListBox listbox = (ListBox)sender;
1280 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
1281 if (indexoftarget != ListBox.NoMatches)
1283 string temp = listbox.Items[indexoftarget].ToString();
1284 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
1285 listbox.Items[indexofsource] = temp;
1286 listbox.SelectedIndex = indexoftarget;
1289 private void lbffmpeg_DragOver(object sender, DragEventArgs e)
1291 //拖动源和放置的目的地一定是一个ListBox
1292 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lbffmpeg))
1294 e.Effect = DragDropEffects.Move;
1296 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
1298 e.Effect = DragDropEffects.Link;
1300 else e.Effect = DragDropEffects.None;
1302 private void btnffmpegAdd_Click(object sender, EventArgs e)
1304 openFileDialog1.Multiselect = true;
1305 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1306 DialogResult result = openFileDialog1.ShowDialog();
1307 if (result == DialogResult.OK)
1309 lbffmpeg.Items.AddRange(openFileDialog1.FileNames);
1312 private void btnffmpegDel_Click(object sender, EventArgs e)
1314 if (lbffmpeg.Items.Count > 0)
1316 if (lbffmpeg.SelectedItems.Count > 0)
1318 int index = lbffmpeg.SelectedIndex;
1319 lbffmpeg.Items.RemoveAt(lbffmpeg.SelectedIndex);
1320 if (index == lbffmpeg.Items.Count)
1322 lbffmpeg.SelectedIndex = index - 1;
1324 if (index >= 0 && index < lbffmpeg.Items.Count && lbffmpeg.Items.Count > 0)
1326 lbffmpeg.SelectedIndex = index;
1331 private void btnffmpegClear_Click(object sender, EventArgs e)
1333 lbffmpeg.Items.Clear();
1335 private void btnBatchFLV_Click(object sender, EventArgs e)
1337 if (lbffmpeg.Items.Count != 0)
1339 string finish;
1340 int i;
1341 ffmpeg = "";
1342 for (i = 0; i < this.lbffmpeg.Items.Count; i++)
1344 finish = lbffmpeg.Items[i].ToString().Remove(lbffmpeg.Items[i].ToString().LastIndexOf(".")) + "_FLV封装.flv";
1345 ffmpeg += "\"" + workpath + "\\ffmpeg.exe\" -i \"" + lbffmpeg.Items[i].ToString() + "\" -c copy -f flv \"" + finish + "\" \r\n";
1347 ffmpeg += "\r\ncmd";
1348 batpath = workpath + "\\flv.bat";
1349 File.WriteAllText(batpath, ffmpeg, UnicodeEncoding.Default);
1350 LogRecord(ffmpeg);
1351 System.Diagnostics.Process.Start(batpath);
1352 //lbffmpeg.Items.Clear();
1354 else MessageBox.Show("请输入视频!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1356 private void btnBatchMP4_Click(object sender, EventArgs e)
1358 if (lbffmpeg.Items.Count != 0)
1360 string finish;
1361 int i;
1362 ffmpeg = "";
1363 for (i = 0; i < this.lbffmpeg.Items.Count; i++)
1365 finish = lbffmpeg.Items[i].ToString().Remove(lbffmpeg.Items[i].ToString().LastIndexOf(".")) + "_MP4封装.mp4";
1366 ffmpeg += "\"" + workpath + "\\ffmpeg.exe\" -i \"" + lbffmpeg.Items[i].ToString() + "\" -c copy -f mp4 \"" + finish + "\" \r\n";
1368 ffmpeg += "\r\ncmd";
1369 batpath = workpath + "\\flv.bat";
1370 File.WriteAllText(batpath, ffmpeg, UnicodeEncoding.Default);
1371 LogRecord(ffmpeg);
1372 System.Diagnostics.Process.Start(batpath);
1373 //lbffmpeg.Items.Clear();
1375 else MessageBox.Show("请输入视频!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1377 private void txtvideo8_TextChanged(object sender, EventArgs e)
1379 namevideo8 = txtvideo8.Text;
1381 private void btnvextract8_Click(object sender, EventArgs e)
1383 if (namevideo8 == "")
1385 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1387 else
1389 vextract = "\"" + workpath + "\\FLVExtractCL.exe\" -v \"" + namevideo8 + "\"";
1390 batpath = workpath + "\\vextract.bat";
1391 File.WriteAllText(batpath, vextract, UnicodeEncoding.Default);
1392 LogRecord(vextract);
1393 System.Diagnostics.Process.Start(batpath);
1396 private void btnaextract8_Click(object sender, EventArgs e)
1398 if (namevideo8 == "")
1400 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1402 else
1404 aextract = "\"" + workpath + "\\FLVExtractCL.exe\" -a \"" + namevideo8 + "\"";
1405 batpath = workpath + "\\aextract.bat";
1406 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
1407 LogRecord(aextract);
1408 System.Diagnostics.Process.Start(batpath);
1411 private void btnvideo8_Click(object sender, EventArgs e)
1413 openFileDialog1.Filter = "视频(*.flv;*.hlv)|*.flv;*.hlv";
1414 DialogResult result = openFileDialog1.ShowDialog();
1415 if (result == DialogResult.OK)
1417 namevideo8 = openFileDialog1.FileName;
1418 txtvideo8.Text = namevideo;
1421 private void btnpreview9_Click(object sender, EventArgs e)
1423 if (AVSScriptTextBox.Text != "")
1425 string filepath = workpath + "\\temp.avs";
1426 File.WriteAllText(filepath, AVSScriptTextBox.Text.ToString(), UnicodeEncoding.Default);
1427 PreviewForm form2 = new PreviewForm();
1428 form2.Show();
1429 form2.axWindowsMediaPlayer1.URL = filepath;
1431 else
1433 MessageBox.Show("请输入正确的AVS脚本!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1436 private void txtout_MouseDoubleClick(object sender, MouseEventArgs e)
1438 if (File.Exists(txtout.Text.ToString()))
1440 System.Diagnostics.Process.Start(txtout.Text.ToString());
1443 private void txtout3_MouseDoubleClick(object sender, MouseEventArgs e)
1445 if (File.Exists(txtout3.Text.ToString()))
1447 System.Diagnostics.Process.Start(txtout3.Text.ToString());
1450 private void txtout6_MouseDoubleClick(object sender, MouseEventArgs e)
1452 if (File.Exists(txtout6.Text.ToString()))
1454 System.Diagnostics.Process.Start(txtout6.Text.ToString());
1457 private void txtout9_MouseDoubleClick(object sender, MouseEventArgs e)
1459 if (File.Exists(txtout9.Text.ToString()))
1461 System.Diagnostics.Process.Start(txtout9.Text.ToString());
1464 private void txtvideo9_TextChanged(object sender, EventArgs e)
1466 if (File.Exists(txtvideo9.Text.ToString()))
1468 namevideo9 = txtvideo9.Text;
1469 string finish = namevideo9.Remove(namevideo9.LastIndexOf("."));
1470 finish += "_AVS压制.mp4";
1471 txtout9.Text = finish;
1472 GenerateAVS();
1474 //if (txtvideo9.Text != "")
1476 // if (txtAVS.Text != "")
1477 // {
1478 // txtAVS.Text = txtAVS.Text.Replace(prevideo9, txtvideo9.Text);
1479 // }
1480 // else
1481 // {
1482 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1483 // foreach (FileInfo FileName in TheFolder.GetFiles())
1484 // {
1485 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1486 // }
1487 // avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\n" + "TextSub(\"" + namesub9 + "\")\r\n";
1488 // txtAVS.Text = avs;
1489 // avs = "";
1490 // }
1491 // prevideo9 = txtvideo9.Text;
1494 private void txtsub9_TextChanged(object sender, EventArgs e)
1496 namesub9 = txtsub9.Text;
1497 GenerateAVS();
1498 //if (txtAVS.Text != "")
1500 // txtAVS.Text=txtAVS.Text.Replace(namesub9, txtsub9.Text);
1501 // namesub9 = txtsub9.Text;
1503 //else
1505 // namesub9 = txtsub9.Text;
1506 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1507 // foreach (FileInfo FileName in TheFolder.GetFiles())
1508 // {
1509 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1510 // }
1511 // avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\n" + "TextSub(\"" + namesub9 + "\")\r\n";
1512 // txtAVS.Text = avs;
1513 // avs = "";
1516 private void txtout9_TextChanged(object sender, EventArgs e)
1518 nameout9 = txtout9.Text;
1520 private void btnAVS9_Click(object sender, EventArgs e)
1522 if (String.IsNullOrEmpty(nameout9))
1524 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1526 else
1528 string filepath = tempavspath;
1529 //string filepath = workpath + "\\temp.avs";
1530 File.WriteAllText(filepath, AVSScriptTextBox.Text, UnicodeEncoding.Default);
1531 x264 = x264bat(filepath, nameout9).Replace("\r\n", "");
1532 x264 += " --acodec none\r\n";
1533 batpath = workpath + "\\x264.bat";
1534 File.WriteAllText(batpath, x264, UnicodeEncoding.Default);
1535 LogRecord(x264);
1536 System.Diagnostics.Process.Start(batpath);
1539 private void btnout9_Click(object sender, EventArgs e)
1541 SaveFileDialog savefile = new SaveFileDialog();
1542 savefile.Filter = "视频(*.mp4)|*.mp4";
1543 DialogResult result = savefile.ShowDialog();
1544 if (result == DialogResult.OK)
1546 txtout9.Text = nameout9 = savefile.FileName;
1549 private void btnAVSone_Click(object sender, EventArgs e)
1551 if (String.IsNullOrEmpty(nameout9))
1553 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1555 else
1557 string filepath = workpath + "\\temp.avs";
1558 File.WriteAllText(filepath, AVSScriptTextBox.Text, UnicodeEncoding.Default);
1559 x264 = x264bat(filepath, "temp.mp4").Replace("\r\n", "");
1560 x264 += " --acodec none\r\n";
1561 //audio
1562 aextract = audiobat(namevideo9, "temp.aac");
1563 //mux
1564 mux = muxbat("temp.mp4", "temp.aac", "23.976", nameout9);
1565 //if (cbDelTmp.Checked == false)
1567 // auto = aextract + x264 + "\r\n" + mux + " \r\ndel temp.aac\r\ndel temp.mp4\r\ndel temp.wav\r\ncmd ";
1569 //else
1571 auto = aextract + x264 + "\r\n" + mux + " \r\ncmd";
1573 batpath = workpath + "\\auto.bat";
1574 File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
1575 System.Diagnostics.Process.Start(batpath);
1578 private void button6_Click_2(object sender, EventArgs e)
1580 //if (Directory.Exists("avsfilter"))
1582 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1583 // foreach (FileInfo FileName in TheFolder.GetFiles())
1584 // {
1585 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1586 // }
1588 avs += "LoadPlugin(\"avsfilter\\VSFilter.DLL\")\r\n";
1589 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);
1590 //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";
1591 AVSScriptTextBox.Text = avs;
1592 avs = "";
1594 private void txth264_TextChanged(object sender, EventArgs e)
1597 private void txtvideo_MouseDoubleClick(object sender, MouseEventArgs e)
1599 if (File.Exists(txtvideo.Text.ToString()))
1601 System.Diagnostics.Process.Start(txtvideo.Text.ToString());
1604 private void txtvideo4_MouseDoubleClick(object sender, MouseEventArgs e)
1606 if (File.Exists(txtvideo4.Text.ToString()))
1608 System.Diagnostics.Process.Start(txtvideo4.Text.ToString());
1611 private void txtout5_MouseDoubleClick(object sender, MouseEventArgs e)
1613 if (File.Exists(txtout5.Text.ToString()))
1615 System.Diagnostics.Process.Start(txtout5.Text.ToString());
1618 private void txtvideo8_MouseDoubleClick(object sender, MouseEventArgs e)
1620 if (File.Exists(txtvideo8.Text.ToString()))
1622 System.Diagnostics.Process.Start(txtvideo8.Text.ToString());
1625 private void txtvideo9_MouseDoubleClick(object sender, MouseEventArgs e)
1627 if (File.Exists(txtvideo9.Text.ToString()))
1629 System.Diagnostics.Process.Start(txtvideo9.Text.ToString());
1632 private void txtvideo6_MouseDoubleClick(object sender, MouseEventArgs e)
1634 if (File.Exists(txtvideo6.Text.ToString()))
1636 System.Diagnostics.Process.Start(txtvideo6.Text.ToString());
1639 private void txtvideo5_MouseDoubleClick(object sender, MouseEventArgs e)
1641 if (File.Exists(txtvideo5.Text.ToString()))
1643 System.Diagnostics.Process.Start(txtvideo5.Text.ToString());
1646 private void txtaudio3_MouseDoubleClick(object sender, MouseEventArgs e)
1648 if (File.Exists(txtaudio3.Text.ToString()))
1650 System.Diagnostics.Process.Start(txtaudio3.Text.ToString());
1653 private void timer1_Tick(object sender, EventArgs e)
1655 Process[] processes = Process.GetProcesses();
1656 for (int i = 0; i < processes.GetLength(0); i++)
1658 //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
1659 if (processes[i].ProcessName.Equals(Path.GetFileNameWithoutExtension(x264ExeComboBox.Text)))
1661 switch (x264PriorityComboBox.SelectedIndex)
1663 case 0: processes[i].PriorityClass = ProcessPriorityClass.Idle; break;
1664 case 1: processes[i].PriorityClass = ProcessPriorityClass.BelowNormal; break;
1665 case 2: processes[i].PriorityClass = ProcessPriorityClass.Normal; break;
1666 case 3: processes[i].PriorityClass = ProcessPriorityClass.AboveNormal; break;
1667 case 4: processes[i].PriorityClass = ProcessPriorityClass.High; break;
1668 case 5: processes[i].PriorityClass = ProcessPriorityClass.RealTime; break;
1673 private void btnsub9_Click(object sender, EventArgs e)
1675 openFileDialog1.Filter = "ASS字幕(*.ass;*.ssa)|*.ass;*.ssa|所有文件(*.*)|*.*";
1676 DialogResult result = openFileDialog1.ShowDialog();
1677 if (result == DialogResult.OK)
1679 namesub9 = openFileDialog1.FileName;
1680 txtsub9.Text = namesub9;
1683 private void btnvideo9_Click(object sender, EventArgs e)
1685 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
1686 DialogResult result = openFileDialog1.ShowDialog();
1687 if (result == DialogResult.OK)
1689 namevideo9 = openFileDialog1.FileName;
1690 txtvideo9.Text = namevideo9;
1693 private void button9_Click(object sender, EventArgs e)
1695 AVSScriptTextBox.Clear();
1697 private void btnClip_Click(object sender, EventArgs e)
1699 if (namevideo4 == "")
1701 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1703 else if (nameout5 == "")
1705 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1707 else
1709 int h1 = int.Parse(maskb.Text.ToString().Substring(0, 2));
1710 int m1 = int.Parse(maskb.Text.ToString().Substring(3, 2));
1711 int s1 = int.Parse(maskb.Text.ToString().Substring(6, 2));
1712 int h2 = int.Parse(maske.Text.ToString().Substring(0, 2));
1713 int m2 = int.Parse(maske.Text.ToString().Substring(3, 2));
1714 int s2 = int.Parse(maske.Text.ToString().Substring(6, 2));
1715 clip = "\"" + workpath + "\\ffmpeg.exe\" -ss " + maskb.Text.ToString() + " -t " + timeminus(h1, m1, s1, h2, m2, s2) + " -i \"" + namevideo4 + "\" -c copy \"" + nameout5 + "\" \r\ncmd";
1716 batpath = workpath + "\\clip.bat";
1717 File.WriteAllText(batpath, clip, UnicodeEncoding.Default);
1718 Process.Start(batpath);
1721 private void cbX264_SelectedIndexChanged(object sender, EventArgs e)
1723 StreamReader sr = new StreamReader(workpath + "\\preset\\" + cbX264.Text + ".txt", System.Text.Encoding.Default);
1724 x264CustomParameterTextBox.Text = sr.ReadToEnd();
1725 sr.Close();
1727 private void cbFPS_SelectedIndexChanged(object sender, EventArgs e)
1730 private void btnMIopen_Click(object sender, EventArgs e)
1732 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
1733 DialogResult result = openFileDialog1.ShowDialog();
1734 if (result == DialogResult.OK)
1736 MIvideo = openFileDialog1.FileName;
1737 MediaInfoTextBox.Text = MediaInfo(MIvideo);
1740 private void btnMIplay_Click(object sender, EventArgs e)
1742 Process.Start(MIvideo);
1744 private void btnMIcopy_Click(object sender, EventArgs e)
1746 Clipboard.SetText(MItext);
1748 private void btnvideo7_Click(object sender, EventArgs e)
1750 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
1751 DialogResult result = openFileDialog1.ShowDialog();
1752 if (result == DialogResult.OK)
1754 namevideo6 = openFileDialog1.FileName;
1755 txtvideo6.Text = namevideo6;
1758 private void btnextract7_Click(object sender, EventArgs e)
1760 if (namevideo6 == "")
1762 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1764 else
1766 int i = namevideo6.IndexOf(".");
1767 string mkvname = namevideo6.Remove(i);
1768 QQButton btn = (QQButton)sender;
1769 switch (btn.Name)
1771 case "MkvExtract1Button":
1772 mkvextract = "\"" + workpath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 1:\"" + mkvname + "_audio.aac\"";
1773 break;
1774 case "MkvExtract2Button":
1775 mkvextract = "\"" + workpath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 2:\"" + mkvname + "_track2\"";
1776 break;
1777 case "MkvExtract3Button":
1778 mkvextract = "\"" + workpath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 3:\"" + mkvname + "_track3\"";
1779 break;
1780 case "MkvExtract4Button":
1781 mkvextract = "\"" + workpath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 4:\"" + mkvname + "_track4\"";
1782 break;
1783 case "btnextract7":
1784 mkvextract = "\"" + workpath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 0:\"" + mkvname + "_video.h264\"";
1785 break;
1787 batpath = workpath + "\\mkvextract.bat";
1788 File.WriteAllText(batpath, mkvextract, UnicodeEncoding.Default);
1789 LogRecord(mkvextract);
1790 System.Diagnostics.Process.Start(batpath);
1793 private void txtMI_TextChanged(object sender, EventArgs e)
1795 MItext = MediaInfoTextBox.Text;
1797 private void txtAVScreate_Click(object sender, EventArgs e)
1800 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
1802 System.Diagnostics.Process.Start("http://www.nmm-hd.org/newbbs/viewtopic.php?f=8&t=219");
1804 private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
1806 System.Diagnostics.Process.Start("http://www.sosg.net/read.php?tid=480646");
1808 private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
1810 System.Diagnostics.Process.Start("http://pan.baidu.com/share/link?shareid=4513&uk=4094576855");
1812 private void btnaextract2_Click(object sender, EventArgs e)
1814 if (namevideo == "")
1816 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1818 else
1820 aextract = "\"" + workpath + "\\mp4box.exe\" -raw 3 \"" + namevideo + "\"";
1821 batpath = workpath + "\\aextract.bat";
1822 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
1823 LogRecord(aextract);
1824 System.Diagnostics.Process.Start(batpath);
1827 private void btnaextract3_Click(object sender, EventArgs e)
1829 if (namevideo == "")
1831 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1833 else
1835 aextract = "\"" + workpath + "\\mp4box.exe\" -raw 4 \"" + namevideo + "\"";
1836 batpath = workpath + "\\aextract.bat";
1837 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
1838 LogRecord(aextract);
1839 System.Diagnostics.Process.Start(batpath);
1842 private void txtvideo6_TextChanged_1(object sender, EventArgs e)
1844 if (File.Exists(txtvideo6.Text.ToString()))
1846 namevideo6 = txtvideo6.Text;
1849 #region 帮助页面
1850 private void AboutBtn_Click(object sender, EventArgs e)
1852 DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
1853 QQMessageBox.Show(
1854 this,
1855 "小丸工具箱 2014版\r\n主页:http://maruko.appinn.me/ \r\n编译日期:" + CompileDate.ToString(),
1856 "关于",
1857 QQMessageBoxIcon.Information,
1858 QQMessageBoxButtons.OK);
1860 private void HomePageBtn_Click(object sender, EventArgs e)
1862 System.Diagnostics.Process.Start("http://maruko.appinn.me/");
1864 #endregion
1865 #region 视频页面
1866 private void x264OneBatchButton_Click(object sender, EventArgs e)
1868 if (lbAuto.Items.Count != 0)
1870 batchAuto();
1871 batpath = workpath + "\\auto.bat";
1872 LogRecord(auto);
1873 WorkingForm wf = new WorkingForm(auto);
1874 wf.Owner = this;
1875 wf.Show();
1877 //File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
1878 //System.Diagnostics.Process.Start(batpath);
1880 else MessageBox.Show("请输入视频!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1882 private void x264VideoBtn_Click(object sender, EventArgs e)
1885 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv;*.avi;*.wmv;*.mpg;*.avs)|*.mp4;*.flv;*.mkv;*.avi;*.wmv;*.mpg;*.avs|所有文件(*.*)|*.*";
1886 DialogResult result = openFileDialog1.ShowDialog();
1887 if (result == DialogResult.OK)
1889 namevideo2 = openFileDialog1.FileName;
1890 x264VideoTextBox.Text = namevideo2;
1893 private void x264OutBtn_Click(object sender, EventArgs e)
1895 SaveFileDialog savefile = new SaveFileDialog();
1896 savefile.Filter = "视频(*.mp4)|*.mp4";
1897 DialogResult result = savefile.ShowDialog();
1898 if (result == DialogResult.OK)
1900 nameout2 = savefile.FileName;
1901 x264OutTextBox.Text = nameout2;
1904 private void x264SubBtn_Click(object sender, EventArgs e)
1906 openFileDialog1.Filter = "ASS字幕(*.ass;*.ssa)|*.ass;*.ssa|所有文件(*.*)|*.*";
1907 DialogResult result = openFileDialog1.ShowDialog();
1908 if (result == DialogResult.OK)
1910 namesub2 = openFileDialog1.FileName;
1911 x264SubTextBox.Text = namesub2;
1914 private void x264StartBtn_Click(object sender, EventArgs e)
1916 if (namevideo2 == "")
1918 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1920 else if (nameout2 == "")
1922 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1924 else
1926 //如果是AVS复制到C盘根目录
1927 if (Path.GetExtension(x264VideoTextBox.Text) == ".avs")
1929 //if (File.Exists(tempavspath)) File.Delete(tempavspath);
1930 File.Copy(x264VideoTextBox.Text, tempavspath, true);
1931 namevideo2 = tempavspath;
1933 x264 = x264bat(namevideo2, nameout2).Replace("\r\n", "");
1934 if (x264SubTextBox.Text != "")
1936 if (x264.IndexOf("--vf") == -1)
1938 x264 += " --vf subtitles --sub \"" + namesub2 + "\"";
1940 else
1942 Regex r = new Regex("--vf\\s\\S*");
1943 Match m = r.Match(x264);
1944 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles");
1945 x264 += " --sub \"" + namesub2 + "\"";
1948 switch (x264AudioModeComboBox.SelectedIndex)
1950 case 1: x264 += " --acodec none"; break;
1951 case 2: x264 += " --acodec copy"; break;
1952 case 3: x264 += " --audiofile \"" + x264AudioParameterTextBox.Text + "\""; break;
1953 case 4: x264 += " --acodec qtaac " + x264AudioParameterTextBox.Text; break;
1954 case 5: x264 += " --acodec faac " + x264AudioParameterTextBox.Text; break;
1955 //case 6: x264 += " --acodec libaacplus " + x264AudioParameterTextBox.Text; break;
1956 case 0: break;
1957 default: ; break;
1959 if (cbFPS2.Text != "auto")
1961 switch (cbFPS2.Text)
1963 case "23.976": x264 += " --fps 24000/1001"; break;
1964 case "24": x264 += " --fps 24"; break;
1965 case "25": x264 += " --fps 25"; break;
1966 case "29.970": x264 += " --fps 30000/1001"; break;
1967 case "30": x264 += " --fps 30"; break;
1968 case "50": x264 += " --fps 50"; break;
1969 case "59.940": x264 += " --fps 60000/1001"; break;
1970 case "60": x264 += " --fps 60"; break;
1971 default: x264 += " --fps " + cbFPS2.Text; break;
1974 if (x264SeekNumericUpDown.Value != 0)
1976 x264 += " --seek " + x264SeekNumericUpDown.Value.ToString();
1978 if (x264FramesNumericUpDown.Value != 0)
1980 x264 += " --frames " + x264FramesNumericUpDown.Value.ToString();
1982 x264 += "\r\n";
1983 if (x264FLVCheckBox.Checked == true)
1985 string flvfile = AddExt(nameout2, "_FLV.flv");
1986 x264 += "\r\n\"" + workpath + "\\ffmpeg.exe\" -i \"" + nameout2 + "\" -c copy -f flv \"" + flvfile + "\" \r\n";
1989 //if (x264ShutdownCheckBox.Checked)
1991 // x264 += "\r\n" + syspath + ":\\Windows\\System32\\shutdown -f -s -t 60";
1994 LogRecord(x264);
1995 WorkingForm wf = new WorkingForm(x264);
1996 wf.Owner = this;
1997 wf.Show();
1999 //x264 += "\r\ncmd";
2000 //batpath = workpath + "\\x264.bat";
2001 //File.WriteAllText(batpath, x264, UnicodeEncoding.Default);
2002 //System.Diagnostics.Process.Start(batpath);
2005 private void x264AddPresetBtn_Click(object sender, EventArgs e)
2007 //create directory
2008 string preset = workpath + "\\preset";
2009 if (!Directory.Exists(preset)) Directory.CreateDirectory(preset);
2010 //add file
2011 aextract = "\"" + workpath + "\\FLVExtractCL.exe\" -a \"" + namevideo8 + "\"";
2012 batpath = workpath + "\\preset\\" + PresetNameTextBox.Text + ".txt";
2013 File.WriteAllText(batpath, x264CustomParameterTextBox.Text, UnicodeEncoding.Default);
2014 //refresh combobox
2015 cbX264.Items.Clear();
2016 if (Directory.Exists(workpath + "\\preset"))
2018 DirectoryInfo TheFolder = new DirectoryInfo("preset");
2019 foreach (FileInfo FileName in TheFolder.GetFiles())
2021 cbX264.Items.Add(FileName.Name.Replace(".txt", ""));
2024 if (cbX264.Items.Count > 0) cbX264.SelectedIndex = 0;
2026 private void x264DeletePresetBtn_Click(object sender, EventArgs e)
2028 if (MessageBox.Show("确定要删除这条预设参数?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
2030 string name = batpath = workpath + "\\preset\\" + cbX264.Text + ".txt";
2031 File.Delete(name);
2032 cbX264.Items.Clear();
2033 if (Directory.Exists(workpath + "\\preset"))
2035 DirectoryInfo TheFolder = new DirectoryInfo("preset");
2036 foreach (FileInfo FileName in TheFolder.GetFiles())
2038 cbX264.Items.Add(FileName.Name.Replace(".txt", ""));
2041 if (cbX264.Items.Count > 0) cbX264.SelectedIndex = 0;
2044 private void x264Mode2RadioButton_CheckedChanged(object sender, EventArgs e)
2046 mode = 2;
2047 lbrate.Visible = true;
2048 x264BitrateNum.Visible = true;
2049 label12.Visible = true;
2050 cbFPS2.Visible = true;
2051 lbFPS2.Visible = true;
2052 lbwidth.Visible = true;
2053 lbheight.Visible = true;
2054 x264WidthNum.Visible = true;
2055 x264HeightNum.Visible = true;
2056 MaintainResolutionCheckBox.Visible = true;
2057 lbcrf.Visible = false;
2058 x264CRFNum.Visible = false;
2059 label4.Visible = false;
2060 x264CustomParameterTextBox.Visible = false;
2061 cbX264.Visible = false;
2062 x264AddPresetBtn.Visible = false;
2063 x264DeletePresetBtn.Visible = false;
2064 PresetNameTextBox.Visible = false;
2066 private void x264Mode3RadioButton_CheckedChanged(object sender, EventArgs e)
2068 mode = 0;
2069 label4.Visible = true;
2070 x264CustomParameterTextBox.Visible = true;
2071 cbX264.Visible = true;
2072 x264AddPresetBtn.Visible = true;
2073 x264DeletePresetBtn.Visible = true;
2074 PresetNameTextBox.Visible = true;
2075 lbwidth.Visible = false;
2076 lbheight.Visible = false;
2077 x264WidthNum.Visible = false;
2078 x264HeightNum.Visible = false;
2079 MaintainResolutionCheckBox.Visible = false;
2080 lbrate.Visible = false;
2081 x264BitrateNum.Visible = false;
2082 label12.Visible = false;
2083 lbcrf.Visible = false;
2084 x264CRFNum.Visible = false;
2085 cbFPS2.Visible = false;
2086 lbFPS2.Visible = false;
2088 private void x264Mode1RadioButton_CheckedChanged(object sender, EventArgs e)
2090 mode = 1;
2091 lbcrf.Visible = true;
2092 x264CRFNum.Visible = true;
2093 cbFPS2.Visible = true;
2094 lbFPS2.Visible = true;
2095 lbwidth.Visible = true;
2096 lbheight.Visible = true;
2097 x264WidthNum.Visible = true;
2098 x264HeightNum.Visible = true;
2099 MaintainResolutionCheckBox.Visible = true;
2100 lbrate.Visible = false;
2101 x264BitrateNum.Visible = false;
2102 label12.Visible = false;
2103 label4.Visible = false;
2104 x264CustomParameterTextBox.Visible = false;
2105 cbX264.Visible = false;
2106 x264AddPresetBtn.Visible = false;
2107 x264DeletePresetBtn.Visible = false;
2108 PresetNameTextBox.Visible = false;
2110 private void x264AudioModeComboBox_SelectedIndexChanged(object sender, EventArgs e)
2112 if (x264AudioModeComboBox.SelectedIndex != -1)
2114 switch (x264AudioModeComboBox.SelectedIndex)
2116 case 1:
2117 x264AudioParameterTextBox.Text = "";
2118 break;
2119 case 2:
2120 x264AudioParameterTextBox.Text = "";
2121 x264AudioParameterTextBox.EmptyTextTip = "可能失败,如出错请用FAAC";
2122 break;
2123 case 3:
2124 x264AudioParameterTextBox.Text = "";
2125 x264AudioParameterTextBox.EmptyTextTip = "把音频文件拖到这里";
2126 break;
2127 case 4:
2128 x264AudioParameterTextBox.Text = "--abitrate 128";
2129 break;
2130 case 5:
2131 x264AudioParameterTextBox.Text = "--abitrate 128";
2132 break;
2133 case 6:
2134 x264AudioParameterTextBox.Text = "";
2135 break;
2136 case 0:
2137 x264AudioParameterTextBox.Text = "";
2138 break;
2139 default:
2140 break;
2144 private void x264PriorityComboBox_SelectedIndexChanged(object sender, EventArgs e)
2146 string processName = x264ExeComboBox.Text;
2147 processName = processName.Replace(".exe", "");
2148 Process[] processes = Process.GetProcesses();
2149 //if (x264PriorityComboBox.SelectedIndex == 4 || x264PriorityComboBox.SelectedIndex == 5)
2151 // if (MessageBox.Show("优先级那么高的话会严重影响其他进程的运行速度,\r\n是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
2152 // {
2153 // x264PriorityComboBox.SelectedIndex = 2;
2154 // }
2156 //遍历电脑中的进程
2157 for (int i = 0; i < processes.GetLength(0); i++)
2159 //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
2160 if (processes[i].ProcessName.Equals(processName))
2162 switch (x264PriorityComboBox.SelectedIndex)
2164 case 0: processes[i].PriorityClass = ProcessPriorityClass.Idle; break;
2165 case 1: processes[i].PriorityClass = ProcessPriorityClass.BelowNormal; break;
2166 case 2: processes[i].PriorityClass = ProcessPriorityClass.Normal; break;
2167 case 3: processes[i].PriorityClass = ProcessPriorityClass.AboveNormal; break;
2168 case 4: processes[i].PriorityClass = ProcessPriorityClass.High; break;
2169 case 5: processes[i].PriorityClass = ProcessPriorityClass.RealTime; break;
2174 private void x264VideoTextBox_TextChanged(object sender, EventArgs e)
2176 string path = x264VideoTextBox.Text;
2177 if (File.Exists(path))
2179 namevideo2 = path;
2180 x264OutTextBox.Text = AddExt(path, "_x264.mp4");
2181 //txtsub2.Text = AddExt(path, ".ass");
2184 private void x264OutTextBox_TextChanged(object sender, EventArgs e)
2186 nameout2 = x264OutTextBox.Text;
2188 private void x264SubTextBox_TextChanged(object sender, EventArgs e)
2190 namesub2 = x264SubTextBox.Text;
2192 private void x264BatchClearBtn_Click(object sender, EventArgs e)
2194 lbAuto.Items.Clear();
2196 private void x264BatchDeleteBtn_Click(object sender, EventArgs e)
2198 if (lbAuto.Items.Count > 0)
2200 if (lbAuto.SelectedItems.Count > 0)
2202 int index = lbAuto.SelectedIndex;
2203 lbAuto.Items.RemoveAt(lbAuto.SelectedIndex);
2204 if (index == lbAuto.Items.Count)
2206 lbAuto.SelectedIndex = index - 1;
2208 if (index >= 0 && index < lbAuto.Items.Count && lbAuto.Items.Count > 0)
2210 lbAuto.SelectedIndex = index;
2215 private void x264BatchAddBtn_Click(object sender, EventArgs e)
2217 openFileDialog1.Multiselect = true;
2218 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2219 DialogResult result = openFileDialog1.ShowDialog();
2220 if (result == DialogResult.OK)
2222 lbAuto.Items.AddRange(openFileDialog1.FileNames);
2225 #endregion
2226 #region 音频界面
2227 private void AudioEncoderComboBox_SelectedIndexChanged(object sender, EventArgs e)
2229 if (File.Exists(txtaudio2.Text))
2231 if (AudioEncoderComboBox.SelectedIndex == 2)
2232 txtout3.Text = AddExt(txtaudio2.Text, "_WAV.wav");
2233 else
2234 txtout3.Text = AddExt(txtaudio2.Text, "_AAC.aac");
2237 private void AudioListBox_DragDrop(object sender, DragEventArgs e)
2239 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
2241 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
2242 foreach (String s in files)
2244 (sender as ListBox).Items.Add(s);
2247 ListBox listbox = (ListBox)sender;
2248 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
2249 if (indexoftarget != ListBox.NoMatches)
2251 string temp = listbox.Items[indexoftarget].ToString();
2252 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
2253 listbox.Items[indexofsource] = temp;
2254 listbox.SelectedIndex = indexoftarget;
2257 private void AudioListBox_DragOver(object sender, DragEventArgs e)
2259 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lbAuto))
2261 e.Effect = DragDropEffects.Move;
2263 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
2265 e.Effect = DragDropEffects.Link;
2267 else e.Effect = DragDropEffects.None;
2269 private void AudioListBox_MouseDown(object sender, MouseEventArgs e)
2271 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
2272 if (indexofsource != ListBox.NoMatches)
2274 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
2277 private void AudioBatchButton_Click(object sender, EventArgs e)
2279 if (AudioListBox.Items.Count != 0)
2281 string finish;
2282 aac = "";
2283 for (int i = 0; i < this.AudioListBox.Items.Count; i++)
2285 if (AudioEncoderComboBox.SelectedIndex == 2)
2286 finish = AddExt(AudioListBox.Items[i].ToString(), "_WAV.wav");
2287 else
2288 finish = AddExt(AudioListBox.Items[i].ToString(), "_AAC.aac");
2289 aac += audiobat(AudioListBox.Items[i].ToString(), finish);
2290 aac += "\r\n";
2292 aac += "\r\ncmd";
2293 batpath = workpath + "\\aac.bat";
2294 File.WriteAllText(batpath, aac, UnicodeEncoding.Default);
2295 LogRecord(aac);
2296 System.Diagnostics.Process.Start(batpath);
2298 else MessageBox.Show("请输入文件!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2300 private void btnaudio2_Click(object sender, EventArgs e)
2302 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2303 DialogResult result = openFileDialog1.ShowDialog();
2304 if (result == DialogResult.OK)
2306 nameaudio2 = openFileDialog1.FileName;
2307 txtaudio2.Text = nameaudio2;
2310 private void btnout3_Click(object sender, EventArgs e)
2312 SaveFileDialog savefile = new SaveFileDialog();
2313 savefile.Filter = "音频(*.aac)|*.aac";
2314 DialogResult result = savefile.ShowDialog();
2315 if (result == DialogResult.OK)
2317 nameout3 = savefile.FileName;
2318 txtout3.Text = nameout3;
2321 private void btnaac_Click(object sender, EventArgs e)
2323 if (nameaudio2 == "")
2325 MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2327 else if (nameout3 == "")
2329 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2331 else
2333 //ffmpeg = "\"" + workpath + "\\ffmpeg.exe\" -y -i \"" + nameaudio2 + "\" -f wav temp.wav";
2334 //int AACbr = 1024 * Convert.ToInt32(numq.Value.ToString());
2335 //string br = AACbr.ToString();
2336 //neroaac = "\"" + workpath + "\\neroAacEnc.exe\" -ignorelength -lc -br " + br + " -if \"temp.wav\" -of \"" + nameout3 + "\"";
2337 //aac = ffmpeg + "&&" + neroaac + "\r\ncmd";
2338 //if (cbwavtemp.Checked == false)
2340 // aac += "del temp.wav\r\ncmd";
2342 batpath = workpath + "\\aac.bat";
2343 File.WriteAllText(batpath, audiobat(nameaudio2, nameout3), UnicodeEncoding.Default);
2344 LogRecord(audiobat(nameaudio2, nameout3));
2345 System.Diagnostics.Process.Start(batpath);
2348 private void txtaudio2_TextChanged(object sender, EventArgs e)
2350 if (File.Exists(txtaudio2.Text.ToString()))
2352 nameaudio2 = txtaudio2.Text;
2353 if (AudioEncoderComboBox.SelectedIndex == 2)
2354 txtout3.Text = AddExt(txtaudio2.Text, "_WAV.wav");
2355 else
2356 txtout3.Text = AddExt(txtaudio2.Text, "_AAC.aac");
2359 private void txtout3_TextChanged(object sender, EventArgs e)
2361 nameout3 = txtout3.Text;
2363 private void txtaudio2_MouseDoubleClick(object sender, MouseEventArgs e)
2365 if (File.Exists(txtaudio2.Text.ToString()))
2367 System.Diagnostics.Process.Start(txtaudio2.Text.ToString());
2370 private void radioButton5_CheckedChanged(object sender, EventArgs e)
2372 lbaacrate.Visible = false;
2373 lbaackbps.Visible = false;
2374 AudioBitrateComboBox.Visible = false;
2375 AudioCustomParameterTextBox.Visible = true;
2377 private void radioButton4_CheckedChanged(object sender, EventArgs e)
2379 lbaacrate.Visible = true;
2380 lbaackbps.Visible = true;
2381 AudioBitrateComboBox.Visible = true;
2382 AudioCustomParameterTextBox.Visible = false;
2384 private void AudioAddButton_Click(object sender, EventArgs e)
2386 openFileDialog1.Multiselect = true;
2387 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2388 DialogResult result = openFileDialog1.ShowDialog();
2389 if (result == DialogResult.OK)
2391 AudioListBox.Items.AddRange(openFileDialog1.FileNames);
2394 private void AudioDeleteButton_Click(object sender, EventArgs e)
2396 if (AudioListBox.Items.Count > 0)
2398 if (AudioListBox.SelectedItems.Count > 0)
2400 int index = AudioListBox.SelectedIndex;
2401 AudioListBox.Items.RemoveAt(AudioListBox.SelectedIndex);
2402 if (index == AudioListBox.Items.Count)
2404 AudioListBox.SelectedIndex = index - 1;
2406 if (index >= 0 && index < AudioListBox.Items.Count && AudioListBox.Items.Count > 0)
2408 AudioListBox.SelectedIndex = index;
2413 private void AudioClearButton_Click(object sender, EventArgs e)
2415 AudioListBox.Items.Clear();
2417 #endregion
2418 #region AVS页面
2419 private void GenerateAVS()
2421 //if (Directory.Exists("avsfilter"))
2423 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
2424 // foreach (FileInfo FileName in TheFolder.GetFiles())
2425 // {
2426 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
2427 // }
2429 avsBuilder.Remove(0, avsBuilder.Length);
2430 avsBuilder.AppendLine("LoadPlugin(\"avsfilter\\VSFilter.DLL\")");
2431 if (UndotCheckBox.Checked) avsBuilder.AppendLine("LoadPlugin(\"avsfilter\\UnDot.DLL\")");
2432 avsBuilder.AppendLine("DirectShowSource(\"" + namevideo9 + "\")");
2433 avsBuilder.AppendLine("ConvertToYV12()");
2434 if (UndotCheckBox.Checked)
2435 avsBuilder.AppendLine("Undot()");
2436 if (TweakCheckBox.Checked)
2437 avsBuilder.AppendLine("Tweak(" + TweakChromaNumericUpDown.Value.ToString() + ", " + TweakSaturationNumericUpDown.Value.ToString() + ", " + TweakBrightnessNumericUpDown.Value.ToString() + ", " + TweakContrastNumericUpDown.Value.ToString() + ")");
2438 if (LevelsCheckBox.Checked)
2439 avsBuilder.AppendLine("Levels(0," + LevelsNumericUpDown.Value.ToString() + ",255,0,255)");
2440 if (LanczosResizeCheckBox.Checked)
2441 avsBuilder.AppendLine("LanczosResize(" + AVSWidthNumericUpDown.Value.ToString() + "," + AVSHeightNumericUpDown.Value.ToString() + ")");
2442 if (SharpenCheckBox.Checked)
2443 avsBuilder.AppendLine("Sharpen(" + SharpenNumericUpDown.Value.ToString() + ")");
2444 if (CropCheckBox.Checked)
2445 avsBuilder.AppendLine("Crop(" + AVSCropTextBox.Text + ")");
2446 if (AddBordersCheckBox.Checked)
2447 avsBuilder.AppendLine("AddBorders(" + AddBorders1NumericUpDown.Value.ToString() + "," + AddBorders2NumericUpDown.Value.ToString() + "," + AddBorders3NumericUpDown.Value.ToString() + "," + AddBorders4NumericUpDown.Value.ToString() + ")");
2448 if (!string.IsNullOrEmpty(txtsub9.Text))
2450 if (Path.GetExtension(namesub9) == ".idx")
2451 avsBuilder.AppendLine("vobsub(\"" + namesub9 + "\")");
2452 else
2453 avsBuilder.AppendLine("TextSub(\"" + namesub9 + "\")");
2455 if (TrimCheckBox.Checked)
2456 avsBuilder.AppendLine("Trim(" + TrimStartNumericUpDown.Value.ToString() + "," + TrimEndNumericUpDown.Value.ToString() + ")");
2457 AVSScriptTextBox.Text = avsBuilder.ToString();
2459 #region 更改AVS
2460 private void TweakCheckBox_CheckedChanged(object sender, EventArgs e)
2462 GenerateAVS();
2464 private void LanczosResizeCheckBox_CheckedChanged(object sender, EventArgs e)
2466 GenerateAVS();
2468 private void AddBordersCheckBox_CheckedChanged(object sender, EventArgs e)
2470 GenerateAVS();
2472 private void CropCheckBox_CheckedChanged(object sender, EventArgs e)
2474 GenerateAVS();
2476 private void TrimCheckBox_CheckedChanged(object sender, EventArgs e)
2478 GenerateAVS();
2480 private void LevelsCheckBox_CheckedChanged(object sender, EventArgs e)
2482 GenerateAVS();
2484 private void SharpenCheckBox_CheckedChanged(object sender, EventArgs e)
2486 GenerateAVS();
2488 private void UndotCheckBox_CheckedChanged(object sender, EventArgs e)
2490 GenerateAVS();
2492 private void TweakChromaNumericUpDown_ValueChanged(object sender, EventArgs e)
2494 GenerateAVS();
2496 private void TweakSaturationNumericUpDown_ValueChanged(object sender, EventArgs e)
2498 GenerateAVS();
2500 private void TweakBrightnessNumericUpDown_ValueChanged(object sender, EventArgs e)
2502 GenerateAVS();
2504 private void TweakContrastNumericUpDown_ValueChanged(object sender, EventArgs e)
2506 GenerateAVS();
2508 private void AVSWidthNumericUpDown_ValueChanged(object sender, EventArgs e)
2510 GenerateAVS();
2512 private void AVSHeightNumericUpDown_ValueChanged(object sender, EventArgs e)
2514 GenerateAVS();
2516 private void AddBorders1NumericUpDown_ValueChanged(object sender, EventArgs e)
2518 GenerateAVS();
2520 private void AddBorders2NumericUpDown_ValueChanged(object sender, EventArgs e)
2522 GenerateAVS();
2524 private void AddBorders3NumericUpDown_ValueChanged(object sender, EventArgs e)
2526 GenerateAVS();
2528 private void AddBorders4NumericUpDown_ValueChanged(object sender, EventArgs e)
2530 GenerateAVS();
2532 private void AVSCropTextBox_TextChanged(object sender, EventArgs e)
2534 GenerateAVS();
2536 private void TrimStartNumericUpDown_ValueChanged(object sender, EventArgs e)
2538 GenerateAVS();
2540 private void TrimEndNumericUpDown_ValueChanged(object sender, EventArgs e)
2542 GenerateAVS();
2544 private void LevelsNumericUpDown_ValueChanged(object sender, EventArgs e)
2546 GenerateAVS();
2548 private void SharpenNumericUpDown_ValueChanged(object sender, EventArgs e)
2550 GenerateAVS();
2553 #endregion
2554 #endregion
2555 private void ExtractMP4Button_Click(object sender, EventArgs e)
2557 openFileDialog1.Filter = "视频(*.mp4)|*.mp4|所有文件(*.*)|*.*";
2558 DialogResult result = openFileDialog1.ShowDialog();
2559 if (result == DialogResult.OK)
2561 namevideo = openFileDialog1.FileName;
2562 ExtractMP4TextBox.Text = namevideo;
2565 private void txtAVS_TextChanged(object sender, EventArgs e)
2567 Match m = Regex.Match(AVSScriptTextBox.Text, "ource\\(\"[a-zA-Z]:\\\\.+\\.\\w+\"");
2568 if (m.Success)
2570 string str = m.ToString();
2571 str = str.Replace("ource(\"", "");
2572 str = str.Replace("\"", "");
2573 str = AddExt(str, "_AVS.mp4");
2574 txtout9.Text = str;
2577 public void Log(string path)
2579 ProcessStartInfo start = new ProcessStartInfo(path);//设置运行的命令行文件问ping.exe文件,这个文件系统会自己找到
2580 //如果是其它exe文件,则有可能需要指定详细路径,如运行winRar.exe
2581 start.CreateNoWindow = false;//不显示dos命令行窗口
2582 start.RedirectStandardOutput = true;//
2583 start.RedirectStandardInput = true;//
2584 start.UseShellExecute = false;//是否指定操作系统外壳进程启动程序
2585 Process p = Process.Start(start);
2586 StreamReader reader = p.StandardOutput;//截取输出流
2587 string line = reader.ReadLine();//每次读取一行
2588 StringBuilder log = new StringBuilder(2000);
2589 while (!reader.EndOfStream)
2591 log.Append(line + "\r\n");
2592 line = reader.ReadLine();
2594 p.WaitForExit();//等待程序执行完退出进程
2595 File.WriteAllText(workpath + "\\log.txt", log.ToString(), UnicodeEncoding.Default);
2596 p.Close();//关闭进程
2597 reader.Close();//关闭流
2599 public void LogRecord(string log)
2601 File.AppendAllText(workpath + "\\log.txt", "===========" + DateTime.Now.ToString() + "===========\r\n" + log + "\r\n\r\n", UnicodeEncoding.Default);
2603 private void DeleteLogButton_Click(object sender, EventArgs e)
2605 if (File.Exists(workpath + "\\log.txt"))
2607 File.Delete(workpath + "\\log.txt");
2608 MessageBox.Show("已经删除日志文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
2610 else MessageBox.Show("没有找到日志文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2612 private void ViewLogButton_Click(object sender, EventArgs e)
2614 if (File.Exists(workpath + "\\log.txt"))
2616 System.Diagnostics.Process.Start(workpath + "\\log.txt");
2618 else MessageBox.Show("没有找到日志文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2620 private void x264PathButton_Click(object sender, EventArgs e)
2622 FolderBrowserDialog fbd = new FolderBrowserDialog();
2623 fbd.ShowDialog();
2624 x264PathTextBox.Text = fbd.SelectedPath;
2626 private void ExtractMP4TextBox_TextChanged(object sender, EventArgs e)
2628 namevideo = ExtractMP4TextBox.Text;
2630 private void MaintainResolutionCheckBox_CheckedChanged(object sender, EventArgs e)
2632 if (MaintainResolutionCheckBox.Checked)
2634 x264WidthNum.Value = 0;
2635 x264HeightNum.Value = 0;
2636 x264WidthNum.Enabled = false;
2637 x264HeightNum.Enabled = false;
2639 else
2641 x264WidthNum.Enabled = true;
2642 x264HeightNum.Enabled = true;
2645 #region globalization
2646 public static void SetLang(string lang, Form form, Type formType)
2648 System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
2649 if (form != null)
2651 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(formType);
2652 resources.ApplyResources(form, "$this");
2653 AppLang(form, resources);
2656 private static void AppLang(Control control, System.ComponentModel.ComponentResourceManager resources)
2658 foreach (Control c in control.Controls)
2660 resources.ApplyResources(c, c.Name);
2661 AppLang(c, resources);
2664 private void languageComboBox_SelectedIndexChanged(object sender, EventArgs e)
2666 StreamReader sr;
2667 x264Mode1RadioButton.Checked = true;
2668 AudioBitrateRadioButton.Checked = true;
2669 switch (languageComboBox.SelectedIndex)
2671 case 0:
2672 SetLang("zh-CN", this, typeof(MainForm));
2673 x264PriorityComboBox.Items.Clear();
2674 x264PriorityComboBox.Items.AddRange(new string[] { "低", "低于标准", "普通", "高于标准", "高", "实时" });
2675 x264PriorityComboBox.SelectedIndex = 2;
2676 x264VideoTextBox.EmptyTextTip = "可以把文件拖曳到这里";
2677 //x264OutTextBox.EmptyTextTip = "宽度和高度全为0即不改变分辨率";
2678 x264PathTextBox.EmptyTextTip = "字幕文件和视频文件在同一目录下且同名";
2679 //txtvideo3.EmptyTextTip = "音频参数在音频选项卡设定";
2680 ExtractMP4TextBox.EmptyTextTip = "抽取的视频或音频在原视频目录下";
2681 txtvideo8.EmptyTextTip = "抽取的视频或音频在原视频目录下";
2682 txtvideo6.EmptyTextTip = "抽取的视频或音频在原视频目录下";
2683 //load Help Text
2684 if (File.Exists(startpath + "\\help.txt"))
2686 sr = new StreamReader(startpath + "\\help.txt", System.Text.Encoding.UTF8);
2687 HelpTextBox.Text = sr.ReadToEnd();
2688 sr.Close();
2690 break;
2691 case 1:
2692 SetLang("zh-TW", this, typeof(MainForm));
2693 x264PriorityComboBox.Items.Clear();
2694 x264PriorityComboBox.Items.AddRange(new string[] { "低", "在標準以下", "標準", "在標準以上", "高", "即時" });
2695 x264PriorityComboBox.SelectedIndex = 2;
2696 x264VideoTextBox.EmptyTextTip = "可以把文件拖曳到這裡";
2697 //x264OutTextBox.EmptyTextTip = "寬度和高度全為0即不改變解析度";
2698 x264PathTextBox.EmptyTextTip = "字幕和視頻在同一資料夾下且同名";
2699 //txtvideo3.EmptyTextTip = "音頻參數需在音頻選項卡设定";
2700 ExtractMP4TextBox.EmptyTextTip = "新檔案生成在原資料夾";
2701 txtvideo8.EmptyTextTip = "新檔案生成在原資料夾";
2702 txtvideo6.EmptyTextTip = "新檔案生成在原資料夾";
2703 //load Help Text
2704 if (File.Exists(startpath + "\\help_zh_tw.txt"))
2706 sr = new StreamReader(startpath + "\\help_zh_tw.txt", System.Text.Encoding.UTF8);
2707 HelpTextBox.Text = sr.ReadToEnd();
2708 sr.Close();
2710 break;
2711 case 2:
2712 SetLang("en-US", this, typeof(MainForm));
2713 x264PriorityComboBox.Items.Clear();
2714 x264PriorityComboBox.Items.AddRange(new string[] { "Idle", "BelowNormal", "Normal", "AboveNormal", "High", "RealTime" });
2715 x264PriorityComboBox.SelectedIndex = 2;
2716 x264VideoTextBox.EmptyTextTip = "Drag file here";
2717 //x264OutTextBox.EmptyTextTip = "Both the width and height equal zero means using original resolution";
2718 x264PathTextBox.EmptyTextTip = "Subtitle and Video must be of the same name and in the same folder";
2719 //txtvideo3.EmptyTextTip = "It is necessary to set audio parameter in the Audio tab";
2720 ExtractMP4TextBox.EmptyTextTip = "New file will be created in the original folder";
2721 txtvideo8.EmptyTextTip = "New file will be created in the original folder";
2722 txtvideo6.EmptyTextTip = "New file will be created in the original folder";
2723 //load Help Text
2724 if (File.Exists(startpath + "\\help.txt"))
2726 sr = new StreamReader(startpath + "\\help.txt", System.Text.Encoding.UTF8);
2727 HelpTextBox.Text = sr.ReadToEnd();
2728 sr.Close();
2730 break;
2731 case 3:
2732 SetLang("ja-JP", this, typeof(MainForm));
2733 x264PriorityComboBox.Items.Clear();
2734 x264PriorityComboBox.Items.AddRange(new string[] { "低", "通常以下", "通常", "通常以上", "高", "リアルタイム" });
2735 x264PriorityComboBox.SelectedIndex = 2;
2736 x264VideoTextBox.EmptyTextTip = "ビデオファイルをここに引きずってください";
2737 //x264OutTextBox.EmptyTextTip = "Both the width and height equal zero means using original resolution";
2738 x264PathTextBox.EmptyTextTip = "字幕とビデオは同じ名前と同じフォルダにある必要があります";
2739 //txtvideo3.EmptyTextTip = "It is necessary to set audio parameter in the Audio tab";
2740 ExtractMP4TextBox.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
2741 txtvideo8.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
2742 txtvideo6.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
2743 break;
2744 default:
2745 SetLang("zh-CN", this, typeof(MainForm));
2746 break;
2749 #endregion
2750 public static void RunProcess(string exe, string arg)
2752 Thread thread = new Thread(() =>
2754 ProcessStartInfo psi = new ProcessStartInfo(exe, arg);
2755 psi.CreateNoWindow = true;
2756 Process p = new Process();
2757 p.StartInfo = psi;
2758 p.Start();
2759 p.WaitForExit();
2760 MessageBox.Show("ts");
2761 p.Close();
2763 thread.IsBackground = true;
2764 thread.Start();
2766 private void DonateButton_Click(object sender, EventArgs e)
2768 System.Diagnostics.Process.Start("https://me.alipay.com/marukochan");
2770 private void AVSSaveButton_Click(object sender, EventArgs e)
2772 SaveFileDialog savefile = new SaveFileDialog();
2773 savefile.Filter = "AVS(*.avs)|*.avs";
2774 DialogResult result = savefile.ShowDialog();
2775 if (result == DialogResult.OK)
2777 File.WriteAllText(savefile.FileName, AVSScriptTextBox.Text, UnicodeEncoding.Default);
2780 private void MuxReplaceAudioButton_Click(object sender, EventArgs e)
2782 if (namevideo == "")
2784 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2785 return;
2787 if (nameaudio == "")
2789 MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2790 return;
2792 if (nameout == "")
2794 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2795 return;
2797 mux = "";
2798 mux = "\"" + workpath + "\\ffmpeg.exe\" -y -i \"" + namevideo + "\" -vcodec copy -an \"" + workpath + "\\video_noaudio.mp4\" \r\n";
2799 mux += "\"" + workpath + "\\ffmpeg.exe\" -y -i \"" + workpath + "\\video_noaudio.mp4\" -i \"" + nameaudio + "\" -vcodec copy -acodec copy \"" + nameout + "\" \r\n";
2800 mux += "del \"" + workpath + "\\video_noaudio.mp4\" \r\n";
2801 batpath = workpath + "\\mux.bat";
2802 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
2803 LogRecord(mux);
2804 Process.Start(batpath);
2806 private void cbx264file_SelectedIndexChanged(object sender, EventArgs e)
2808 if (x264ExeComboBox.Text.Contains("all"))
2810 x264AudioModeComboBox.Items.Clear();
2811 x264AudioModeComboBox.Items.Add("默认");
2812 x264AudioModeComboBox.Items.Add("无音频流");
2813 x264AudioModeComboBox.Items.Add("复制音频流");
2814 x264AudioModeComboBox.Items.Add("外置音频流");
2815 x264AudioModeComboBox.SelectedIndex = 1;
2817 else
2819 x264AudioModeComboBox.Items.Clear();
2820 x264AudioModeComboBox.Items.Add("默认");
2821 x264AudioModeComboBox.Items.Add("无音频流");
2822 x264AudioModeComboBox.Items.Add("复制音频流");
2823 x264AudioModeComboBox.Items.Add("外置音频流");
2824 x264AudioModeComboBox.Items.Add("QTAAC");
2825 x264AudioModeComboBox.Items.Add("FAAC");
2826 x264AudioModeComboBox.SelectedIndex = 5;
2830 #region 一图流
2832 private void AudioPicButton_Click(object sender, EventArgs e)
2834 openFileDialog1.Filter = "图片(*.jpg;*.jpeg;*.png;*.bmp;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件(*.*)|*.*";
2835 DialogResult result = openFileDialog1.ShowDialog();
2836 if (result == DialogResult.OK)
2838 AudioPicTextBox.Text = openFileDialog1.FileName;
2841 private void AudioPicAudioButton_Click(object sender, EventArgs e)
2843 openFileDialog1.Filter = "音频(*.aac;*.mp3;*.mp4;*.wav)|*.aac;*.mp3;*.mp4;*.wav|所有文件(*.*)|*.*";
2844 DialogResult result = openFileDialog1.ShowDialog();
2845 if (result == DialogResult.OK)
2847 AudioPicAudioTextBox.Text = openFileDialog1.FileName;
2850 private void AudioOnePicOutputButton_Click(object sender, EventArgs e)
2852 SaveFileDialog savefile = new SaveFileDialog();
2853 savefile.Filter = "MP4视频(*.mp4)|*.mp4|FLV视频(*.flv)|*.flv";
2854 savefile.FileName = "Single";
2855 DialogResult result = savefile.ShowDialog();
2856 if (result == DialogResult.OK)
2858 AudioOnePicOutputTextBox.Text = savefile.FileName;
2861 public int SecondsFromHHMMSS(string hhmmss)
2863 int hh = int.Parse(hhmmss.Substring(0, 2));
2864 int mm = int.Parse(hhmmss.Substring(3, 2));
2865 int ss = int.Parse(hhmmss.Substring(6, 2));
2866 return hh * 3600 + mm * 60 + ss;
2868 private void AudioOnePicButton_Click(object sender, EventArgs e)
2870 if (!File.Exists(AudioPicTextBox.Text))
2872 MessageBox.Show("请选择图片文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2874 else if (!File.Exists(AudioPicAudioTextBox.Text))
2876 MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2878 else if (AudioOnePicOutputTextBox.Text == "")
2880 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2882 else
2884 System.Drawing.Image img = System.Drawing.Image.FromFile(AudioPicTextBox.Text);
2885 int sourceWidth = img.Width;
2886 int sourceHeight = img.Height;
2887 if (img.Width % 2 != 0 || img.Height % 2 != 0)
2889 MessageBox.Show("图片的长和宽必须是偶数。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2890 img.Dispose();
2891 return;
2893 if (img.RawFormat.Equals(ImageFormat.Jpeg))
2895 File.Copy(AudioPicTextBox.Text, tempPic, true);
2897 else
2899 System.Drawing.Imaging.Encoder ImageEncoder = System.Drawing.Imaging.Encoder.Quality;
2900 EncoderParameter ep = new EncoderParameter(ImageEncoder, 100L);
2901 EncoderParameters eps = new EncoderParameters(1);
2902 ImageCodecInfo ImageCoderType = getImageCoderInfo("image/jpeg");
2903 eps.Param[0] = ep;
2904 img.Save(tempPic, ImageCoderType, eps);
2905 //img.Save(tempPic, ImageFormat.Jpeg);
2907 //获得音频时长
2908 MediaInfo MI = new MediaInfo();
2909 MI.Open(AudioPicAudioTextBox.Text);
2910 int seconds = SecondsFromHHMMSS(MI.Get(StreamKind.General, 0, "Duration/String3"));
2911 if (AudioCopyCheckBox.Checked)
2913 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";
2914 mux += "ffmpeg -i SinglePictureVideo.mp4 -i \"" + AudioPicAudioTextBox.Text + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
2915 mux += "del SinglePictureVideo.mp4\r\n";
2917 else
2919 mux = "ffmpeg -i \"" + AudioPicAudioTextBox.Text + "\" -f wav - |neroaacenc -br " + OnePicAudioBitrateNum.Value.ToString() + "000 -ignorelength -if - -of audio.mp4 -lc\r\n";
2920 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";
2921 mux += "ffmpeg -i SinglePictureVideo.mp4 -i audio.mp4 -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
2922 mux += "del SinglePictureVideo.mp4\r\ndel audio.mp4\r\n";
2925 string audioPath = AddExt(Path.GetFileName(AudioPicAudioTextBox.Text), "_atmp.mp4");
2926 string videoPath = AddExt(Path.GetFileName(AudioPicAudioTextBox.Text), "_vtmp.mp4");
2927 string picturePath = "c:\\" + Path.GetFileNameWithoutExtension(AudioPicTextBox.Text) + "_tmp.jpg";
2928 if (AudioCopyCheckBox.Checked)
2930 mux = "ffmpeg -loop 1 -r " + AudioOnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + picturePath + "\" -vcodec libx264 -crf 24 -y \"" + videoPath + "\"\r\n";
2931 mux += "ffmpeg -i \"" + videoPath + "\" -i \"" + AudioPicAudioTextBox.Text + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
2932 mux += "del \"" + videoPath + "\"\r\ndel \"" + picturePath + "\"\r\n";
2934 else
2936 mux = "ffmpeg -i \"" + AudioPicAudioTextBox.Text + "\" -f wav - |neroaacenc -br " + AudioOnePicAudioBitrateNum.Value.ToString() + "000 -ignorelength -if - -of \"" + audioPath + "\" -lc\r\n";
2937 mux += "ffmpeg -loop 1 -r " + AudioOnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + picturePath + "\" -vcodec libx264 -crf 24 -y \"" + videoPath + "\"\r\n";
2938 mux += "ffmpeg -i \"" + videoPath + "\" -i \"" + audioPath + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
2939 mux += "del \"" + videoPath + "\"\r\ndel \"" + audioPath + "\"\r\ndel \"" + picturePath + "\"\r\n";
2942 batpath = Path.Combine(workpath, Path.GetRandomFileName() + ".bat");
2943 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
2944 LogRecord(mux);
2945 Process.Start(batpath);
2948 private void txtMI_DragDrop(object sender, DragEventArgs e)
2950 MIvideo = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
2951 MediaInfoTextBox.Text = MediaInfo(MIvideo);
2953 private void txtMI_DragEnter(object sender, DragEventArgs e)
2955 if (e.Data.GetDataPresent(DataFormats.FileDrop))
2956 e.Effect = DragDropEffects.Link;
2957 else e.Effect = DragDropEffects.None;
2959 private void AudioPicAudioTextBox_TextChanged(object sender, EventArgs e)
2961 if (File.Exists(AudioPicAudioTextBox.Text.ToString()))
2963 AudioOnePicOutputTextBox.Text = AddExt(AudioPicAudioTextBox.Text, "_SP.flv");
2966 /// <summary>
2967 /// 获取图片编码类型信息
2968 /// </summary>
2969 /// <param name="ImageCoderType">编码类型</param>
2970 /// <returns>ImageCodecInfo</returns>
2971 private ImageCodecInfo getImageCoderInfo(string ImageCoderType)
2973 ImageCodecInfo[] coderTypeArray = ImageCodecInfo.GetImageEncoders();
2974 foreach (ImageCodecInfo coderType in coderTypeArray)
2976 if (coderType.MimeType.Equals(ImageCoderType))
2977 return coderType;
2979 return null;
2982 #endregion
2985 #region 后黑
2987 private void BlackVideoButton_Click(object sender, EventArgs e)
2989 openFileDialog1.Filter = "FLV视频(*.flv)|*.flv";
2990 DialogResult result = openFileDialog1.ShowDialog();
2991 if (result == DialogResult.OK)
2993 BlackVideoTextBox.Text = openFileDialog1.FileName;
2997 private void BlackOutputButton_Click(object sender, EventArgs e)
2999 SaveFileDialog savefile = new SaveFileDialog();
3000 savefile.Filter = "FLV视频(*.flv)|*.flv";
3001 DialogResult result = savefile.ShowDialog();
3002 if (result == DialogResult.OK)
3004 BlackOutputTextBox.Text = savefile.FileName;
3008 private void BlackPicButton_Click(object sender, EventArgs e)
3010 openFileDialog1.Filter = "图片(*.jpg;*.jpeg;*.png;*.bmp;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件(*.*)|*.*";
3011 DialogResult result = openFileDialog1.ShowDialog();
3012 if (result == DialogResult.OK)
3014 BlackPicTextBox.Text = openFileDialog1.FileName;
3018 private void BlackStartButton_Click(object sender, EventArgs e)
3020 string videoname = BlackVideoTextBox.Text;
3021 MediaInfo MI = new MediaInfo();
3022 MI.Open(videoname);
3023 double videobitrate = double.Parse(MI.Get(StreamKind.General, 0, "BitRate"));
3024 double targetBitrate = (double)BlackBitrateNum.Value;
3026 //验证
3027 if (!File.Exists(BlackVideoTextBox.Text) || Path.GetExtension(BlackVideoTextBox.Text) != ".flv")
3029 MessageBox.Show("请选择FLV视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3030 return;
3032 if (!File.Exists(BlackPicTextBox.Text) && BlackNoPicCheckBox.Checked == false)
3034 MessageBox.Show("请选择图片文件或勾选使用黑屏", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3035 return;
3037 if (BlackOutputTextBox.Text == "")
3039 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3040 return;
3043 if (videobitrate < 1000000)
3045 MessageBox.Show("此视频不需要后黑。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
3046 return;
3048 if (videobitrate > 2500000)
3050 MessageBox.Show("此视频码率过大,请先压制再后黑。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
3051 return;
3055 //处理图片
3056 int videoWidth = int.Parse(MI.Get(StreamKind.Video, 0, "Width"));
3057 int videoHeight = int.Parse(MI.Get(StreamKind.Video, 0, "Height"));
3058 if (BlackNoPicCheckBox.Checked)
3060 Bitmap bm = new Bitmap(videoWidth, videoHeight);
3061 Graphics g = Graphics.FromImage(bm);
3062 //g.FillRectangle(Brushes.White, new Rectangle(0, 0, 800, 600));
3063 g.Clear(Color.Black);
3064 bm.Save(tempPic, ImageFormat.Jpeg);
3065 g.Dispose();
3066 bm.Dispose();
3068 else
3070 System.Drawing.Image img = System.Drawing.Image.FromFile(BlackPicTextBox.Text);
3071 int sourceWidth = img.Width;
3072 int sourceHeight = img.Height;
3073 if (img.Width % 2 != 0 || img.Height % 2 != 0)
3075 MessageBox.Show("图片的长和宽必须都是偶数。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3076 img.Dispose();
3077 return;
3079 if (img.Width != videoWidth || img.Height != videoHeight)
3081 MessageBox.Show("图片的长和宽和视频不一致。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3082 img.Dispose();
3083 return;
3085 if (img.RawFormat.Equals(ImageFormat.Jpeg))
3087 File.Copy(BlackPicTextBox.Text, tempPic, true);
3089 else
3091 System.Drawing.Imaging.Encoder ImageEncoder = System.Drawing.Imaging.Encoder.Quality;
3092 EncoderParameter ep = new EncoderParameter(ImageEncoder, 100L);
3093 EncoderParameters eps = new EncoderParameters(1);
3094 ImageCodecInfo ImageCoderType = getImageCoderInfo("image/jpeg");
3095 eps.Param[0] = ep;
3096 img.Save(tempPic, ImageCoderType, eps);
3097 //img.Save(tempPic, ImageFormat.Jpeg);
3100 int blackSecond = 300;
3101 //计算后黑时长
3102 if (BlackSecondComboBox.Text == "auto")
3104 int seconds = SecondsFromHHMMSS(MI.Get(StreamKind.General, 0, "Duration/String3"));
3105 double s = videobitrate / 1000.0 * (double)seconds / targetBitrate - (double)seconds;
3106 blackSecond = (int)s;
3107 BlackSecondComboBox.Text = blackSecond.ToString();
3109 else
3111 blackSecond = int.Parse(Regex.Replace(BlackSecondComboBox.Text.ToString(), @"\D", "")); //排除除数字外的所有字符
3114 //批处理
3115 mux = "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";
3116 mux += string.Format("flvbind \"{0}\" \"{1}\" black.flv\r\n", BlackOutputTextBox.Text, BlackVideoTextBox.Text);
3117 mux += "del black.flv\r\n";
3119 batpath = Path.Combine(workpath, Path.GetRandomFileName() + ".bat");
3120 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
3121 LogRecord(mux);
3122 Process.Start(batpath);
3125 private void BlackVideoTextBox_TextChanged(object sender, EventArgs e)
3127 string path = BlackVideoTextBox.Text;
3128 if (File.Exists(path))
3130 BlackOutputTextBox.Text = AddExt(path, "_black.flv");
3133 #endregion
3135 private void BlackNoPicCheckBox_CheckedChanged(object sender, EventArgs e)
3137 BlackPicTextBox.Enabled = !BlackNoPicCheckBox.Checked;
3138 BlackPicButton.Enabled = !BlackNoPicCheckBox.Checked;
3141 private void BlackSecondComboBox_SelectedIndexChanged(object sender, EventArgs e)
3143 if (BlackSecondComboBox.Text != "auto")
3145 BlackBitrateNum.Enabled = false;
3147 else
3149 BlackBitrateNum.Enabled = true;
3153 private void SetDefaultButton_Click(object sender, EventArgs e)
3155 InitParameter();
3158 //Ctrl+A 可以全选文本
3159 private void MediaInfoTextBox_KeyDown(object sender, KeyEventArgs e)
3161 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
3163 ((TextBox)sender).SelectAll();
3167 private void AVSScriptTextBox_KeyDown(object sender, KeyEventArgs e)
3169 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
3171 ((TextBox)sender).SelectAll();
3175 private void x264CustomParameterTextBox_KeyDown(object sender, KeyEventArgs e)
3177 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
3179 ((TextBox)sender).SelectAll();
3183 private void CheckUpdateButton_Click(object sender, EventArgs e)
3185 WebRequest request = WebRequest.Create("http://hi.baidu.com/xiaowanmaruko/item/119203f757097c603c148502");
3186 request.Credentials = CredentialCache.DefaultCredentials;
3187 // Get the response.
3188 request.BeginGetResponse(new AsyncCallback(OnResponse), request);
3191 protected void OnResponse(IAsyncResult ar)
3193 WebRequest wrq = (WebRequest)ar.AsyncState;
3194 WebResponse wrs = wrq.EndGetResponse(ar);
3195 // read the response ...
3196 Stream dataStream = wrs.GetResponseStream();
3197 // Open the stream using a StreamReader for easy access.
3198 StreamReader reader = new StreamReader(dataStream);
3199 // Read the content.
3200 string responseFromServer = reader.ReadToEnd();
3201 Regex reg = new Regex(@"Maruko20\S+Maruko");
3202 Match m = reg.Match(responseFromServer);
3203 if (m.Success)
3205 string a = m.Value.Replace("Maruko", "");
3206 DateTime NewDate = DateTime.Parse(a);
3207 //DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
3208 int s = DateTime.Compare(NewDate, ReleaseDate);
3209 if (s == 1) //NewDate is later than ReleaseDate
3211 DialogResult dr = MessageBox.Show(string.Format("新鲜小丸已于{0}上架,主人不来尝一口咩?", NewDate.ToString("yyyy-M-d")), "Info", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
3212 if (dr == DialogResult.Yes)
3214 Process.Start("http://maruko.appinn.me");
3216 else
3218 return;
3221 else
3223 MessageBox.Show("喵~伦家已经是最新版啦!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
3228 private void x264ShutdownCheckBox_CheckedChanged(object sender, EventArgs e)
3230 shutdownState = x264ShutdownCheckBox.Checked;