Add NotifyIcon for WorkingForm. Fix workPath in WorkingForm..
[marukotoolbox.git] / mp4box / MainForm.cs
blobb71ee10da33d4ded24a09351e3dc554c3567756a
1 using System.Collections.Generic;
2 using System.ComponentModel;
3 using System.Data;
4 using System.Drawing;
5 using System.Text;
6 using System.Windows.Forms;
7 using System.IO;
8 using System.Diagnostics;
9 using MediaInfoLib;
10 using System.Runtime.InteropServices;
11 using System.Text.RegularExpressions;
12 using System;
13 using ControlExs;
14 using System.Globalization;
15 using System.Threading;
16 using System.Configuration;
17 using System.Drawing.Imaging;
18 using System.Net;
19 namespace mp4box
21 public partial class MainForm : Form
24 #region Private Members Declaration
26 StringBuilder avsBuilder = new StringBuilder(1000);
27 string syspath = Environment.GetFolderPath(Environment.SpecialFolder.System).Remove(1);
28 int indexofsource;
29 int indexoftarget;
30 byte mode = 1;
31 string clip = "";
32 string MIvideo = "";
33 string namevideo = "";
34 string namevideo2 = "";
35 //string namevideo3 = "";
36 string namevideo4 = "";
37 string namevideo5 = "";
38 string namevideo6 = "";
39 string nameaudio = "";
40 string nameaudio2 = "";
41 string nameaudio3 = "";
42 string namevideo8 = "";
43 string namevideo9 = "video";
44 string nameout;
45 string nameout2;
46 string nameout3;
47 //string nameout4;
48 string nameout5;
49 string nameout6;
50 string nameout9;
51 string namesub;
52 string namesub2 = "";
53 string namesub9 = "subtitle";
54 string MItext = "把视频文件拖到这里";
55 string mkvextract;
56 string mkvmerge;
57 string mux;
58 string x264;
59 string ffmpeg;
60 string neroaac;
61 string aac;
62 string aextract;
63 string vextract;
64 string batpath;
65 string auto;
66 string startpath;
67 string avs = "";
68 string tempavspath = "";
69 string tempPic = "";
70 DateTime ReleaseDate = DateTime.Parse("2014-4-14");
72 #endregion
74 public string workPath = "!undefined";
75 public bool shutdownState = false;
76 public bool trayMode = false;
78 [StructLayout(LayoutKind.Sequential)]
79 public struct MARGINS
81 public int Left;
82 public int Right;
83 public int Top;
84 public int Bottom;
86 [DllImport("dwmapi.dll", PreserveSig = false)]
87 static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
88 [DllImport("dwmapi.dll", PreserveSig = false)]
89 static extern bool DwmIsCompositionEnabled();
90 public MainForm()
92 InitializeComponent();
94 public string MediaInfo(string VideoName)
96 string info = "无视频信息";
97 if (File.Exists(VideoName))
99 MediaInfo MI = new MediaInfo();
100 MI.Open(VideoName);
101 //全局
102 string container = MI.Get(StreamKind.General, 0, "Format");
103 string bitrate = MI.Get(StreamKind.General, 0, "BitRate/String");
104 string duration = MI.Get(StreamKind.General, 0, "Duration/String1");
105 string fileSize = MI.Get(StreamKind.General, 0, "FileSize/String");
106 //视频
107 string vid = MI.Get(StreamKind.Video, 0, "ID");
108 string video = MI.Get(StreamKind.Video, 0, "Format");
109 string vBitRate = MI.Get(StreamKind.Video, 0, "BitRate/String");
110 string vSize = MI.Get(StreamKind.Video, 0, "StreamSize/String");
111 string width = MI.Get(StreamKind.Video, 0, "Width");
112 string height = MI.Get(StreamKind.Video, 0, "Height");
113 string risplayAspectRatio = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio/String");
114 string risplayAspectRatio2 = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio");
115 string frameRate = MI.Get(StreamKind.Video, 0, "FrameRate/String");
116 string bitDepth = MI.Get(StreamKind.Video, 0, "BitDepth/String");
117 string pixelAspectRatio = MI.Get(StreamKind.Video, 0, "PixelAspectRatio");
118 string encodedLibrary = MI.Get(StreamKind.Video, 0, "Encoded_Library");
119 string encodeTime = MI.Get(StreamKind.Video, 0, "Encoded_Date");
120 string codecProfile = MI.Get(StreamKind.Video, 0, "Codec_Profile");
121 string frameCount = MI.Get(StreamKind.Video, 0, "FrameCount");
123 //音频
124 string aid = MI.Get(StreamKind.Audio, 0, "ID");
125 string audio = MI.Get(StreamKind.Audio, 0, "Format");
126 string aBitRate = MI.Get(StreamKind.Audio, 0, "BitRate/String");
127 string samplingRate = MI.Get(StreamKind.Audio, 0, "SamplingRate/String");
128 string channel = MI.Get(StreamKind.Audio, 0, "Channel(s)");
129 string aSize = MI.Get(StreamKind.Audio, 0, "StreamSize/String");
130 info = Path.GetFileName(VideoName) + "\r\n" +
131 "容器:" + container + "\r\n" +
132 "总码率:" + bitrate + "\r\n" +
133 "大小:" + fileSize + "\r\n" +
134 "时长:" + duration + "\r\n" +
135 "\r\n" +
136 "视频(" + vid + "):" + video + "\r\n" +
137 "码率:" + vBitRate + "\r\n" +
138 "大小:" + vSize + "\r\n" +
139 "分辨率:" + width + "x" + height + "\r\n" +
140 "宽高比:" + risplayAspectRatio + "(" + risplayAspectRatio2 + ")" + "\r\n" +
141 "帧率:" + frameRate + "\r\n" +
142 "位深度:" + bitDepth + "\r\n" +
143 "像素宽高比:" + pixelAspectRatio + "\r\n" +
144 "编码库:" + encodedLibrary + "\r\n" +
145 "Profile:" + codecProfile + "\r\n" +
146 "编码时间:" + encodeTime + "\r\n" +
147 "总帧数:" + frameCount + "\r\n" +
149 "\r\n" +
150 "音频(" + aid + "):" + audio + "\r\n" +
151 "大小:" + aSize + "\r\n" +
152 "码率:" + aBitRate + "\r\n" +
153 "采样率:" + samplingRate + "\r\n" +
154 "声道数:" + channel + "\r\n";
155 MI.Close();
157 return info;
159 public string AddExt(string name, string ext)
161 string finish = name.Remove(name.LastIndexOf("."));
162 finish += ext;
163 return finish;
165 public string muxbat(string input1, string input2, string fps, string output)
167 mux = "\"" + workPath + "\\mp4box.exe\" -fps " + fps + " -add " + input1 + " -add " + input2 + " -new \"" + output + "\"";
168 return mux;
170 public string muxbat(string input1, string input2, string output)
172 mux = "\"" + workPath + "\\mp4box.exe\" -add " + input1 + " -add " + input2 + " -new \"" + output + "\"";
173 return mux;
175 public string x264bat(string input, string output)
177 switch (mode)
179 case 1:
180 if (x264HeightNum.Value == 0 || x264WidthNum.Value == 0 || MaintainResolutionCheckBox.Checked)
182 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";
184 else
186 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";
188 break;
189 case 2:
190 if (x264HeightNum.Value == 0 || x264WidthNum.Value == 0 || MaintainResolutionCheckBox.Checked)
192 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";
194 else
196 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";
198 break;
199 case 0:
200 x264 = "\"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" " + x264CustomParameterTextBox.Text + " --demuxer " + x264DemuxerComboBox.Text + " -o \"" + output + "\" \"" + input + "\"\r\n";
201 break;
203 return x264;
205 //public string x264bat(string input, string output)
207 // switch (mode)
208 // {
209 // case 1:
210 // if (numheight.Value == 0 || numwidth.Value == 0)
211 // {
212 // 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";
213 // }
214 // else
215 // {
216 // 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";
217 // }
218 // break;
219 // case 2:
220 // if (numheight.Value == 0 || numwidth.Value == 0)
221 // {
222 // 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";
223 // }
224 // else
225 // {
226 // 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";
227 // }
228 // break;
229 // case 0:
230 // x264 = "\"" + workpath + "\\x264.exe\" " + txth264.Text + " -o \"" + output + "\" \"" + input + "\"\r\n";
231 // break;
232 // }
233 // return x264;
235 public string timeminus(int h1, int m1, int s1, int h2, int m2, int s2)
237 int h = 0;
238 int m = 0;
239 int s = 0;
240 s = s2 - s1;
241 if (s < 0)
243 m = -1;
244 s = s + 60;
246 m = m + m2 - m1;
247 if (m < 0)
249 h = -1;
250 m = m + 60;
252 h = h + h2 - h1;
253 return h.ToString() + ":" + m.ToString() + ":" + s.ToString();
255 public string timeplus(int h1, int m1, int s1, int h2, int m2, int s2)
257 int h = 0;
258 int m = 0;
259 int s = 0;
260 s = s1 + s2;
261 if (s >= 60)
263 m = 1;
264 s = s - 60;
266 m = m + m1 + m2;
267 if (m >= 60)
269 h = 1;
270 m = m - 60;
272 h = h + h1 + h2;
273 return h.ToString() + ":" + m.ToString() + ":" + s.ToString();
275 public string audiobat(string input, string output)
277 int AACbr = 1024 * Convert.ToInt32(AudioBitrateComboBox.Text);
278 string br = AACbr.ToString();
279 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + input + "\" -f wav temp.wav";
280 switch (AudioEncoderComboBox.SelectedIndex)
282 case 0:
283 if (AudioBitrateRadioButton.Checked)
285 neroaac = "\"" + workPath + "\\neroAacEnc.exe\" -ignorelength -lc -br " + br + " -if \"temp.wav\" -of \"" + output + "\"";
287 if (AudioCustomizeRadioButton.Checked)
289 neroaac = "\"" + workPath + "\\neroAacEnc.exe\" " + AudioCustomParameterTextBox.Text.ToString() + " -if \"temp.wav\" -of \"" + output + "\"";
291 break;
292 case 1:
293 if (AudioBitrateRadioButton.Checked)
295 neroaac = "\"" + workPath + "\\qaac.exe\" -q 2 -c " + AudioBitrateComboBox.Text + " \"temp.wav\" -o \"" + output + "\"";
297 if (AudioCustomizeRadioButton.Checked)
299 neroaac = "\"" + workPath + "\\qaac.exe\" " + AudioCustomParameterTextBox.Text.ToString() + " \"temp.wav\" -o \"" + output + "\"";
301 break;
302 case 2:
303 if (Path.GetExtension(output) == ".aac")
304 output = AddExt(output, ".wav");
305 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + input + "\" -f wav \"" + output + "\"";
306 neroaac = "";
308 break;
309 default:
310 break;
312 aac = ffmpeg + "\r\n" + neroaac + "\r\n";
313 if (cbwavtemp.Checked == false)
315 aac += "del temp.wav\r\n";
317 return aac;
319 public void oneAuto(string video, string output)
321 x264 = x264bat(video, "temp.mp4");
322 x264 = x264.Replace("\r\n", "");
323 if (x264SubTextBox.Text != "")
325 if (x264.IndexOf("--vf") == -1)
327 x264 += " --vf subtitles --sub \"" + namesub2 + "\"";
329 else
331 Regex r = new Regex("--vf\\s\\S*");
332 Match m = r.Match(x264);
333 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles");
334 x264 += " --sub \"" + namesub2 + "\"";
337 x264 += " --acodec none\r\n";
338 //audio
339 //如果是avs
340 if (video.Substring(video.LastIndexOf(".") + 1) == "avs")
342 aextract = "\r\n";
343 //string nameavs = namevideo3;
344 //int a, b;
345 //StreamReader sr = new StreamReader(namevideo3, System.Text.Encoding.Default);
346 //string str = sr.ReadToEnd();
347 //a = str.IndexOf("DirectShowSource(\"");
348 //if (a == -1)
350 // a = str.IndexOf("FFVideoSource(\"");
351 // b = str.IndexOf("\"", a + 15);
352 // namevideo3 = str.Substring(a + 15, b - a - 15);
354 //else
356 // b = str.IndexOf("\"", a + 18);
357 // namevideo3 = str.Substring(a + 18, b - a - 18);
359 //if (namevideo3.IndexOf(":") != 1)
361 // namevideo3 = nameavs.Substring(0, nameavs.LastIndexOf("\\") + 1) + namevideo3;
364 else
366 aextract = audiobat(video, "temp.aac");
368 //mux
369 mux = muxbat("temp.mp4", "temp.aac", cbFPS.Text, output);
370 //if (cbDelTmp.Checked == false)
372 // auto = aextract + x264 + mux + " \r\ndel temp.aac\r\ndel temp.mp4\r\ndel temp.wav\r\n";
374 //else
376 auto = aextract + x264 + mux + " \r\n\r\n";
378 if (x264FLVCheckBox.Checked == true)
380 string flvfile = AddExt(output, "_FLV.flv");
381 auto += "\r\n\"" + workPath + "\\ffmpeg.exe\" -i \"" + output + "\" -c copy -f flv \"" + flvfile + "\" \r\n";
383 //if (x264ShutdownCheckBox.Checked)
385 // auto += "\r\n" + syspath + ":\\Windows\\System32\\shutdown -f -s -t 60\r\n";
387 //auto += "cmd";
389 public void batchAuto()
391 int i;
392 auto = "";
393 for (i = 0; i < this.lbAuto.Items.Count; i++)
395 x264 = x264bat(lbAuto.Items[i].ToString(), "temp.mp4");
396 x264 = x264.Replace("\r\n", "");
397 //判断是否内嵌字幕
398 string sub = "";
399 string asssub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".ass";
400 string ssasub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".ssa";
401 string srtsub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".srt";
402 if (x264BatchSubCheckBox.Checked)
404 if (File.Exists(asssub))
406 sub = asssub;
408 else if (File.Exists(ssasub))
410 sub = ssasub;
412 else if (File.Exists(srtsub))
414 sub = srtsub;
416 if (sub != "")
418 if (x264.IndexOf("--vf") == -1)
420 x264 += " --vf subtitles --sub \"" + sub + "\"";
422 else
424 Regex r = new Regex("--vf\\s\\S*");
425 Match m = r.Match(x264);
426 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles");
427 x264 += " --sub \"" + sub + "\"";
431 x264 += " --acodec none\r\n";
432 //audio
433 //如果是avs
434 if (lbAuto.Items[i].ToString().Substring(lbAuto.Items[i].ToString().LastIndexOf(".") + 1) == "avs")
436 aextract = "\r\n";
437 //string tempvideoname;
438 //int a, b;
439 //StreamReader sr = new StreamReader(lbAuto.Items[i].ToString(), System.Text.Encoding.Default);
440 //string str = sr.ReadToEnd();
441 //a = str.IndexOf("DirectShowSource(\"");
442 //if (a == -1)
444 // a = str.IndexOf("FFVideoSource(\"");
445 // b = str.IndexOf("\"", a + 15);
446 // tempvideoname = str.Substring(a + 15, b - a - 15);
448 //else
450 // b = str.IndexOf("\"", a + 18);
451 // tempvideoname = str.Substring(a + 18, b - a - 18);
453 //if (tempvideoname.IndexOf(":") != 1)
455 // tempvideoname = lbAuto.Items[i].ToString().Substring(0, lbAuto.Items[i].ToString().LastIndexOf("\\") + 1) + tempvideoname;
457 //aextract = audiobat(tempvideoname, "temp.aac");
458 //ffmpeg = "\"" + workpath + "\\ffmpeg.exe\" -y -i \"" + tempvideoname + "\" -f wav temp.wav";
460 else //如果不是avs
462 aextract = audiobat(lbAuto.Items[i].ToString(), "temp.aac");
464 //mux
465 string finish;
466 if (Directory.Exists(x264PathTextBox.Text))
467 finish = x264PathTextBox.Text + "\\" + Path.GetFileNameWithoutExtension(lbAuto.Items[i].ToString()) + "_onekeybatch.mp4";
468 else
469 finish = AddExt(lbAuto.Items[i].ToString(), "_onekeybatch.mp4");
470 mux = muxbat("temp.mp4", "temp.aac", finish);
471 //mux = "\"" + workpath + "\\mp4box.exe\" -add temp.mp4 -add temp.aac -new \"" + finish + "\"";
472 auto += aextract + x264 + mux + " \r\ndel temp.aac\r\ndel temp.mp4\r\ndel temp.wav\r\n";
473 //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";
476 //if (x264ShutdownCheckBox.Checked)
478 // auto += "\r\n" + syspath + ":\\Windows\\System32\\shutdown -f -s -t 60";
481 public void batchAuto2()
483 int i;
484 auto = "";
485 for (i = 0; i < this.lbAuto.Items.Count; i++)
487 string sub = "";
488 string asssub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".ass";
489 string ssasub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".ssa";
490 string srtsub = lbAuto.Items[i].ToString().Remove(lbAuto.Items[i].ToString().LastIndexOf(".")) + ".srt";
491 string finish;
492 if (Directory.Exists(x264PathTextBox.Text))
493 finish = x264PathTextBox.Text + "\\" + Path.GetFileNameWithoutExtension(lbAuto.Items[i].ToString()) + "_batch.mp4";
494 else
495 finish = AddExt(lbAuto.Items[i].ToString(), "_Batch.mp4");
496 x264 = x264bat(lbAuto.Items[i].ToString(), finish).Replace("\r\n", "");
497 //判断是否内嵌字幕
498 if (x264BatchSubCheckBox.Checked)
500 if (File.Exists(asssub))
502 sub = asssub;
504 else if (File.Exists(ssasub))
506 sub = ssasub;
508 else if (File.Exists(srtsub))
510 sub = srtsub;
512 if (sub != "")
514 if (x264.IndexOf("--vf") == -1)
516 x264 += " --vf subtitles --sub \"" + sub + "\"";
518 else
520 Regex r = new Regex("--vf\\s\\S*");
521 Match m = r.Match(x264);
522 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles");
523 x264 += " --sub \"" + sub + "\"";
527 switch (x264AudioModeComboBox.SelectedIndex)
529 case 1: x264 += " --acodec none"; break;
530 case 2: x264 += " --acodec copy"; break;
531 case 3: x264 += " --audiofile \"" + x264AudioParameterTextBox.Text + "\""; break;
532 case 4: x264 += " --acodec qtaac " + x264AudioParameterTextBox.Text; break;
533 case 5: x264 += " --acodec faac " + x264AudioParameterTextBox.Text; break;
534 //case 6: x264 += " --acodec libaacplus " + x264AudioParameterTextBox.Text; break;
535 case 0: break;
536 default: ; break;
538 if (cbFPS2.Text != "auto")
540 switch (cbFPS2.Text)
542 case "23.976": x264 += " --fps 24000/1001"; break;
543 case "24": x264 += " --fps 24"; break;
544 case "25": x264 += " --fps 25"; break;
545 case "29.970": x264 += " --fps 30000/1001"; break;
546 case "30": x264 += " --fps 30"; break;
547 case "50": x264 += " --fps 50"; break;
548 case "59.940": x264 += " --fps 60000/1001"; break;
549 case "60": x264 += " --fps 60"; break;
550 default: x264 += " --fps " + cbFPS2.Text; break;
553 auto = auto + "\r\n" + x264;
556 //if (x264ShutdownCheckBox.Checked)
558 // auto += "\r\n" + syspath + ":\\Windows\\System32\\shutdown -f -s -t 60";
560 //auto += "\r\n@echo off&&echo MsgBox \"Finish!\",64,\"Maruko Toolbox\" >> msg.vbs &&call msg.vbs &&del msg.vbs\r\ncmd";
561 auto += "\r\n";
563 private void btnaudio_Click(object sender, EventArgs e)
565 openFileDialog1.Filter = "音频(*.aac;*.mp3;*.mp4)|*.aac;*.mp3;*.mp4|所有文件(*.*)|*.*";
566 DialogResult result = openFileDialog1.ShowDialog();
567 if (result == DialogResult.OK)
569 nameaudio = openFileDialog1.FileName;
570 txtaudio.Text = nameaudio;
573 private void btnvideo_Click(object sender, EventArgs e)
575 openFileDialog1.Filter = "所有文件(*.*)|*.*";
576 DialogResult result = openFileDialog1.ShowDialog();
577 if (result == DialogResult.OK)
579 namevideo = openFileDialog1.FileName;
580 txtvideo.Text = namevideo;
583 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
586 private void btnout_Click(object sender, EventArgs e)
588 SaveFileDialog savefile = new SaveFileDialog();
589 savefile.Filter = "视频(*.mp4)|*.mp4";
590 DialogResult result = savefile.ShowDialog();
591 if (result == DialogResult.OK)
593 nameout = savefile.FileName;
594 txtout.Text = nameout;
597 private void btnmux_Click(object sender, EventArgs e)
599 if (namevideo == "")
601 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
603 //else if (nameaudio == "")
605 // MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
607 else if (nameout == "")
609 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
611 else
613 if (cbFPS.Text == "auto")
615 mux = "\"" + workPath + "\\mp4box.exe\" -add \"" + namevideo + "\" -add \"" + nameaudio + "\" -new \"" + nameout + "\" \r\n cmd";
617 else
619 mux = "\"" + workPath + "\\mp4box.exe\" -fps " + cbFPS.Text + " -add \"" + namevideo + "\" -add \"" + nameaudio + "\" -new \"" + nameout + "\" \r\n cmd";
621 batpath = workPath + "\\mux.bat";
622 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
623 LogRecord(mux);
624 Process.Start(batpath);
627 private void btnaextract_Click(object sender, EventArgs e)
629 if (namevideo == "")
631 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
633 else
635 aextract = "\"" + workPath + "\\mp4box.exe\" -raw 2 \"" + namevideo + "\"";
636 batpath = workPath + "\\aextract.bat";
637 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
638 LogRecord(aextract);
639 System.Diagnostics.Process.Start(batpath);
642 private void button1_Click(object sender, EventArgs e)
644 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);
646 private void btnvextract_Click(object sender, EventArgs e)
648 if (namevideo == "")
650 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
652 else
654 vextract = "\"" + workPath + "\\mp4box.exe\" -raw 1 \"" + namevideo + "\"";
655 batpath = workPath + "\\vextract.bat";
656 File.WriteAllText(batpath, vextract, UnicodeEncoding.Default);
657 LogRecord(vextract);
658 System.Diagnostics.Process.Start(batpath);
661 private void txtvideo_TextChanged(object sender, EventArgs e)
663 if (File.Exists(txtvideo.Text.ToString()))
665 namevideo = txtvideo.Text;
666 txtout.Text = AddExt(txtvideo.Text, "_Mux.mp4");
669 private void txtaudio_TextChanged(object sender, EventArgs e)
671 nameaudio = txtaudio.Text;
673 private void txtout_TextChanged(object sender, EventArgs e)
675 nameout = txtout.Text;
677 private void btnout4_Click(object sender, EventArgs e)
679 if (namevideo2 == "")
681 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
683 else if (nameout2 == "")
685 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
687 else
689 //x264
690 oneAuto(namevideo2, nameout2);
691 batpath = workPath + "\\auto.bat";
692 LogRecord(auto);
693 WorkingForm wf = new WorkingForm(auto);
694 wf.Owner = this;
695 wf.Show();
696 //File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
697 //System.Diagnostics.Process.Start(batpath);
701 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
704 #region Delete Temp Files
706 if (SetupDeleteTempFileCheckBox.Checked && !workPath.Equals("!undefined"))
708 List<string> deleteFileList = new List<string>();
710 string systemDisk = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 3);
711 string systemTempPath = systemDisk + @"windows\temp";
713 //Delete all BAT files
714 DirectoryInfo theFolder = new DirectoryInfo(workPath);
715 foreach (FileInfo NextFile in theFolder.GetFiles())
717 if (NextFile.Extension.Equals(".bat"))
718 deleteFileList.Add(NextFile.FullName);
721 //string[] deletedfiles = { tempPic, "msg.vbs", tempavspath, "temp.avs", "clip.bat", "aextract.bat", "vextract.bat",
722 // "x264.bat", "aac.bat", "auto.bat", "mux.bat", "flv.bat", "mkvmerge.bat", "mkvextract.bat", "tmp.stat.mbtree", "tmp.stat" };
723 string[] deletedfiles = { tempPic, tempavspath, workPath + "msg.vbs", workPath + "tmp.stat.mbtree", workPath + "tmp.stat" };
724 deleteFileList.AddRange(deletedfiles);
726 foreach (string file in deleteFileList)
728 File.Delete(file);
731 #endregion
733 #region Save Settings
734 Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
735 cfa.AppSettings.Settings["x264CRF"].Value = x264CRFNum.Value.ToString();
736 cfa.AppSettings.Settings["x264Bitrate"].Value = x264BitrateNum.Value.ToString();
737 cfa.AppSettings.Settings["x264AudioParameter"].Value = x264AudioParameterTextBox.Text;
738 cfa.AppSettings.Settings["x264AudioMode"].Value = x264AudioModeComboBox.SelectedIndex.ToString();
739 cfa.AppSettings.Settings["x264Exe"].Value = x264ExeComboBox.SelectedIndex.ToString();
740 cfa.AppSettings.Settings["x264Demuxer"].Value = x264DemuxerComboBox.SelectedIndex.ToString();
741 cfa.AppSettings.Settings["x264Width"].Value = x264WidthNum.Value.ToString();
742 cfa.AppSettings.Settings["x264Height"].Value = x264HeightNum.Value.ToString();
743 cfa.AppSettings.Settings["x264CustomParameter"].Value = x264CustomParameterTextBox.Text;
744 cfa.AppSettings.Settings["x264Priority"].Value = x264PriorityComboBox.SelectedIndex.ToString();
745 cfa.AppSettings.Settings["AVSScript"].Value = AVSScriptTextBox.Text;
746 cfa.AppSettings.Settings["AudioEncoder"].Value = AudioEncoderComboBox.SelectedIndex.ToString();
747 cfa.AppSettings.Settings["AudioCustomParameter"].Value = AudioCustomParameterTextBox.Text;
748 cfa.AppSettings.Settings["AudioParameter"].Value = AudioBitrateComboBox.Text;
749 cfa.AppSettings.Settings["OnePicAudioBitrate"].Value = OnePicAudioBitrateNum.Value.ToString();
750 cfa.AppSettings.Settings["OnePicFPS"].Value = OnePicFPSNum.Value.ToString();
751 cfa.AppSettings.Settings["OnePicCRF"].Value = OnePicCRFNum.Value.ToString();
752 cfa.AppSettings.Settings["BlackFPS"].Value = BlackFPSNum.Value.ToString();
753 cfa.AppSettings.Settings["BlackCRF"].Value = BlackCRFNum.Value.ToString();
754 cfa.AppSettings.Settings["BlackBitrate"].Value = BlackBitrateNum.Value.ToString();
755 cfa.AppSettings.Settings["SetupDeleteTempFile"].Value = SetupDeleteTempFileCheckBox.Checked.ToString();
756 cfa.AppSettings.Settings["TrayMode"].Value = TrayModeCheckBox.Checked.ToString();
757 cfa.AppSettings.Settings["LanguageIndex"].Value = languageComboBox.SelectedIndex.ToString();
759 cfa.Save();
760 ConfigurationManager.RefreshSection("appSettings"); // 刷新命名节,在下次检索它时将从磁盘重新读取它。记住应用程序要刷新节点
761 #endregion
764 private void txtvideo4_TextChanged(object sender, EventArgs e)
766 if (File.Exists(txtvideo4.Text.ToString()))
768 namevideo4 = txtvideo4.Text;
769 //string finish = namevideo4.Insert(namevideo4.LastIndexOf(".")-1,"");
770 //string ext = namevideo4.Substring(namevideo4.LastIndexOf(".") + 1, 3);
771 //finish += "_clip." + ext;
772 string finish = namevideo4.Insert(namevideo4.LastIndexOf("."), "_clip");
773 txtout5.Text = finish;
776 private void txtout5_TextChanged(object sender, EventArgs e)
778 nameout5 = txtout5.Text;
780 private void btnvideo4_Click(object sender, EventArgs e)
782 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
783 DialogResult result = openFileDialog1.ShowDialog();
784 if (result == DialogResult.OK)
786 namevideo4 = openFileDialog1.FileName;
787 txtvideo4.Text = namevideo4;
790 private void btnout5_Click(object sender, EventArgs e)
792 SaveFileDialog savefile = new SaveFileDialog();
793 savefile.Filter = "视频(*.*)|*.*";
794 DialogResult result = savefile.ShowDialog();
795 if (result == DialogResult.OK)
797 nameout5 = savefile.FileName;
798 txtout5.Text = nameout5;
802 public static bool IsWindowsVistaOrNewer
804 get { return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 6); }
808 /// <summary>
809 /// 还原默认参数
810 /// </summary>
811 private void InitParameter()
813 x264CRFNum.Value = 24;
814 x264BitrateNum.Value = 800;
815 x264AudioParameterTextBox.Text = "--abitrate 128";
816 x264AudioModeComboBox.SelectedIndex = 5;
817 x264DemuxerComboBox.SelectedIndex = 2;
818 x264WidthNum.Value = 0;
819 x264HeightNum.Value = 0;
820 x264CustomParameterTextBox.Text = "";
821 x264PriorityComboBox.SelectedIndex = 2;
822 AudioEncoderComboBox.SelectedIndex = 0;
823 AudioCustomParameterTextBox.Text = "";
824 AudioBitrateComboBox.Text = "128";
825 OnePicAudioBitrateNum.Value = 128;
826 OnePicFPSNum.Value = 1;
827 OnePicCRFNum.Value = 24;
828 AVSScriptTextBox.Text = "";
829 BlackFPSNum.Value = 1;
830 BlackCRFNum.Value = 51;
831 BlackBitrateNum.Value = 900;
832 SetupDeleteTempFileCheckBox.Checked = true;
837 private void Form1_Load(object sender, EventArgs e)
839 var modulename = Process.GetCurrentProcess().MainModule.ModuleName;
840 var procesname = Path.GetFileNameWithoutExtension(modulename);
841 Process[] processes = Process.GetProcessesByName(procesname);
842 if (processes.Length > 1)
844 MessageBox.Show("你已经打开了一个小丸工具箱喔!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
845 this.Close();
847 //Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-TW");
848 //use YAHEI in VistaOrNewer
849 //if (IsWindowsVistaOrNewer)
851 // FontFamily myFontFamily = new FontFamily("微软雅黑"); //采用哪种字体
852 // Font myFont = new Font(myFontFamily, 9, FontStyle.Regular); //字是那种字体,显示的风格
853 // this.Font = myFont;
856 //define workpath
857 startpath = System.Windows.Forms.Application.StartupPath;
858 workPath = startpath + "\\tools";
859 if (!Directory.Exists(workPath))
860 Directory.CreateDirectory(workPath);
861 //string diskSymbol = startpath.Substring(0, 1);
863 string systemDisk = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 3);
864 string systemTempPath = systemDisk + @"windows\temp";
865 tempavspath = systemTempPath + "\\temp.avs";
866 tempPic = systemTempPath + "\\marukotemp.jpg";
867 InitParameter();
869 DirectoryInfo folder = new DirectoryInfo(workPath);
870 foreach (FileInfo FileName in folder.GetFiles())
872 if (FileName.Name.Contains("x264") && Path.GetExtension(FileName.Name) == ".exe")
874 x264ExeComboBox.Items.Add(FileName.Name);
878 ReleaseDatelabel.Text = ReleaseDate.ToString("yyyy-M-d");
880 //load Help Text
881 if (File.Exists(startpath + "\\help.txt"))
883 StreamReader sr = new StreamReader(startpath + "\\help.txt", System.Text.Encoding.UTF8);
884 HelpTextBox.Text = sr.ReadToEnd();
885 sr.Close();
889 //load settings
890 x264CRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264CRF"]);
891 x264BitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Bitrate"]);
892 x264AudioParameterTextBox.Text = ConfigurationManager.AppSettings["x264AudioParameter"];
893 x264AudioModeComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264AudioMode"]);
894 x264ExeComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Exe"]);
895 x264DemuxerComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Demuxer"]);
896 x264WidthNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Width"]);
897 x264HeightNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Height"]);
898 x264CustomParameterTextBox.Text = ConfigurationManager.AppSettings["x264CustomParameter"];
899 x264PriorityComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Priority"]);
900 AVSScriptTextBox.Text = ConfigurationManager.AppSettings["AVSScript"];
901 AudioEncoderComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["AudioEncoder"]);
902 AudioCustomParameterTextBox.Text = ConfigurationManager.AppSettings["AudioCustomParameter"];
903 AudioBitrateComboBox.Text = ConfigurationManager.AppSettings["AudioBitrate"];
904 OnePicAudioBitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicAudioBitrate"]);
905 OnePicFPSNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicFPS"]);
906 OnePicCRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicCRF"]);
907 BlackFPSNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackFPS"]);
908 BlackCRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackCRF"]);
909 BlackBitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackBitrate"]);
910 SetupDeleteTempFileCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["SetupDeleteTempFile"]);
911 TrayModeCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["TrayMode"]);
913 if (x264ExeComboBox.SelectedIndex == -1)
915 x264ExeComboBox.SelectedIndex = x264ExeComboBox.Items.IndexOf("x264_32_tMod-8bit-420.exe");
918 if (int.Parse(ConfigurationManager.AppSettings["LanguageIndex"]) == -1) //First Startup
920 string culture = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
921 switch (culture)
923 case "zh-CN":
924 languageComboBox.SelectedIndex = 0;
925 break;
926 case "zh-SG":
927 languageComboBox.SelectedIndex = 0;
928 break;
929 case "zh-TW":
930 languageComboBox.SelectedIndex = 1;
931 break;
932 case "zh-HK ":
933 languageComboBox.SelectedIndex = 1;
934 break;
935 case "zh-MO":
936 languageComboBox.SelectedIndex = 1;
937 break;
938 case "en-US":
939 languageComboBox.SelectedIndex = 2;
940 break;
941 case "ja-JP":
942 languageComboBox.SelectedIndex = 3;
943 break;
944 default:
945 break;
948 else
949 languageComboBox.SelectedIndex = int.Parse(ConfigurationManager.AppSettings["LanguageIndex"]);
951 catch (Exception)
953 throw;
955 //create directory
956 string preset = workPath + "\\preset";
957 if (!Directory.Exists(preset))
958 Directory.CreateDirectory(preset);
959 DirectoryInfo TheFolder = new DirectoryInfo(preset);
960 foreach (FileInfo FileName in TheFolder.GetFiles())
962 cbX264.Items.Add(FileName.Name.Replace(".txt", ""));
967 private void button2_Click(object sender, EventArgs e)
969 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
970 DialogResult result = openFileDialog1.ShowDialog();
971 if (result == DialogResult.OK)
973 namevideo6 = openFileDialog1.FileName;
974 txtvideo6.Text = namevideo6;
977 private void label16_Click(object sender, EventArgs e)
980 private void button3_Click(object sender, EventArgs e)
982 if (namevideo6 == "")
984 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
986 else
988 mkvextract = workPath + "\\ mkvextract.exe tracks \"" + namevideo6 + "\" 1:video.h264 2:audio.aac";
989 batpath = workPath + "\\mkvextract.bat";
990 File.WriteAllText(batpath, mkvextract, UnicodeEncoding.Default);
991 System.Diagnostics.Process.Start(batpath);
994 private void button4_Click(object sender, EventArgs e)
996 openFileDialog1.Filter = "视频(*.mp4)|*.mp4|所有文件(*.*)|*.*";
997 DialogResult result = openFileDialog1.ShowDialog();
998 if (result == DialogResult.OK)
1000 namevideo5 = openFileDialog1.FileName;
1001 txtvideo5.Text = namevideo5;
1004 private void button5_Click(object sender, EventArgs e)
1006 openFileDialog1.Filter = "音频(*.mp3)|*.mp3|音频(*.aac)|*.aac|所有文件(*.*)|*.*";
1007 DialogResult result = openFileDialog1.ShowDialog();
1008 if (result == DialogResult.OK)
1010 nameaudio3 = openFileDialog1.FileName;
1011 txtaudio3.Text = nameaudio3;
1014 private void button6_Click(object sender, EventArgs e)
1016 SaveFileDialog savefile = new SaveFileDialog();
1017 savefile.Filter = "视频(*.mkv)|*.mkv";
1018 DialogResult result = savefile.ShowDialog();
1019 if (result == DialogResult.OK)
1021 nameout6 = savefile.FileName;
1022 txtout6.Text = nameout6;
1025 private void button7_Click(object sender, EventArgs e)
1027 if (namevideo5 == "")
1029 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1031 else if (nameaudio3 == "")
1033 MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1035 else if (nameout6 == "")
1037 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1039 else
1041 mkvmerge = workPath + "\\mkvmerge.exe -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\"";
1042 batpath = workPath + "\\mkvmerge.bat";
1043 File.WriteAllText(batpath, mkvmerge, UnicodeEncoding.Default);
1044 System.Diagnostics.Process.Start(batpath);
1048 private void button2_Click_1(object sender, EventArgs e)
1050 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1051 DialogResult result = openFileDialog1.ShowDialog();
1052 if (result == DialogResult.OK)
1054 namevideo5 = openFileDialog1.FileName;
1055 txtvideo5.Text = namevideo5;
1058 private void button6_Click_1(object sender, EventArgs e)
1060 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
1061 DialogResult result = openFileDialog1.ShowDialog();
1062 if (result == DialogResult.OK)
1064 namevideo6 = openFileDialog1.FileName;
1065 txtvideo6.Text = namevideo6;
1068 private void button7_Click_1(object sender, EventArgs e)
1070 if (namevideo5 == "" && nameaudio3 == "")
1072 MessageBox.Show("请选择文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1074 else
1076 if (txtaudio3.Text != "" && txtsub.Text != "")
1078 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\" \"" + namesub + "\"";
1080 if (txtaudio3.Text == "" && txtsub.Text == "")
1082 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\"";
1084 if (txtaudio3.Text != "" && txtsub.Text == "")
1086 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\"";
1088 if (txtaudio3.Text == "" && txtsub.Text != "")
1090 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + namesub + "\"";
1092 mkvmerge += "\r\ncmd";
1093 batpath = workPath + "\\mkvmerge.bat";
1094 File.WriteAllText(batpath, mkvmerge, UnicodeEncoding.Default);
1095 LogRecord(mkvmerge);
1096 System.Diagnostics.Process.Start(batpath);
1099 private void button4_Click_1(object sender, EventArgs e)
1101 SaveFileDialog savefile = new SaveFileDialog();
1102 savefile.Filter = "视频(*.mkv)|*.mkv";
1103 DialogResult result = savefile.ShowDialog();
1104 if (result == DialogResult.OK)
1106 nameout6 = savefile.FileName;
1107 txtout6.Text = nameout6;
1110 private void button3_Click_1(object sender, EventArgs e)
1112 openFileDialog1.Filter = "音频(*.mp3;*.aac)|*.mp3;*.aac|所有文件(*.*)|*.*";
1113 DialogResult result = openFileDialog1.ShowDialog();
1114 if (result == DialogResult.OK)
1116 nameaudio3 = openFileDialog1.FileName;
1117 txtaudio3.Text = nameaudio3;
1120 private void button5_Click_1(object sender, EventArgs e)
1122 openFileDialog1.Filter = "ASS字幕(*.ass;*.srt)|*.ass;*.srt|所有文件(*.*)|*.*";
1123 DialogResult result = openFileDialog1.ShowDialog();
1124 if (result == DialogResult.OK)
1126 namesub = openFileDialog1.FileName;
1127 txtsub.Text = namesub;
1130 private void button8_Click(object sender, EventArgs e)
1132 if (namevideo6 == "")
1134 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1136 else
1138 int i = namevideo6.IndexOf(".mkv");
1139 string mkvname = namevideo6.Remove(i);
1140 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 1:\"" + mkvname + "_video.h264\" 2:\"" + mkvname + "_audio.aac\"";
1141 batpath = workPath + "\\mkvextract.bat";
1142 File.WriteAllText(batpath, mkvextract, UnicodeEncoding.Default);
1143 System.Diagnostics.Process.Start(batpath);
1146 private void txtvideo5_TextChanged(object sender, EventArgs e)
1148 if (File.Exists(txtvideo5.Text.ToString()))
1150 namevideo5 = txtvideo5.Text;
1151 string finish = namevideo5.Remove(namevideo5.LastIndexOf("."));
1152 finish += "_mkv封装.mkv";
1153 txtout6.Text = finish;
1156 private void txtaudio3_TextChanged(object sender, EventArgs e)
1158 nameaudio3 = txtaudio3.Text;
1160 private void txtsub_TextChanged(object sender, EventArgs e)
1162 namesub = txtsub.Text;
1164 private void txtout6_TextChanged_1(object sender, EventArgs e)
1166 nameout6 = txtout6.Text;
1168 private void txtvideo6_TextChanged(object sender, EventArgs e)
1170 namevideo6 = txtvideo6.Text;
1173 private void btnAutoAdd_Click(object sender, EventArgs e)
1175 openFileDialog1.Multiselect = true;
1176 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1177 DialogResult result = openFileDialog1.ShowDialog();
1178 if (result == DialogResult.OK)
1180 lbAuto.Items.AddRange(openFileDialog1.FileNames);
1183 private void btnAutoDel_Click(object sender, EventArgs e)
1185 if (lbAuto.Items.Count > 0)
1187 if (lbAuto.SelectedItems.Count > 0)
1189 int index = lbAuto.SelectedIndex;
1190 lbAuto.Items.RemoveAt(lbAuto.SelectedIndex);
1191 if (index == lbAuto.Items.Count)
1193 lbAuto.SelectedIndex = index - 1;
1195 if (index >= 0 && index < lbAuto.Items.Count && lbAuto.Items.Count > 0)
1197 lbAuto.SelectedIndex = index;
1202 private void btnAutoClear_Click(object sender, EventArgs e)
1204 lbAuto.Items.Clear();
1206 private void lbAuto_DragDrop(object sender, DragEventArgs e)
1208 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
1210 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
1211 foreach (String s in files)
1213 (sender as ListBox).Items.Add(s);
1216 ListBox listbox = (ListBox)sender;
1217 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
1218 if (indexoftarget != ListBox.NoMatches)
1220 string temp = listbox.Items[indexoftarget].ToString();
1221 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
1222 listbox.Items[indexofsource] = temp;
1223 listbox.SelectedIndex = indexoftarget;
1226 private void lbAuto_DragEnter(object sender, DragEventArgs e)
1228 //if (e.Data.GetDataPresent(DataFormats.FileDrop))
1229 // e.Effect = DragDropEffects.All;
1230 //else e.Effect = DragDropEffects.None;
1232 private void lbAuto_DragOver(object sender, DragEventArgs e)
1234 //拖动源和放置的目的地一定是一个ListBox
1235 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lbAuto))
1237 e.Effect = DragDropEffects.Move;
1239 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
1241 e.Effect = DragDropEffects.Link;
1243 else e.Effect = DragDropEffects.None;
1245 private void lbAuto_MouseDown(object sender, MouseEventArgs e)
1247 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
1248 if (indexofsource != ListBox.NoMatches)
1250 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
1253 private void btnBatchAuto_Click(object sender, EventArgs e)
1255 if (lbAuto.Items.Count != 0)
1257 batchAuto2();
1258 batpath = workPath + "\\auto.bat";
1259 LogRecord(auto);
1260 WorkingForm wf = new WorkingForm(auto, lbAuto.Items.Count);
1261 wf.Owner = this;
1262 wf.Show();
1264 //File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
1265 //System.Diagnostics.Process.Start(batpath);
1267 else MessageBox.Show("请输入视频!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1269 private void lbffmpeg_MouseDown(object sender, MouseEventArgs e)
1271 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
1272 if (indexofsource != ListBox.NoMatches)
1274 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
1277 private void lbffmpeg_DragDrop(object sender, DragEventArgs e)
1279 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
1281 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
1282 foreach (String s in files)
1284 (sender as ListBox).Items.Add(s);
1287 ListBox listbox = (ListBox)sender;
1288 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
1289 if (indexoftarget != ListBox.NoMatches)
1291 string temp = listbox.Items[indexoftarget].ToString();
1292 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
1293 listbox.Items[indexofsource] = temp;
1294 listbox.SelectedIndex = indexoftarget;
1297 private void lbffmpeg_DragOver(object sender, DragEventArgs e)
1299 //拖动源和放置的目的地一定是一个ListBox
1300 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lbffmpeg))
1302 e.Effect = DragDropEffects.Move;
1304 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
1306 e.Effect = DragDropEffects.Link;
1308 else e.Effect = DragDropEffects.None;
1310 private void btnffmpegAdd_Click(object sender, EventArgs e)
1312 openFileDialog1.Multiselect = true;
1313 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1314 DialogResult result = openFileDialog1.ShowDialog();
1315 if (result == DialogResult.OK)
1317 lbffmpeg.Items.AddRange(openFileDialog1.FileNames);
1320 private void btnffmpegDel_Click(object sender, EventArgs e)
1322 if (lbffmpeg.Items.Count > 0)
1324 if (lbffmpeg.SelectedItems.Count > 0)
1326 int index = lbffmpeg.SelectedIndex;
1327 lbffmpeg.Items.RemoveAt(lbffmpeg.SelectedIndex);
1328 if (index == lbffmpeg.Items.Count)
1330 lbffmpeg.SelectedIndex = index - 1;
1332 if (index >= 0 && index < lbffmpeg.Items.Count && lbffmpeg.Items.Count > 0)
1334 lbffmpeg.SelectedIndex = index;
1339 private void btnffmpegClear_Click(object sender, EventArgs e)
1341 lbffmpeg.Items.Clear();
1343 private void btnBatchFLV_Click(object sender, EventArgs e)
1345 if (lbffmpeg.Items.Count != 0)
1347 string finish;
1348 int i;
1349 ffmpeg = "";
1350 for (i = 0; i < this.lbffmpeg.Items.Count; i++)
1352 finish = lbffmpeg.Items[i].ToString().Remove(lbffmpeg.Items[i].ToString().LastIndexOf(".")) + "_FLV封装.flv";
1353 ffmpeg += "\"" + workPath + "\\ffmpeg.exe\" -i \"" + lbffmpeg.Items[i].ToString() + "\" -c copy -f flv \"" + finish + "\" \r\n";
1355 ffmpeg += "\r\ncmd";
1356 batpath = workPath + "\\flv.bat";
1357 File.WriteAllText(batpath, ffmpeg, UnicodeEncoding.Default);
1358 LogRecord(ffmpeg);
1359 System.Diagnostics.Process.Start(batpath);
1360 //lbffmpeg.Items.Clear();
1362 else MessageBox.Show("请输入视频!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1364 private void btnBatchMP4_Click(object sender, EventArgs e)
1366 if (lbffmpeg.Items.Count != 0)
1368 string finish;
1369 int i;
1370 ffmpeg = "";
1371 for (i = 0; i < this.lbffmpeg.Items.Count; i++)
1373 finish = lbffmpeg.Items[i].ToString().Remove(lbffmpeg.Items[i].ToString().LastIndexOf(".")) + "_MP4封装.mp4";
1374 ffmpeg += "\"" + workPath + "\\ffmpeg.exe\" -i \"" + lbffmpeg.Items[i].ToString() + "\" -c copy -f mp4 \"" + finish + "\" \r\n";
1376 ffmpeg += "\r\ncmd";
1377 batpath = workPath + "\\flv.bat";
1378 File.WriteAllText(batpath, ffmpeg, UnicodeEncoding.Default);
1379 LogRecord(ffmpeg);
1380 System.Diagnostics.Process.Start(batpath);
1381 //lbffmpeg.Items.Clear();
1383 else MessageBox.Show("请输入视频!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1385 private void txtvideo8_TextChanged(object sender, EventArgs e)
1387 namevideo8 = txtvideo8.Text;
1389 private void btnvextract8_Click(object sender, EventArgs e)
1391 if (namevideo8 == "")
1393 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1395 else
1397 vextract = "\"" + workPath + "\\FLVExtractCL.exe\" -v \"" + namevideo8 + "\"";
1398 batpath = workPath + "\\vextract.bat";
1399 File.WriteAllText(batpath, vextract, UnicodeEncoding.Default);
1400 LogRecord(vextract);
1401 System.Diagnostics.Process.Start(batpath);
1404 private void btnaextract8_Click(object sender, EventArgs e)
1406 if (namevideo8 == "")
1408 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1410 else
1412 aextract = "\"" + workPath + "\\FLVExtractCL.exe\" -a \"" + namevideo8 + "\"";
1413 batpath = workPath + "\\aextract.bat";
1414 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
1415 LogRecord(aextract);
1416 System.Diagnostics.Process.Start(batpath);
1419 private void btnvideo8_Click(object sender, EventArgs e)
1421 openFileDialog1.Filter = "视频(*.flv;*.hlv)|*.flv;*.hlv";
1422 DialogResult result = openFileDialog1.ShowDialog();
1423 if (result == DialogResult.OK)
1425 namevideo8 = openFileDialog1.FileName;
1426 txtvideo8.Text = namevideo;
1429 private void btnpreview9_Click(object sender, EventArgs e)
1431 if (AVSScriptTextBox.Text != "")
1433 string filepath = workPath + "\\temp.avs";
1434 File.WriteAllText(filepath, AVSScriptTextBox.Text.ToString(), UnicodeEncoding.Default);
1435 PreviewForm form2 = new PreviewForm();
1436 form2.Show();
1437 form2.axWindowsMediaPlayer1.URL = filepath;
1439 else
1441 MessageBox.Show("请输入正确的AVS脚本!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1444 private void txtout_MouseDoubleClick(object sender, MouseEventArgs e)
1446 if (File.Exists(txtout.Text.ToString()))
1448 System.Diagnostics.Process.Start(txtout.Text.ToString());
1451 private void txtout3_MouseDoubleClick(object sender, MouseEventArgs e)
1453 if (File.Exists(txtout3.Text.ToString()))
1455 System.Diagnostics.Process.Start(txtout3.Text.ToString());
1458 private void txtout6_MouseDoubleClick(object sender, MouseEventArgs e)
1460 if (File.Exists(txtout6.Text.ToString()))
1462 System.Diagnostics.Process.Start(txtout6.Text.ToString());
1465 private void txtout9_MouseDoubleClick(object sender, MouseEventArgs e)
1467 if (File.Exists(txtout9.Text.ToString()))
1469 System.Diagnostics.Process.Start(txtout9.Text.ToString());
1472 private void txtvideo9_TextChanged(object sender, EventArgs e)
1474 if (File.Exists(txtvideo9.Text.ToString()))
1476 namevideo9 = txtvideo9.Text;
1477 string finish = namevideo9.Remove(namevideo9.LastIndexOf("."));
1478 finish += "_AVS压制.mp4";
1479 txtout9.Text = finish;
1480 GenerateAVS();
1482 //if (txtvideo9.Text != "")
1484 // if (txtAVS.Text != "")
1485 // {
1486 // txtAVS.Text = txtAVS.Text.Replace(prevideo9, txtvideo9.Text);
1487 // }
1488 // else
1489 // {
1490 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1491 // foreach (FileInfo FileName in TheFolder.GetFiles())
1492 // {
1493 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1494 // }
1495 // avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\n" + "TextSub(\"" + namesub9 + "\")\r\n";
1496 // txtAVS.Text = avs;
1497 // avs = "";
1498 // }
1499 // prevideo9 = txtvideo9.Text;
1502 private void txtsub9_TextChanged(object sender, EventArgs e)
1504 namesub9 = txtsub9.Text;
1505 GenerateAVS();
1506 //if (txtAVS.Text != "")
1508 // txtAVS.Text=txtAVS.Text.Replace(namesub9, txtsub9.Text);
1509 // namesub9 = txtsub9.Text;
1511 //else
1513 // namesub9 = txtsub9.Text;
1514 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1515 // foreach (FileInfo FileName in TheFolder.GetFiles())
1516 // {
1517 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1518 // }
1519 // avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\n" + "TextSub(\"" + namesub9 + "\")\r\n";
1520 // txtAVS.Text = avs;
1521 // avs = "";
1524 private void txtout9_TextChanged(object sender, EventArgs e)
1526 nameout9 = txtout9.Text;
1528 private void btnAVS9_Click(object sender, EventArgs e)
1530 if (String.IsNullOrEmpty(nameout9))
1532 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1534 else
1536 string filepath = tempavspath;
1537 //string filepath = workpath + "\\temp.avs";
1538 File.WriteAllText(filepath, AVSScriptTextBox.Text, UnicodeEncoding.Default);
1539 x264 = x264bat(filepath, nameout9).Replace("\r\n", "");
1540 x264 += " --acodec none\r\n";
1541 batpath = workPath + "\\x264.bat";
1542 File.WriteAllText(batpath, x264, UnicodeEncoding.Default);
1543 LogRecord(x264);
1544 System.Diagnostics.Process.Start(batpath);
1547 private void btnout9_Click(object sender, EventArgs e)
1549 SaveFileDialog savefile = new SaveFileDialog();
1550 savefile.Filter = "视频(*.mp4)|*.mp4";
1551 DialogResult result = savefile.ShowDialog();
1552 if (result == DialogResult.OK)
1554 txtout9.Text = nameout9 = savefile.FileName;
1557 private void btnAVSone_Click(object sender, EventArgs e)
1559 if (String.IsNullOrEmpty(nameout9))
1561 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1563 else
1565 string filepath = workPath + "\\temp.avs";
1566 File.WriteAllText(filepath, AVSScriptTextBox.Text, UnicodeEncoding.Default);
1567 x264 = x264bat(filepath, "temp.mp4").Replace("\r\n", "");
1568 x264 += " --acodec none\r\n";
1569 //audio
1570 aextract = audiobat(namevideo9, "temp.aac");
1571 //mux
1572 mux = muxbat("temp.mp4", "temp.aac", "23.976", nameout9);
1573 //if (cbDelTmp.Checked == false)
1575 // auto = aextract + x264 + "\r\n" + mux + " \r\ndel temp.aac\r\ndel temp.mp4\r\ndel temp.wav\r\ncmd ";
1577 //else
1579 auto = aextract + x264 + "\r\n" + mux + " \r\ncmd";
1581 batpath = workPath + "\\auto.bat";
1582 File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
1583 System.Diagnostics.Process.Start(batpath);
1586 private void button6_Click_2(object sender, EventArgs e)
1588 //if (Directory.Exists("avsfilter"))
1590 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1591 // foreach (FileInfo FileName in TheFolder.GetFiles())
1592 // {
1593 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1594 // }
1596 avs += "LoadPlugin(\"avsfilter\\VSFilter.DLL\")\r\n";
1597 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);
1598 //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";
1599 AVSScriptTextBox.Text = avs;
1600 avs = "";
1602 private void txth264_TextChanged(object sender, EventArgs e)
1605 private void txtvideo_MouseDoubleClick(object sender, MouseEventArgs e)
1607 if (File.Exists(txtvideo.Text.ToString()))
1609 System.Diagnostics.Process.Start(txtvideo.Text.ToString());
1612 private void txtvideo4_MouseDoubleClick(object sender, MouseEventArgs e)
1614 if (File.Exists(txtvideo4.Text.ToString()))
1616 System.Diagnostics.Process.Start(txtvideo4.Text.ToString());
1619 private void txtout5_MouseDoubleClick(object sender, MouseEventArgs e)
1621 if (File.Exists(txtout5.Text.ToString()))
1623 System.Diagnostics.Process.Start(txtout5.Text.ToString());
1626 private void txtvideo8_MouseDoubleClick(object sender, MouseEventArgs e)
1628 if (File.Exists(txtvideo8.Text.ToString()))
1630 System.Diagnostics.Process.Start(txtvideo8.Text.ToString());
1633 private void txtvideo9_MouseDoubleClick(object sender, MouseEventArgs e)
1635 if (File.Exists(txtvideo9.Text.ToString()))
1637 System.Diagnostics.Process.Start(txtvideo9.Text.ToString());
1640 private void txtvideo6_MouseDoubleClick(object sender, MouseEventArgs e)
1642 if (File.Exists(txtvideo6.Text.ToString()))
1644 System.Diagnostics.Process.Start(txtvideo6.Text.ToString());
1647 private void txtvideo5_MouseDoubleClick(object sender, MouseEventArgs e)
1649 if (File.Exists(txtvideo5.Text.ToString()))
1651 System.Diagnostics.Process.Start(txtvideo5.Text.ToString());
1654 private void txtaudio3_MouseDoubleClick(object sender, MouseEventArgs e)
1656 if (File.Exists(txtaudio3.Text.ToString()))
1658 System.Diagnostics.Process.Start(txtaudio3.Text.ToString());
1661 private void timer1_Tick(object sender, EventArgs e)
1663 Process[] processes = Process.GetProcesses();
1664 for (int i = 0; i < processes.GetLength(0); i++)
1666 //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
1667 if (processes[i].ProcessName.Equals(Path.GetFileNameWithoutExtension(x264ExeComboBox.Text)))
1669 switch (x264PriorityComboBox.SelectedIndex)
1671 case 0: processes[i].PriorityClass = ProcessPriorityClass.Idle; break;
1672 case 1: processes[i].PriorityClass = ProcessPriorityClass.BelowNormal; break;
1673 case 2: processes[i].PriorityClass = ProcessPriorityClass.Normal; break;
1674 case 3: processes[i].PriorityClass = ProcessPriorityClass.AboveNormal; break;
1675 case 4: processes[i].PriorityClass = ProcessPriorityClass.High; break;
1676 case 5: processes[i].PriorityClass = ProcessPriorityClass.RealTime; break;
1681 private void btnsub9_Click(object sender, EventArgs e)
1683 openFileDialog1.Filter = "ASS字幕(*.ass;*.ssa)|*.ass;*.ssa|所有文件(*.*)|*.*";
1684 DialogResult result = openFileDialog1.ShowDialog();
1685 if (result == DialogResult.OK)
1687 namesub9 = openFileDialog1.FileName;
1688 txtsub9.Text = namesub9;
1691 private void btnvideo9_Click(object sender, EventArgs e)
1693 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
1694 DialogResult result = openFileDialog1.ShowDialog();
1695 if (result == DialogResult.OK)
1697 namevideo9 = openFileDialog1.FileName;
1698 txtvideo9.Text = namevideo9;
1701 private void button9_Click(object sender, EventArgs e)
1703 AVSScriptTextBox.Clear();
1705 private void btnClip_Click(object sender, EventArgs e)
1707 if (namevideo4 == "")
1709 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1711 else if (nameout5 == "")
1713 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1715 else
1717 int h1 = int.Parse(maskb.Text.ToString().Substring(0, 2));
1718 int m1 = int.Parse(maskb.Text.ToString().Substring(3, 2));
1719 int s1 = int.Parse(maskb.Text.ToString().Substring(6, 2));
1720 int h2 = int.Parse(maske.Text.ToString().Substring(0, 2));
1721 int m2 = int.Parse(maske.Text.ToString().Substring(3, 2));
1722 int s2 = int.Parse(maske.Text.ToString().Substring(6, 2));
1723 clip = "\"" + workPath + "\\ffmpeg.exe\" -ss " + maskb.Text.ToString() + " -t " + timeminus(h1, m1, s1, h2, m2, s2) + " -i \"" + namevideo4 + "\" -c copy \"" + nameout5 + "\" \r\ncmd";
1724 batpath = workPath + "\\clip.bat";
1725 File.WriteAllText(batpath, clip, UnicodeEncoding.Default);
1726 Process.Start(batpath);
1729 private void cbX264_SelectedIndexChanged(object sender, EventArgs e)
1731 StreamReader sr = new StreamReader(workPath + "\\preset\\" + cbX264.Text + ".txt", System.Text.Encoding.Default);
1732 x264CustomParameterTextBox.Text = sr.ReadToEnd();
1733 sr.Close();
1735 private void cbFPS_SelectedIndexChanged(object sender, EventArgs e)
1738 private void btnMIopen_Click(object sender, EventArgs e)
1740 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
1741 DialogResult result = openFileDialog1.ShowDialog();
1742 if (result == DialogResult.OK)
1744 MIvideo = openFileDialog1.FileName;
1745 MediaInfoTextBox.Text = MediaInfo(MIvideo);
1748 private void btnMIplay_Click(object sender, EventArgs e)
1750 Process.Start(MIvideo);
1752 private void btnMIcopy_Click(object sender, EventArgs e)
1754 Clipboard.SetText(MItext);
1756 private void btnvideo7_Click(object sender, EventArgs e)
1758 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
1759 DialogResult result = openFileDialog1.ShowDialog();
1760 if (result == DialogResult.OK)
1762 namevideo6 = openFileDialog1.FileName;
1763 txtvideo6.Text = namevideo6;
1766 private void btnextract7_Click(object sender, EventArgs e)
1768 if (namevideo6 == "")
1770 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1772 else
1774 int i = namevideo6.IndexOf(".");
1775 string mkvname = namevideo6.Remove(i);
1776 QQButton btn = (QQButton)sender;
1777 switch (btn.Name)
1779 case "MkvExtract1Button":
1780 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 1:\"" + mkvname + "_audio.aac\"";
1781 break;
1782 case "MkvExtract2Button":
1783 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 2:\"" + mkvname + "_track2\"";
1784 break;
1785 case "MkvExtract3Button":
1786 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 3:\"" + mkvname + "_track3\"";
1787 break;
1788 case "MkvExtract4Button":
1789 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 4:\"" + mkvname + "_track4\"";
1790 break;
1791 case "btnextract7":
1792 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 0:\"" + mkvname + "_video.h264\"";
1793 break;
1795 batpath = workPath + "\\mkvextract.bat";
1796 File.WriteAllText(batpath, mkvextract, UnicodeEncoding.Default);
1797 LogRecord(mkvextract);
1798 System.Diagnostics.Process.Start(batpath);
1801 private void txtMI_TextChanged(object sender, EventArgs e)
1803 MItext = MediaInfoTextBox.Text;
1805 private void txtAVScreate_Click(object sender, EventArgs e)
1808 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
1810 System.Diagnostics.Process.Start("http://www.nmm-hd.org/newbbs/viewtopic.php?f=8&t=219");
1812 private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
1814 System.Diagnostics.Process.Start("http://www.sosg.net/read.php?tid=480646");
1816 private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
1818 System.Diagnostics.Process.Start("http://pan.baidu.com/share/link?shareid=4513&uk=4094576855");
1820 private void btnaextract2_Click(object sender, EventArgs e)
1822 if (namevideo == "")
1824 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1826 else
1828 aextract = "\"" + workPath + "\\mp4box.exe\" -raw 3 \"" + namevideo + "\"";
1829 batpath = workPath + "\\aextract.bat";
1830 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
1831 LogRecord(aextract);
1832 System.Diagnostics.Process.Start(batpath);
1835 private void btnaextract3_Click(object sender, EventArgs e)
1837 if (namevideo == "")
1839 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1841 else
1843 aextract = "\"" + workPath + "\\mp4box.exe\" -raw 4 \"" + namevideo + "\"";
1844 batpath = workPath + "\\aextract.bat";
1845 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
1846 LogRecord(aextract);
1847 System.Diagnostics.Process.Start(batpath);
1850 private void txtvideo6_TextChanged_1(object sender, EventArgs e)
1852 if (File.Exists(txtvideo6.Text.ToString()))
1854 namevideo6 = txtvideo6.Text;
1857 #region 帮助页面
1858 private void AboutBtn_Click(object sender, EventArgs e)
1860 DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
1861 QQMessageBox.Show(
1862 this,
1863 "小丸工具箱 2014版\r\n主页:http://maruko.appinn.me/ \r\n编译日期:" + CompileDate.ToString(),
1864 "关于",
1865 QQMessageBoxIcon.Information,
1866 QQMessageBoxButtons.OK);
1868 private void HomePageBtn_Click(object sender, EventArgs e)
1870 System.Diagnostics.Process.Start("http://maruko.appinn.me/");
1872 #endregion
1873 #region 视频页面
1874 private void x264OneBatchButton_Click(object sender, EventArgs e)
1876 if (lbAuto.Items.Count != 0)
1878 batchAuto();
1879 batpath = workPath + "\\auto.bat";
1880 LogRecord(auto);
1881 WorkingForm wf = new WorkingForm(auto);
1882 wf.Owner = this;
1883 wf.Show();
1885 //File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
1886 //System.Diagnostics.Process.Start(batpath);
1888 else MessageBox.Show("请输入视频!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1890 private void x264VideoBtn_Click(object sender, EventArgs e)
1893 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv;*.avi;*.wmv;*.mpg;*.avs)|*.mp4;*.flv;*.mkv;*.avi;*.wmv;*.mpg;*.avs|所有文件(*.*)|*.*";
1894 DialogResult result = openFileDialog1.ShowDialog();
1895 if (result == DialogResult.OK)
1897 namevideo2 = openFileDialog1.FileName;
1898 x264VideoTextBox.Text = namevideo2;
1901 private void x264OutBtn_Click(object sender, EventArgs e)
1903 SaveFileDialog savefile = new SaveFileDialog();
1904 savefile.Filter = "视频(*.mp4)|*.mp4";
1905 DialogResult result = savefile.ShowDialog();
1906 if (result == DialogResult.OK)
1908 nameout2 = savefile.FileName;
1909 x264OutTextBox.Text = nameout2;
1912 private void x264SubBtn_Click(object sender, EventArgs e)
1914 openFileDialog1.Filter = "ASS字幕(*.ass;*.ssa)|*.ass;*.ssa|所有文件(*.*)|*.*";
1915 DialogResult result = openFileDialog1.ShowDialog();
1916 if (result == DialogResult.OK)
1918 namesub2 = openFileDialog1.FileName;
1919 x264SubTextBox.Text = namesub2;
1922 private void x264StartBtn_Click(object sender, EventArgs e)
1924 if (namevideo2 == "")
1926 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1928 else if (nameout2 == "")
1930 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1932 else
1934 //如果是AVS复制到C盘根目录
1935 if (Path.GetExtension(x264VideoTextBox.Text) == ".avs")
1937 //if (File.Exists(tempavspath)) File.Delete(tempavspath);
1938 File.Copy(x264VideoTextBox.Text, tempavspath, true);
1939 namevideo2 = tempavspath;
1941 x264 = x264bat(namevideo2, nameout2).Replace("\r\n", "");
1942 if (x264SubTextBox.Text != "")
1944 if (x264.IndexOf("--vf") == -1)
1946 x264 += " --vf subtitles --sub \"" + namesub2 + "\"";
1948 else
1950 Regex r = new Regex("--vf\\s\\S*");
1951 Match m = r.Match(x264);
1952 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles");
1953 x264 += " --sub \"" + namesub2 + "\"";
1956 switch (x264AudioModeComboBox.SelectedIndex)
1958 case 1: x264 += " --acodec none"; break;
1959 case 2: x264 += " --acodec copy"; break;
1960 case 3: x264 += " --audiofile \"" + x264AudioParameterTextBox.Text + "\""; break;
1961 case 4: x264 += " --acodec qtaac " + x264AudioParameterTextBox.Text; break;
1962 case 5: x264 += " --acodec faac " + x264AudioParameterTextBox.Text; break;
1963 //case 6: x264 += " --acodec libaacplus " + x264AudioParameterTextBox.Text; break;
1964 case 0: break;
1965 default: ; break;
1967 if (cbFPS2.Text != "auto")
1969 switch (cbFPS2.Text)
1971 case "23.976": x264 += " --fps 24000/1001"; break;
1972 case "24": x264 += " --fps 24"; break;
1973 case "25": x264 += " --fps 25"; break;
1974 case "29.970": x264 += " --fps 30000/1001"; break;
1975 case "30": x264 += " --fps 30"; break;
1976 case "50": x264 += " --fps 50"; break;
1977 case "59.940": x264 += " --fps 60000/1001"; break;
1978 case "60": x264 += " --fps 60"; break;
1979 default: x264 += " --fps " + cbFPS2.Text; break;
1982 if (x264SeekNumericUpDown.Value != 0)
1984 x264 += " --seek " + x264SeekNumericUpDown.Value.ToString();
1986 if (x264FramesNumericUpDown.Value != 0)
1988 x264 += " --frames " + x264FramesNumericUpDown.Value.ToString();
1990 x264 += "\r\n";
1991 if (x264FLVCheckBox.Checked == true)
1993 string flvfile = AddExt(nameout2, "_FLV.flv");
1994 x264 += "\r\n\"" + workPath + "\\ffmpeg.exe\" -i \"" + nameout2 + "\" -c copy -f flv \"" + flvfile + "\" \r\n";
1997 //if (x264ShutdownCheckBox.Checked)
1999 // x264 += "\r\n" + syspath + ":\\Windows\\System32\\shutdown -f -s -t 60";
2002 LogRecord(x264);
2003 WorkingForm wf = new WorkingForm(x264);
2004 wf.Owner = this;
2005 wf.Show();
2007 //x264 += "\r\ncmd";
2008 //batpath = workpath + "\\x264.bat";
2009 //File.WriteAllText(batpath, x264, UnicodeEncoding.Default);
2010 //System.Diagnostics.Process.Start(batpath);
2013 private void x264AddPresetBtn_Click(object sender, EventArgs e)
2015 //create directory
2016 string preset = workPath + "\\preset";
2017 if (!Directory.Exists(preset)) Directory.CreateDirectory(preset);
2018 //add file
2019 aextract = "\"" + workPath + "\\FLVExtractCL.exe\" -a \"" + namevideo8 + "\"";
2020 batpath = workPath + "\\preset\\" + PresetNameTextBox.Text + ".txt";
2021 File.WriteAllText(batpath, x264CustomParameterTextBox.Text, UnicodeEncoding.Default);
2022 //refresh combobox
2023 cbX264.Items.Clear();
2024 if (Directory.Exists(workPath + "\\preset"))
2026 DirectoryInfo TheFolder = new DirectoryInfo("preset");
2027 foreach (FileInfo FileName in TheFolder.GetFiles())
2029 cbX264.Items.Add(FileName.Name.Replace(".txt", ""));
2032 if (cbX264.Items.Count > 0) cbX264.SelectedIndex = 0;
2034 private void x264DeletePresetBtn_Click(object sender, EventArgs e)
2036 if (MessageBox.Show("确定要删除这条预设参数?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
2038 string name = batpath = workPath + "\\preset\\" + cbX264.Text + ".txt";
2039 File.Delete(name);
2040 cbX264.Items.Clear();
2041 if (Directory.Exists(workPath + "\\preset"))
2043 DirectoryInfo TheFolder = new DirectoryInfo("preset");
2044 foreach (FileInfo FileName in TheFolder.GetFiles())
2046 cbX264.Items.Add(FileName.Name.Replace(".txt", ""));
2049 if (cbX264.Items.Count > 0) cbX264.SelectedIndex = 0;
2052 private void x264Mode2RadioButton_CheckedChanged(object sender, EventArgs e)
2054 mode = 2;
2055 lbrate.Visible = true;
2056 x264BitrateNum.Visible = true;
2057 label12.Visible = true;
2058 cbFPS2.Visible = true;
2059 lbFPS2.Visible = true;
2060 lbwidth.Visible = true;
2061 lbheight.Visible = true;
2062 x264WidthNum.Visible = true;
2063 x264HeightNum.Visible = true;
2064 MaintainResolutionCheckBox.Visible = true;
2065 lbcrf.Visible = false;
2066 x264CRFNum.Visible = false;
2067 label4.Visible = false;
2068 x264CustomParameterTextBox.Visible = false;
2069 cbX264.Visible = false;
2070 x264AddPresetBtn.Visible = false;
2071 x264DeletePresetBtn.Visible = false;
2072 PresetNameTextBox.Visible = false;
2074 private void x264Mode3RadioButton_CheckedChanged(object sender, EventArgs e)
2076 mode = 0;
2077 label4.Visible = true;
2078 x264CustomParameterTextBox.Visible = true;
2079 cbX264.Visible = true;
2080 x264AddPresetBtn.Visible = true;
2081 x264DeletePresetBtn.Visible = true;
2082 PresetNameTextBox.Visible = true;
2083 lbwidth.Visible = false;
2084 lbheight.Visible = false;
2085 x264WidthNum.Visible = false;
2086 x264HeightNum.Visible = false;
2087 MaintainResolutionCheckBox.Visible = false;
2088 lbrate.Visible = false;
2089 x264BitrateNum.Visible = false;
2090 label12.Visible = false;
2091 lbcrf.Visible = false;
2092 x264CRFNum.Visible = false;
2093 cbFPS2.Visible = false;
2094 lbFPS2.Visible = false;
2096 private void x264Mode1RadioButton_CheckedChanged(object sender, EventArgs e)
2098 mode = 1;
2099 lbcrf.Visible = true;
2100 x264CRFNum.Visible = true;
2101 cbFPS2.Visible = true;
2102 lbFPS2.Visible = true;
2103 lbwidth.Visible = true;
2104 lbheight.Visible = true;
2105 x264WidthNum.Visible = true;
2106 x264HeightNum.Visible = true;
2107 MaintainResolutionCheckBox.Visible = true;
2108 lbrate.Visible = false;
2109 x264BitrateNum.Visible = false;
2110 label12.Visible = false;
2111 label4.Visible = false;
2112 x264CustomParameterTextBox.Visible = false;
2113 cbX264.Visible = false;
2114 x264AddPresetBtn.Visible = false;
2115 x264DeletePresetBtn.Visible = false;
2116 PresetNameTextBox.Visible = false;
2118 private void x264AudioModeComboBox_SelectedIndexChanged(object sender, EventArgs e)
2120 if (x264AudioModeComboBox.SelectedIndex != -1)
2122 switch (x264AudioModeComboBox.SelectedIndex)
2124 case 1:
2125 x264AudioParameterTextBox.Text = "";
2126 break;
2127 case 2:
2128 x264AudioParameterTextBox.Text = "";
2129 x264AudioParameterTextBox.EmptyTextTip = "可能失败,如出错请用FAAC";
2130 break;
2131 case 3:
2132 x264AudioParameterTextBox.Text = "";
2133 x264AudioParameterTextBox.EmptyTextTip = "把音频文件拖到这里";
2134 break;
2135 case 4:
2136 x264AudioParameterTextBox.Text = "--abitrate 128";
2137 break;
2138 case 5:
2139 x264AudioParameterTextBox.Text = "--abitrate 128";
2140 break;
2141 case 6:
2142 x264AudioParameterTextBox.Text = "";
2143 break;
2144 case 0:
2145 x264AudioParameterTextBox.Text = "";
2146 break;
2147 default:
2148 break;
2152 private void x264PriorityComboBox_SelectedIndexChanged(object sender, EventArgs e)
2154 string processName = x264ExeComboBox.Text;
2155 processName = processName.Replace(".exe", "");
2156 Process[] processes = Process.GetProcesses();
2157 //if (x264PriorityComboBox.SelectedIndex == 4 || x264PriorityComboBox.SelectedIndex == 5)
2159 // if (MessageBox.Show("优先级那么高的话会严重影响其他进程的运行速度,\r\n是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
2160 // {
2161 // x264PriorityComboBox.SelectedIndex = 2;
2162 // }
2164 //遍历电脑中的进程
2165 for (int i = 0; i < processes.GetLength(0); i++)
2167 //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
2168 if (processes[i].ProcessName.Equals(processName))
2170 switch (x264PriorityComboBox.SelectedIndex)
2172 case 0: processes[i].PriorityClass = ProcessPriorityClass.Idle; break;
2173 case 1: processes[i].PriorityClass = ProcessPriorityClass.BelowNormal; break;
2174 case 2: processes[i].PriorityClass = ProcessPriorityClass.Normal; break;
2175 case 3: processes[i].PriorityClass = ProcessPriorityClass.AboveNormal; break;
2176 case 4: processes[i].PriorityClass = ProcessPriorityClass.High; break;
2177 case 5: processes[i].PriorityClass = ProcessPriorityClass.RealTime; break;
2182 private void x264VideoTextBox_TextChanged(object sender, EventArgs e)
2184 string path = x264VideoTextBox.Text;
2185 if (File.Exists(path))
2187 namevideo2 = path;
2188 x264OutTextBox.Text = AddExt(path, "_x264.mp4");
2189 //txtsub2.Text = AddExt(path, ".ass");
2192 private void x264OutTextBox_TextChanged(object sender, EventArgs e)
2194 nameout2 = x264OutTextBox.Text;
2196 private void x264SubTextBox_TextChanged(object sender, EventArgs e)
2198 namesub2 = x264SubTextBox.Text;
2200 private void x264BatchClearBtn_Click(object sender, EventArgs e)
2202 lbAuto.Items.Clear();
2204 private void x264BatchDeleteBtn_Click(object sender, EventArgs e)
2206 if (lbAuto.Items.Count > 0)
2208 if (lbAuto.SelectedItems.Count > 0)
2210 int index = lbAuto.SelectedIndex;
2211 lbAuto.Items.RemoveAt(lbAuto.SelectedIndex);
2212 if (index == lbAuto.Items.Count)
2214 lbAuto.SelectedIndex = index - 1;
2216 if (index >= 0 && index < lbAuto.Items.Count && lbAuto.Items.Count > 0)
2218 lbAuto.SelectedIndex = index;
2223 private void x264BatchAddBtn_Click(object sender, EventArgs e)
2225 openFileDialog1.Multiselect = true;
2226 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2227 DialogResult result = openFileDialog1.ShowDialog();
2228 if (result == DialogResult.OK)
2230 lbAuto.Items.AddRange(openFileDialog1.FileNames);
2233 #endregion
2234 #region 音频界面
2235 private void AudioEncoderComboBox_SelectedIndexChanged(object sender, EventArgs e)
2237 if (File.Exists(txtaudio2.Text))
2239 if (AudioEncoderComboBox.SelectedIndex == 2)
2240 txtout3.Text = AddExt(txtaudio2.Text, "_WAV.wav");
2241 else
2242 txtout3.Text = AddExt(txtaudio2.Text, "_AAC.aac");
2245 private void AudioListBox_DragDrop(object sender, DragEventArgs e)
2247 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
2249 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
2250 foreach (String s in files)
2252 (sender as ListBox).Items.Add(s);
2255 ListBox listbox = (ListBox)sender;
2256 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
2257 if (indexoftarget != ListBox.NoMatches)
2259 string temp = listbox.Items[indexoftarget].ToString();
2260 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
2261 listbox.Items[indexofsource] = temp;
2262 listbox.SelectedIndex = indexoftarget;
2265 private void AudioListBox_DragOver(object sender, DragEventArgs e)
2267 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lbAuto))
2269 e.Effect = DragDropEffects.Move;
2271 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
2273 e.Effect = DragDropEffects.Link;
2275 else e.Effect = DragDropEffects.None;
2277 private void AudioListBox_MouseDown(object sender, MouseEventArgs e)
2279 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
2280 if (indexofsource != ListBox.NoMatches)
2282 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
2285 private void AudioBatchButton_Click(object sender, EventArgs e)
2287 if (AudioListBox.Items.Count != 0)
2289 string finish;
2290 aac = "";
2291 for (int i = 0; i < this.AudioListBox.Items.Count; i++)
2293 if (AudioEncoderComboBox.SelectedIndex == 2)
2294 finish = AddExt(AudioListBox.Items[i].ToString(), "_WAV.wav");
2295 else
2296 finish = AddExt(AudioListBox.Items[i].ToString(), "_AAC.aac");
2297 aac += audiobat(AudioListBox.Items[i].ToString(), finish);
2298 aac += "\r\n";
2300 aac += "\r\ncmd";
2301 batpath = workPath + "\\aac.bat";
2302 File.WriteAllText(batpath, aac, UnicodeEncoding.Default);
2303 LogRecord(aac);
2304 System.Diagnostics.Process.Start(batpath);
2306 else MessageBox.Show("请输入文件!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2308 private void btnaudio2_Click(object sender, EventArgs e)
2310 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2311 DialogResult result = openFileDialog1.ShowDialog();
2312 if (result == DialogResult.OK)
2314 nameaudio2 = openFileDialog1.FileName;
2315 txtaudio2.Text = nameaudio2;
2318 private void btnout3_Click(object sender, EventArgs e)
2320 SaveFileDialog savefile = new SaveFileDialog();
2321 savefile.Filter = "音频(*.aac)|*.aac";
2322 DialogResult result = savefile.ShowDialog();
2323 if (result == DialogResult.OK)
2325 nameout3 = savefile.FileName;
2326 txtout3.Text = nameout3;
2329 private void btnaac_Click(object sender, EventArgs e)
2331 if (nameaudio2 == "")
2333 MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2335 else if (nameout3 == "")
2337 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2339 else
2341 //ffmpeg = "\"" + workpath + "\\ffmpeg.exe\" -y -i \"" + nameaudio2 + "\" -f wav temp.wav";
2342 //int AACbr = 1024 * Convert.ToInt32(numq.Value.ToString());
2343 //string br = AACbr.ToString();
2344 //neroaac = "\"" + workpath + "\\neroAacEnc.exe\" -ignorelength -lc -br " + br + " -if \"temp.wav\" -of \"" + nameout3 + "\"";
2345 //aac = ffmpeg + "&&" + neroaac + "\r\ncmd";
2346 //if (cbwavtemp.Checked == false)
2348 // aac += "del temp.wav\r\ncmd";
2350 batpath = workPath + "\\aac.bat";
2351 File.WriteAllText(batpath, audiobat(nameaudio2, nameout3), UnicodeEncoding.Default);
2352 LogRecord(audiobat(nameaudio2, nameout3));
2353 System.Diagnostics.Process.Start(batpath);
2356 private void txtaudio2_TextChanged(object sender, EventArgs e)
2358 if (File.Exists(txtaudio2.Text.ToString()))
2360 nameaudio2 = txtaudio2.Text;
2361 if (AudioEncoderComboBox.SelectedIndex == 2)
2362 txtout3.Text = AddExt(txtaudio2.Text, "_WAV.wav");
2363 else
2364 txtout3.Text = AddExt(txtaudio2.Text, "_AAC.aac");
2367 private void txtout3_TextChanged(object sender, EventArgs e)
2369 nameout3 = txtout3.Text;
2371 private void txtaudio2_MouseDoubleClick(object sender, MouseEventArgs e)
2373 if (File.Exists(txtaudio2.Text.ToString()))
2375 System.Diagnostics.Process.Start(txtaudio2.Text.ToString());
2378 private void radioButton5_CheckedChanged(object sender, EventArgs e)
2380 lbaacrate.Visible = false;
2381 lbaackbps.Visible = false;
2382 AudioBitrateComboBox.Visible = false;
2383 AudioCustomParameterTextBox.Visible = true;
2385 private void radioButton4_CheckedChanged(object sender, EventArgs e)
2387 lbaacrate.Visible = true;
2388 lbaackbps.Visible = true;
2389 AudioBitrateComboBox.Visible = true;
2390 AudioCustomParameterTextBox.Visible = false;
2392 private void AudioAddButton_Click(object sender, EventArgs e)
2394 openFileDialog1.Multiselect = true;
2395 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2396 DialogResult result = openFileDialog1.ShowDialog();
2397 if (result == DialogResult.OK)
2399 AudioListBox.Items.AddRange(openFileDialog1.FileNames);
2402 private void AudioDeleteButton_Click(object sender, EventArgs e)
2404 if (AudioListBox.Items.Count > 0)
2406 if (AudioListBox.SelectedItems.Count > 0)
2408 int index = AudioListBox.SelectedIndex;
2409 AudioListBox.Items.RemoveAt(AudioListBox.SelectedIndex);
2410 if (index == AudioListBox.Items.Count)
2412 AudioListBox.SelectedIndex = index - 1;
2414 if (index >= 0 && index < AudioListBox.Items.Count && AudioListBox.Items.Count > 0)
2416 AudioListBox.SelectedIndex = index;
2421 private void AudioClearButton_Click(object sender, EventArgs e)
2423 AudioListBox.Items.Clear();
2425 #endregion
2426 #region AVS页面
2427 private void GenerateAVS()
2429 //if (Directory.Exists("avsfilter"))
2431 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
2432 // foreach (FileInfo FileName in TheFolder.GetFiles())
2433 // {
2434 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
2435 // }
2437 avsBuilder.Remove(0, avsBuilder.Length);
2438 avsBuilder.AppendLine("LoadPlugin(\"avsfilter\\VSFilter.DLL\")");
2439 if (UndotCheckBox.Checked) avsBuilder.AppendLine("LoadPlugin(\"avsfilter\\UnDot.DLL\")");
2440 avsBuilder.AppendLine("DirectShowSource(\"" + namevideo9 + "\")");
2441 avsBuilder.AppendLine("ConvertToYV12()");
2442 if (UndotCheckBox.Checked)
2443 avsBuilder.AppendLine("Undot()");
2444 if (TweakCheckBox.Checked)
2445 avsBuilder.AppendLine("Tweak(" + TweakChromaNumericUpDown.Value.ToString() + ", " + TweakSaturationNumericUpDown.Value.ToString() + ", " + TweakBrightnessNumericUpDown.Value.ToString() + ", " + TweakContrastNumericUpDown.Value.ToString() + ")");
2446 if (LevelsCheckBox.Checked)
2447 avsBuilder.AppendLine("Levels(0," + LevelsNumericUpDown.Value.ToString() + ",255,0,255)");
2448 if (LanczosResizeCheckBox.Checked)
2449 avsBuilder.AppendLine("LanczosResize(" + AVSWidthNumericUpDown.Value.ToString() + "," + AVSHeightNumericUpDown.Value.ToString() + ")");
2450 if (SharpenCheckBox.Checked)
2451 avsBuilder.AppendLine("Sharpen(" + SharpenNumericUpDown.Value.ToString() + ")");
2452 if (CropCheckBox.Checked)
2453 avsBuilder.AppendLine("Crop(" + AVSCropTextBox.Text + ")");
2454 if (AddBordersCheckBox.Checked)
2455 avsBuilder.AppendLine("AddBorders(" + AddBorders1NumericUpDown.Value.ToString() + "," + AddBorders2NumericUpDown.Value.ToString() + "," + AddBorders3NumericUpDown.Value.ToString() + "," + AddBorders4NumericUpDown.Value.ToString() + ")");
2456 if (!string.IsNullOrEmpty(txtsub9.Text))
2458 if (Path.GetExtension(namesub9) == ".idx")
2459 avsBuilder.AppendLine("vobsub(\"" + namesub9 + "\")");
2460 else
2461 avsBuilder.AppendLine("TextSub(\"" + namesub9 + "\")");
2463 if (TrimCheckBox.Checked)
2464 avsBuilder.AppendLine("Trim(" + TrimStartNumericUpDown.Value.ToString() + "," + TrimEndNumericUpDown.Value.ToString() + ")");
2465 AVSScriptTextBox.Text = avsBuilder.ToString();
2467 #region 更改AVS
2468 private void TweakCheckBox_CheckedChanged(object sender, EventArgs e)
2470 GenerateAVS();
2472 private void LanczosResizeCheckBox_CheckedChanged(object sender, EventArgs e)
2474 GenerateAVS();
2476 private void AddBordersCheckBox_CheckedChanged(object sender, EventArgs e)
2478 GenerateAVS();
2480 private void CropCheckBox_CheckedChanged(object sender, EventArgs e)
2482 GenerateAVS();
2484 private void TrimCheckBox_CheckedChanged(object sender, EventArgs e)
2486 GenerateAVS();
2488 private void LevelsCheckBox_CheckedChanged(object sender, EventArgs e)
2490 GenerateAVS();
2492 private void SharpenCheckBox_CheckedChanged(object sender, EventArgs e)
2494 GenerateAVS();
2496 private void UndotCheckBox_CheckedChanged(object sender, EventArgs e)
2498 GenerateAVS();
2500 private void TweakChromaNumericUpDown_ValueChanged(object sender, EventArgs e)
2502 GenerateAVS();
2504 private void TweakSaturationNumericUpDown_ValueChanged(object sender, EventArgs e)
2506 GenerateAVS();
2508 private void TweakBrightnessNumericUpDown_ValueChanged(object sender, EventArgs e)
2510 GenerateAVS();
2512 private void TweakContrastNumericUpDown_ValueChanged(object sender, EventArgs e)
2514 GenerateAVS();
2516 private void AVSWidthNumericUpDown_ValueChanged(object sender, EventArgs e)
2518 GenerateAVS();
2520 private void AVSHeightNumericUpDown_ValueChanged(object sender, EventArgs e)
2522 GenerateAVS();
2524 private void AddBorders1NumericUpDown_ValueChanged(object sender, EventArgs e)
2526 GenerateAVS();
2528 private void AddBorders2NumericUpDown_ValueChanged(object sender, EventArgs e)
2530 GenerateAVS();
2532 private void AddBorders3NumericUpDown_ValueChanged(object sender, EventArgs e)
2534 GenerateAVS();
2536 private void AddBorders4NumericUpDown_ValueChanged(object sender, EventArgs e)
2538 GenerateAVS();
2540 private void AVSCropTextBox_TextChanged(object sender, EventArgs e)
2542 GenerateAVS();
2544 private void TrimStartNumericUpDown_ValueChanged(object sender, EventArgs e)
2546 GenerateAVS();
2548 private void TrimEndNumericUpDown_ValueChanged(object sender, EventArgs e)
2550 GenerateAVS();
2552 private void LevelsNumericUpDown_ValueChanged(object sender, EventArgs e)
2554 GenerateAVS();
2556 private void SharpenNumericUpDown_ValueChanged(object sender, EventArgs e)
2558 GenerateAVS();
2561 #endregion
2562 #endregion
2563 private void ExtractMP4Button_Click(object sender, EventArgs e)
2565 openFileDialog1.Filter = "视频(*.mp4)|*.mp4|所有文件(*.*)|*.*";
2566 DialogResult result = openFileDialog1.ShowDialog();
2567 if (result == DialogResult.OK)
2569 namevideo = openFileDialog1.FileName;
2570 ExtractMP4TextBox.Text = namevideo;
2573 private void txtAVS_TextChanged(object sender, EventArgs e)
2575 Match m = Regex.Match(AVSScriptTextBox.Text, "ource\\(\"[a-zA-Z]:\\\\.+\\.\\w+\"");
2576 if (m.Success)
2578 string str = m.ToString();
2579 str = str.Replace("ource(\"", "");
2580 str = str.Replace("\"", "");
2581 str = AddExt(str, "_AVS.mp4");
2582 txtout9.Text = str;
2585 public void Log(string path)
2587 ProcessStartInfo start = new ProcessStartInfo(path);//设置运行的命令行文件问ping.exe文件,这个文件系统会自己找到
2588 //如果是其它exe文件,则有可能需要指定详细路径,如运行winRar.exe
2589 start.CreateNoWindow = false;//不显示dos命令行窗口
2590 start.RedirectStandardOutput = true;//
2591 start.RedirectStandardInput = true;//
2592 start.UseShellExecute = false;//是否指定操作系统外壳进程启动程序
2593 Process p = Process.Start(start);
2594 StreamReader reader = p.StandardOutput;//截取输出流
2595 string line = reader.ReadLine();//每次读取一行
2596 StringBuilder log = new StringBuilder(2000);
2597 while (!reader.EndOfStream)
2599 log.Append(line + "\r\n");
2600 line = reader.ReadLine();
2602 p.WaitForExit();//等待程序执行完退出进程
2603 File.WriteAllText(workPath + "\\log.txt", log.ToString(), UnicodeEncoding.Default);
2604 p.Close();//关闭进程
2605 reader.Close();//关闭流
2607 public void LogRecord(string log)
2609 File.AppendAllText(workPath + "\\log.txt", "===========" + DateTime.Now.ToString() + "===========\r\n" + log + "\r\n\r\n", UnicodeEncoding.Default);
2611 private void DeleteLogButton_Click(object sender, EventArgs e)
2613 if (File.Exists(workPath + "\\log.txt"))
2615 File.Delete(workPath + "\\log.txt");
2616 MessageBox.Show("已经删除日志文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
2618 else MessageBox.Show("没有找到日志文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2620 private void ViewLogButton_Click(object sender, EventArgs e)
2622 if (File.Exists(workPath + "\\log.txt"))
2624 System.Diagnostics.Process.Start(workPath + "\\log.txt");
2626 else MessageBox.Show("没有找到日志文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2628 private void x264PathButton_Click(object sender, EventArgs e)
2630 FolderBrowserDialog fbd = new FolderBrowserDialog();
2631 fbd.ShowDialog();
2632 x264PathTextBox.Text = fbd.SelectedPath;
2634 private void ExtractMP4TextBox_TextChanged(object sender, EventArgs e)
2636 namevideo = ExtractMP4TextBox.Text;
2638 private void MaintainResolutionCheckBox_CheckedChanged(object sender, EventArgs e)
2640 if (MaintainResolutionCheckBox.Checked)
2642 x264WidthNum.Value = 0;
2643 x264HeightNum.Value = 0;
2644 x264WidthNum.Enabled = false;
2645 x264HeightNum.Enabled = false;
2647 else
2649 x264WidthNum.Enabled = true;
2650 x264HeightNum.Enabled = true;
2653 #region globalization
2654 public static void SetLang(string lang, Form form, Type formType)
2656 System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
2657 if (form != null)
2659 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(formType);
2660 resources.ApplyResources(form, "$this");
2661 AppLang(form, resources);
2664 private static void AppLang(Control control, System.ComponentModel.ComponentResourceManager resources)
2666 foreach (Control c in control.Controls)
2668 resources.ApplyResources(c, c.Name);
2669 AppLang(c, resources);
2672 private void languageComboBox_SelectedIndexChanged(object sender, EventArgs e)
2674 StreamReader sr;
2675 x264Mode1RadioButton.Checked = true;
2676 AudioBitrateRadioButton.Checked = true;
2677 switch (languageComboBox.SelectedIndex)
2679 case 0:
2680 SetLang("zh-CN", this, typeof(MainForm));
2681 x264PriorityComboBox.Items.Clear();
2682 x264PriorityComboBox.Items.AddRange(new string[] { "低", "低于标准", "普通", "高于标准", "高", "实时" });
2683 x264PriorityComboBox.SelectedIndex = 2;
2684 x264VideoTextBox.EmptyTextTip = "可以把文件拖曳到这里";
2685 //x264OutTextBox.EmptyTextTip = "宽度和高度全为0即不改变分辨率";
2686 x264PathTextBox.EmptyTextTip = "字幕文件和视频文件在同一目录下且同名";
2687 //txtvideo3.EmptyTextTip = "音频参数在音频选项卡设定";
2688 ExtractMP4TextBox.EmptyTextTip = "抽取的视频或音频在原视频目录下";
2689 txtvideo8.EmptyTextTip = "抽取的视频或音频在原视频目录下";
2690 txtvideo6.EmptyTextTip = "抽取的视频或音频在原视频目录下";
2691 //load Help Text
2692 if (File.Exists(startpath + "\\help.txt"))
2694 sr = new StreamReader(startpath + "\\help.txt", System.Text.Encoding.UTF8);
2695 HelpTextBox.Text = sr.ReadToEnd();
2696 sr.Close();
2698 break;
2699 case 1:
2700 SetLang("zh-TW", this, typeof(MainForm));
2701 x264PriorityComboBox.Items.Clear();
2702 x264PriorityComboBox.Items.AddRange(new string[] { "低", "在標準以下", "標準", "在標準以上", "高", "即時" });
2703 x264PriorityComboBox.SelectedIndex = 2;
2704 x264VideoTextBox.EmptyTextTip = "可以把文件拖曳到這裡";
2705 //x264OutTextBox.EmptyTextTip = "寬度和高度全為0即不改變解析度";
2706 x264PathTextBox.EmptyTextTip = "字幕和視頻在同一資料夾下且同名";
2707 //txtvideo3.EmptyTextTip = "音頻參數需在音頻選項卡设定";
2708 ExtractMP4TextBox.EmptyTextTip = "新檔案生成在原資料夾";
2709 txtvideo8.EmptyTextTip = "新檔案生成在原資料夾";
2710 txtvideo6.EmptyTextTip = "新檔案生成在原資料夾";
2711 //load Help Text
2712 if (File.Exists(startpath + "\\help_zh_tw.txt"))
2714 sr = new StreamReader(startpath + "\\help_zh_tw.txt", System.Text.Encoding.UTF8);
2715 HelpTextBox.Text = sr.ReadToEnd();
2716 sr.Close();
2718 break;
2719 case 2:
2720 SetLang("en-US", this, typeof(MainForm));
2721 x264PriorityComboBox.Items.Clear();
2722 x264PriorityComboBox.Items.AddRange(new string[] { "Idle", "BelowNormal", "Normal", "AboveNormal", "High", "RealTime" });
2723 x264PriorityComboBox.SelectedIndex = 2;
2724 x264VideoTextBox.EmptyTextTip = "Drag file here";
2725 //x264OutTextBox.EmptyTextTip = "Both the width and height equal zero means using original resolution";
2726 x264PathTextBox.EmptyTextTip = "Subtitle and Video must be of the same name and in the same folder";
2727 //txtvideo3.EmptyTextTip = "It is necessary to set audio parameter in the Audio tab";
2728 ExtractMP4TextBox.EmptyTextTip = "New file will be created in the original folder";
2729 txtvideo8.EmptyTextTip = "New file will be created in the original folder";
2730 txtvideo6.EmptyTextTip = "New file will be created in the original folder";
2731 //load Help Text
2732 if (File.Exists(startpath + "\\help.txt"))
2734 sr = new StreamReader(startpath + "\\help.txt", System.Text.Encoding.UTF8);
2735 HelpTextBox.Text = sr.ReadToEnd();
2736 sr.Close();
2738 break;
2739 case 3:
2740 SetLang("ja-JP", this, typeof(MainForm));
2741 x264PriorityComboBox.Items.Clear();
2742 x264PriorityComboBox.Items.AddRange(new string[] { "低", "通常以下", "通常", "通常以上", "高", "リアルタイム" });
2743 x264PriorityComboBox.SelectedIndex = 2;
2744 x264VideoTextBox.EmptyTextTip = "ビデオファイルをここに引きずってください";
2745 //x264OutTextBox.EmptyTextTip = "Both the width and height equal zero means using original resolution";
2746 x264PathTextBox.EmptyTextTip = "字幕とビデオは同じ名前と同じフォルダにある必要があります";
2747 //txtvideo3.EmptyTextTip = "It is necessary to set audio parameter in the Audio tab";
2748 ExtractMP4TextBox.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
2749 txtvideo8.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
2750 txtvideo6.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
2751 break;
2752 default:
2753 SetLang("zh-CN", this, typeof(MainForm));
2754 break;
2757 #endregion
2758 public static void RunProcess(string exe, string arg)
2760 Thread thread = new Thread(() =>
2762 ProcessStartInfo psi = new ProcessStartInfo(exe, arg);
2763 psi.CreateNoWindow = true;
2764 Process p = new Process();
2765 p.StartInfo = psi;
2766 p.Start();
2767 p.WaitForExit();
2768 MessageBox.Show("ts");
2769 p.Close();
2771 thread.IsBackground = true;
2772 thread.Start();
2774 private void DonateButton_Click(object sender, EventArgs e)
2776 System.Diagnostics.Process.Start("https://me.alipay.com/marukochan");
2778 private void AVSSaveButton_Click(object sender, EventArgs e)
2780 SaveFileDialog savefile = new SaveFileDialog();
2781 savefile.Filter = "AVS(*.avs)|*.avs";
2782 DialogResult result = savefile.ShowDialog();
2783 if (result == DialogResult.OK)
2785 File.WriteAllText(savefile.FileName, AVSScriptTextBox.Text, UnicodeEncoding.Default);
2788 private void MuxReplaceAudioButton_Click(object sender, EventArgs e)
2790 if (namevideo == "")
2792 MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2793 return;
2795 if (nameaudio == "")
2797 MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2798 return;
2800 if (nameout == "")
2802 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2803 return;
2805 mux = "";
2806 mux = "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + namevideo + "\" -vcodec copy -an \"" + workPath + "\\video_noaudio.mp4\" \r\n";
2807 mux += "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + workPath + "\\video_noaudio.mp4\" -i \"" + nameaudio + "\" -vcodec copy -acodec copy \"" + nameout + "\" \r\n";
2808 mux += "del \"" + workPath + "\\video_noaudio.mp4\" \r\n";
2809 batpath = workPath + "\\mux.bat";
2810 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
2811 LogRecord(mux);
2812 Process.Start(batpath);
2814 private void cbx264file_SelectedIndexChanged(object sender, EventArgs e)
2816 if (x264ExeComboBox.Text.Contains("all"))
2818 x264AudioModeComboBox.Items.Clear();
2819 x264AudioModeComboBox.Items.Add("默认");
2820 x264AudioModeComboBox.Items.Add("无音频流");
2821 x264AudioModeComboBox.Items.Add("复制音频流");
2822 x264AudioModeComboBox.Items.Add("外置音频流");
2823 x264AudioModeComboBox.SelectedIndex = 1;
2825 else
2827 x264AudioModeComboBox.Items.Clear();
2828 x264AudioModeComboBox.Items.Add("默认");
2829 x264AudioModeComboBox.Items.Add("无音频流");
2830 x264AudioModeComboBox.Items.Add("复制音频流");
2831 x264AudioModeComboBox.Items.Add("外置音频流");
2832 x264AudioModeComboBox.Items.Add("QTAAC");
2833 x264AudioModeComboBox.Items.Add("FAAC");
2834 x264AudioModeComboBox.SelectedIndex = 5;
2838 #region 一图流
2840 private void AudioPicButton_Click(object sender, EventArgs e)
2842 openFileDialog1.Filter = "图片(*.jpg;*.jpeg;*.png;*.bmp;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件(*.*)|*.*";
2843 DialogResult result = openFileDialog1.ShowDialog();
2844 if (result == DialogResult.OK)
2846 AudioPicTextBox.Text = openFileDialog1.FileName;
2849 private void AudioPicAudioButton_Click(object sender, EventArgs e)
2851 openFileDialog1.Filter = "音频(*.aac;*.mp3;*.mp4;*.wav)|*.aac;*.mp3;*.mp4;*.wav|所有文件(*.*)|*.*";
2852 DialogResult result = openFileDialog1.ShowDialog();
2853 if (result == DialogResult.OK)
2855 AudioPicAudioTextBox.Text = openFileDialog1.FileName;
2858 private void AudioOnePicOutputButton_Click(object sender, EventArgs e)
2860 SaveFileDialog savefile = new SaveFileDialog();
2861 savefile.Filter = "MP4视频(*.mp4)|*.mp4|FLV视频(*.flv)|*.flv";
2862 savefile.FileName = "Single";
2863 DialogResult result = savefile.ShowDialog();
2864 if (result == DialogResult.OK)
2866 AudioOnePicOutputTextBox.Text = savefile.FileName;
2869 public int SecondsFromHHMMSS(string hhmmss)
2871 int hh = int.Parse(hhmmss.Substring(0, 2));
2872 int mm = int.Parse(hhmmss.Substring(3, 2));
2873 int ss = int.Parse(hhmmss.Substring(6, 2));
2874 return hh * 3600 + mm * 60 + ss;
2876 private void AudioOnePicButton_Click(object sender, EventArgs e)
2878 if (!File.Exists(AudioPicTextBox.Text))
2880 MessageBox.Show("请选择图片文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2882 else if (!File.Exists(AudioPicAudioTextBox.Text))
2884 MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2886 else if (AudioOnePicOutputTextBox.Text == "")
2888 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2890 else
2892 System.Drawing.Image img = System.Drawing.Image.FromFile(AudioPicTextBox.Text);
2893 int sourceWidth = img.Width;
2894 int sourceHeight = img.Height;
2895 if (img.Width % 2 != 0 || img.Height % 2 != 0)
2897 MessageBox.Show("图片的长和宽必须是偶数。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2898 img.Dispose();
2899 return;
2901 if (img.RawFormat.Equals(ImageFormat.Jpeg))
2903 File.Copy(AudioPicTextBox.Text, tempPic, true);
2905 else
2907 System.Drawing.Imaging.Encoder ImageEncoder = System.Drawing.Imaging.Encoder.Quality;
2908 EncoderParameter ep = new EncoderParameter(ImageEncoder, 100L);
2909 EncoderParameters eps = new EncoderParameters(1);
2910 ImageCodecInfo ImageCoderType = getImageCoderInfo("image/jpeg");
2911 eps.Param[0] = ep;
2912 img.Save(tempPic, ImageCoderType, eps);
2913 //img.Save(tempPic, ImageFormat.Jpeg);
2915 //获得音频时长
2916 MediaInfo MI = new MediaInfo();
2917 MI.Open(AudioPicAudioTextBox.Text);
2918 int seconds = SecondsFromHHMMSS(MI.Get(StreamKind.General, 0, "Duration/String3"));
2919 if (AudioCopyCheckBox.Checked)
2921 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";
2922 mux += "ffmpeg -i SinglePictureVideo.mp4 -i \"" + AudioPicAudioTextBox.Text + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
2923 mux += "del SinglePictureVideo.mp4\r\n";
2925 else
2927 mux = "ffmpeg -i \"" + AudioPicAudioTextBox.Text + "\" -f wav - |neroaacenc -br " + OnePicAudioBitrateNum.Value.ToString() + "000 -ignorelength -if - -of audio.mp4 -lc\r\n";
2928 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";
2929 mux += "ffmpeg -i SinglePictureVideo.mp4 -i audio.mp4 -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
2930 mux += "del SinglePictureVideo.mp4\r\ndel audio.mp4\r\n";
2933 string audioPath = AddExt(Path.GetFileName(AudioPicAudioTextBox.Text), "_atmp.mp4");
2934 string videoPath = AddExt(Path.GetFileName(AudioPicAudioTextBox.Text), "_vtmp.mp4");
2935 string picturePath = "c:\\" + Path.GetFileNameWithoutExtension(AudioPicTextBox.Text) + "_tmp.jpg";
2936 if (AudioCopyCheckBox.Checked)
2938 mux = "ffmpeg -loop 1 -r " + AudioOnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + picturePath + "\" -vcodec libx264 -crf 24 -y \"" + videoPath + "\"\r\n";
2939 mux += "ffmpeg -i \"" + videoPath + "\" -i \"" + AudioPicAudioTextBox.Text + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
2940 mux += "del \"" + videoPath + "\"\r\ndel \"" + picturePath + "\"\r\n";
2942 else
2944 mux = "ffmpeg -i \"" + AudioPicAudioTextBox.Text + "\" -f wav - |neroaacenc -br " + AudioOnePicAudioBitrateNum.Value.ToString() + "000 -ignorelength -if - -of \"" + audioPath + "\" -lc\r\n";
2945 mux += "ffmpeg -loop 1 -r " + AudioOnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + picturePath + "\" -vcodec libx264 -crf 24 -y \"" + videoPath + "\"\r\n";
2946 mux += "ffmpeg -i \"" + videoPath + "\" -i \"" + audioPath + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
2947 mux += "del \"" + videoPath + "\"\r\ndel \"" + audioPath + "\"\r\ndel \"" + picturePath + "\"\r\n";
2950 batpath = Path.Combine(workPath, Path.GetRandomFileName() + ".bat");
2951 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
2952 LogRecord(mux);
2953 Process.Start(batpath);
2956 private void txtMI_DragDrop(object sender, DragEventArgs e)
2958 MIvideo = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
2959 MediaInfoTextBox.Text = MediaInfo(MIvideo);
2961 private void txtMI_DragEnter(object sender, DragEventArgs e)
2963 if (e.Data.GetDataPresent(DataFormats.FileDrop))
2964 e.Effect = DragDropEffects.Link;
2965 else e.Effect = DragDropEffects.None;
2967 private void AudioPicAudioTextBox_TextChanged(object sender, EventArgs e)
2969 if (File.Exists(AudioPicAudioTextBox.Text.ToString()))
2971 AudioOnePicOutputTextBox.Text = AddExt(AudioPicAudioTextBox.Text, "_SP.flv");
2974 /// <summary>
2975 /// 获取图片编码类型信息
2976 /// </summary>
2977 /// <param name="ImageCoderType">编码类型</param>
2978 /// <returns>ImageCodecInfo</returns>
2979 private ImageCodecInfo getImageCoderInfo(string ImageCoderType)
2981 ImageCodecInfo[] coderTypeArray = ImageCodecInfo.GetImageEncoders();
2982 foreach (ImageCodecInfo coderType in coderTypeArray)
2984 if (coderType.MimeType.Equals(ImageCoderType))
2985 return coderType;
2987 return null;
2990 #endregion
2993 #region 后黑
2995 private void BlackVideoButton_Click(object sender, EventArgs e)
2997 openFileDialog1.Filter = "FLV视频(*.flv)|*.flv";
2998 DialogResult result = openFileDialog1.ShowDialog();
2999 if (result == DialogResult.OK)
3001 BlackVideoTextBox.Text = openFileDialog1.FileName;
3005 private void BlackOutputButton_Click(object sender, EventArgs e)
3007 SaveFileDialog savefile = new SaveFileDialog();
3008 savefile.Filter = "FLV视频(*.flv)|*.flv";
3009 DialogResult result = savefile.ShowDialog();
3010 if (result == DialogResult.OK)
3012 BlackOutputTextBox.Text = savefile.FileName;
3016 private void BlackPicButton_Click(object sender, EventArgs e)
3018 openFileDialog1.Filter = "图片(*.jpg;*.jpeg;*.png;*.bmp;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件(*.*)|*.*";
3019 DialogResult result = openFileDialog1.ShowDialog();
3020 if (result == DialogResult.OK)
3022 BlackPicTextBox.Text = openFileDialog1.FileName;
3026 private void BlackStartButton_Click(object sender, EventArgs e)
3028 string videoname = BlackVideoTextBox.Text;
3029 MediaInfo MI = new MediaInfo();
3030 MI.Open(videoname);
3031 double videobitrate = double.Parse(MI.Get(StreamKind.General, 0, "BitRate"));
3032 double targetBitrate = (double)BlackBitrateNum.Value;
3034 //验证
3035 if (!File.Exists(BlackVideoTextBox.Text) || Path.GetExtension(BlackVideoTextBox.Text) != ".flv")
3037 MessageBox.Show("请选择FLV视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3038 return;
3040 if (!File.Exists(BlackPicTextBox.Text) && BlackNoPicCheckBox.Checked == false)
3042 MessageBox.Show("请选择图片文件或勾选使用黑屏", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3043 return;
3045 if (BlackOutputTextBox.Text == "")
3047 MessageBox.Show("请选择输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3048 return;
3051 if (videobitrate < 1000000)
3053 MessageBox.Show("此视频不需要后黑。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
3054 return;
3056 if (videobitrate > 2500000)
3058 MessageBox.Show("此视频码率过大,请先压制再后黑。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
3059 return;
3063 //处理图片
3064 int videoWidth = int.Parse(MI.Get(StreamKind.Video, 0, "Width"));
3065 int videoHeight = int.Parse(MI.Get(StreamKind.Video, 0, "Height"));
3066 if (BlackNoPicCheckBox.Checked)
3068 Bitmap bm = new Bitmap(videoWidth, videoHeight);
3069 Graphics g = Graphics.FromImage(bm);
3070 //g.FillRectangle(Brushes.White, new Rectangle(0, 0, 800, 600));
3071 g.Clear(Color.Black);
3072 bm.Save(tempPic, ImageFormat.Jpeg);
3073 g.Dispose();
3074 bm.Dispose();
3076 else
3078 System.Drawing.Image img = System.Drawing.Image.FromFile(BlackPicTextBox.Text);
3079 int sourceWidth = img.Width;
3080 int sourceHeight = img.Height;
3081 if (img.Width % 2 != 0 || img.Height % 2 != 0)
3083 MessageBox.Show("图片的长和宽必须都是偶数。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3084 img.Dispose();
3085 return;
3087 if (img.Width != videoWidth || img.Height != videoHeight)
3089 MessageBox.Show("图片的长和宽和视频不一致。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3090 img.Dispose();
3091 return;
3093 if (img.RawFormat.Equals(ImageFormat.Jpeg))
3095 File.Copy(BlackPicTextBox.Text, tempPic, true);
3097 else
3099 System.Drawing.Imaging.Encoder ImageEncoder = System.Drawing.Imaging.Encoder.Quality;
3100 EncoderParameter ep = new EncoderParameter(ImageEncoder, 100L);
3101 EncoderParameters eps = new EncoderParameters(1);
3102 ImageCodecInfo ImageCoderType = getImageCoderInfo("image/jpeg");
3103 eps.Param[0] = ep;
3104 img.Save(tempPic, ImageCoderType, eps);
3105 //img.Save(tempPic, ImageFormat.Jpeg);
3108 int blackSecond = 300;
3109 //计算后黑时长
3110 if (BlackSecondComboBox.Text == "auto")
3112 int seconds = SecondsFromHHMMSS(MI.Get(StreamKind.General, 0, "Duration/String3"));
3113 double s = videobitrate / 1000.0 * (double)seconds / targetBitrate - (double)seconds;
3114 blackSecond = (int)s;
3115 BlackSecondComboBox.Text = blackSecond.ToString();
3117 else
3119 blackSecond = int.Parse(Regex.Replace(BlackSecondComboBox.Text.ToString(), @"\D", "")); //排除除数字外的所有字符
3122 //批处理
3123 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";
3124 mux += string.Format("flvbind \"{0}\" \"{1}\" black.flv\r\n", BlackOutputTextBox.Text, BlackVideoTextBox.Text);
3125 mux += "del black.flv\r\n";
3127 batpath = Path.Combine(workPath, Path.GetRandomFileName() + ".bat");
3128 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
3129 LogRecord(mux);
3130 Process.Start(batpath);
3133 private void BlackVideoTextBox_TextChanged(object sender, EventArgs e)
3135 string path = BlackVideoTextBox.Text;
3136 if (File.Exists(path))
3138 BlackOutputTextBox.Text = AddExt(path, "_black.flv");
3141 #endregion
3143 private void BlackNoPicCheckBox_CheckedChanged(object sender, EventArgs e)
3145 BlackPicTextBox.Enabled = !BlackNoPicCheckBox.Checked;
3146 BlackPicButton.Enabled = !BlackNoPicCheckBox.Checked;
3149 private void BlackSecondComboBox_SelectedIndexChanged(object sender, EventArgs e)
3151 if (BlackSecondComboBox.Text != "auto")
3153 BlackBitrateNum.Enabled = false;
3155 else
3157 BlackBitrateNum.Enabled = true;
3161 private void SetDefaultButton_Click(object sender, EventArgs e)
3163 InitParameter();
3166 //Ctrl+A 可以全选文本
3167 private void MediaInfoTextBox_KeyDown(object sender, KeyEventArgs e)
3169 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
3171 ((TextBox)sender).SelectAll();
3175 private void AVSScriptTextBox_KeyDown(object sender, KeyEventArgs e)
3177 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
3179 ((TextBox)sender).SelectAll();
3183 private void x264CustomParameterTextBox_KeyDown(object sender, KeyEventArgs e)
3185 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
3187 ((TextBox)sender).SelectAll();
3191 private void CheckUpdateButton_Click(object sender, EventArgs e)
3193 WebRequest request = WebRequest.Create("http://hi.baidu.com/xiaowanmaruko/item/119203f757097c603c148502");
3194 request.Credentials = CredentialCache.DefaultCredentials;
3195 // Get the response.
3196 request.BeginGetResponse(new AsyncCallback(OnResponse), request);
3199 protected void OnResponse(IAsyncResult ar)
3201 WebRequest wrq = (WebRequest)ar.AsyncState;
3202 WebResponse wrs = wrq.EndGetResponse(ar);
3203 // read the response ...
3204 Stream dataStream = wrs.GetResponseStream();
3205 // Open the stream using a StreamReader for easy access.
3206 StreamReader reader = new StreamReader(dataStream);
3207 // Read the content.
3208 string responseFromServer = reader.ReadToEnd();
3209 Regex reg = new Regex(@"Maruko20\S+Maruko");
3210 Match m = reg.Match(responseFromServer);
3211 if (m.Success)
3213 string a = m.Value.Replace("Maruko", "");
3214 DateTime NewDate = DateTime.Parse(a);
3215 //DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
3216 int s = DateTime.Compare(NewDate, ReleaseDate);
3217 if (s == 1) //NewDate is later than ReleaseDate
3219 DialogResult dr = MessageBox.Show(string.Format("新鲜小丸已于{0}上架,主人不来尝一口咩?", NewDate.ToString("yyyy-M-d")), "Info", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
3220 if (dr == DialogResult.Yes)
3222 Process.Start("http://maruko.appinn.me");
3224 else
3226 return;
3229 else
3231 MessageBox.Show("喵~伦家已经是最新版啦!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
3236 private void x264ShutdownCheckBox_CheckedChanged(object sender, EventArgs e)
3238 shutdownState = x264ShutdownCheckBox.Checked;
3241 private void TrayModeCheckBox_CheckedChanged(object sender, EventArgs e)
3243 trayMode = TrayModeCheckBox.Checked;