modify UI
[marukotoolbox.git] / mp4box / MainForm.cs
blob6578deddefdcec74632af808d499c8d8d01b037d
1 // ------------------------------------------------------------------
2 // Copyright (C) 2011-2015 Maruko Toolbox Project
3 //
4 // Authors: komaruchan <sandy_0308@hotmail.com>
5 // LunarShaddow <aflyhorse@hotmail.com>
6 // LYF <lyfjxymf@sina.com>
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
17 // express or implied.
18 // See the License for the specific language governing permissions
19 // and limitations under the License.
20 // -------------------------------------------------------------------
23 using ControlExs;
24 using MediaInfoLib;
25 using System;
26 using System.Collections.Generic;
27 using System.ComponentModel;
28 using System.Configuration;
29 using System.Diagnostics;
30 using System.Drawing;
31 using System.Drawing.Imaging;
32 using System.IO;
33 using System.Linq;
34 using System.Net;
35 using System.Reflection;
36 using System.Runtime.InteropServices;
37 using System.Runtime.Remoting.Messaging;
38 using System.Text;
39 using System.Text.RegularExpressions;
40 using System.Threading;
41 using System.Windows.Forms;
42 using System.Xml.Linq;
44 namespace mp4box
46 public partial class MainForm : FormBase
48 public string workPath = "!undefined";
49 public bool shutdownState = false;
50 public bool trayMode = false;
51 XDocument xdoc;
52 #region Private Members Declaration
54 private StringBuilder avsBuilder = new StringBuilder(1000);
55 private string syspath = Environment.GetFolderPath(Environment.SpecialFolder.System).Remove(1);
56 private int indexofsource;
57 private int indexoftarget;
58 private byte mode = 1;
59 private string clip = "";
60 private string MIvideo = "";
61 private string namevideo = "";
62 private string namevideo2 = "";
64 //string namevideo3 = "";
65 private string namevideo4 = "";
67 private string namevideo5 = "";
68 private string namevideo6 = "";
69 private string nameaudio = "";
70 private string nameaudio2 = "";
71 private string nameaudio3 = "";
72 private string namevideo8 = "";
73 private string namevideo9 = "video";
74 private string nameout;
75 private string nameout2;
76 private string nameout3;
78 //string nameout4;
79 private string nameout5;
81 private string nameout6;
82 private string nameout9;
83 private string namesub;
84 private string namesub2 = "";
85 private string namesub9 = "subtitle";
86 private string MItext = "把视频文件拖到这里";
87 private string mkvextract;
88 private string mkvmerge;
89 private string mux;
90 private string x264;
91 private string ffmpeg;
92 private string aac;
93 private string aextract;
94 private string batpath;
95 private string auto;
96 private string startpath;
97 private string avs = "";
98 private string tempavspath = "";
99 private string tempPic = "";
100 private string logFileName, logPath;
101 private DateTime ReleaseDate = DateTime.Parse("2015-4-2 8:0:0");
103 #endregion Private Members Declaration
105 #region CPU Porocessors Number
107 [StructLayout(LayoutKind.Sequential)]
108 public struct SYSTEM_INFO
110 public uint dwOemId;
111 public uint dwPageSize;
112 public uint lpMinimumApplicationAddress;
113 public uint lpMaximumApplicationAddress;
114 public uint dwActiveProcessorMask;
115 public uint dwNumberOfProcessors;
116 public uint dwProcessorType;
117 public uint dwAllocationGranularity;
118 public uint dwProcessorLevel;
119 public uint dwProcessorRevision;
122 [DllImport("kernel32")]
123 private static extern void GetSystemInfo(ref SYSTEM_INFO pSI);
125 #endregion CPU Porocessors Number
127 public MainForm()
129 logPath = Application.StartupPath + "\\logs";
130 logFileName = logPath + "\\LogFile-" + DateTime.Now.ToString("yyyy'-'MM'-'dd'_'HH'-'mm'-'ss") + ".log";
131 InitializeComponent();
134 public string MediaInfo(string VideoName)
136 string info = "无视频信息";
137 if (File.Exists(VideoName))
139 MediaInfo MI = new MediaInfo();
140 MI.Open(VideoName);
141 //全局
142 string container = MI.Get(StreamKind.General, 0, "Format");
143 string bitrate = MI.Get(StreamKind.General, 0, "BitRate/String");
144 string duration = MI.Get(StreamKind.General, 0, "Duration/String1");
145 string fileSize = MI.Get(StreamKind.General, 0, "FileSize/String");
146 //视频
147 string vid = MI.Get(StreamKind.Video, 0, "ID");
148 string video = MI.Get(StreamKind.Video, 0, "Format");
149 string vBitRate = MI.Get(StreamKind.Video, 0, "BitRate/String");
150 string vSize = MI.Get(StreamKind.Video, 0, "StreamSize/String");
151 string width = MI.Get(StreamKind.Video, 0, "Width");
152 string height = MI.Get(StreamKind.Video, 0, "Height");
153 string risplayAspectRatio = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio/String");
154 string risplayAspectRatio2 = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio");
155 string frameRate = MI.Get(StreamKind.Video, 0, "FrameRate/String");
156 string bitDepth = MI.Get(StreamKind.Video, 0, "BitDepth/String");
157 string pixelAspectRatio = MI.Get(StreamKind.Video, 0, "PixelAspectRatio");
158 string encodedLibrary = MI.Get(StreamKind.Video, 0, "Encoded_Library");
159 string encodeTime = MI.Get(StreamKind.Video, 0, "Encoded_Date");
160 string codecProfile = MI.Get(StreamKind.Video, 0, "Codec_Profile");
161 string frameCount = MI.Get(StreamKind.Video, 0, "FrameCount");
163 //音频
164 string aid = MI.Get(StreamKind.Audio, 0, "ID");
165 string audio = MI.Get(StreamKind.Audio, 0, "Format");
166 string aBitRate = MI.Get(StreamKind.Audio, 0, "BitRate/String");
167 string samplingRate = MI.Get(StreamKind.Audio, 0, "SamplingRate/String");
168 string channel = MI.Get(StreamKind.Audio, 0, "Channel(s)");
169 string aSize = MI.Get(StreamKind.Audio, 0, "StreamSize/String");
171 string audioInfo = MI.Get(StreamKind.Audio, 0, "Inform") + MI.Get(StreamKind.Audio, 1, "Inform") + MI.Get(StreamKind.Audio, 2, "Inform") + MI.Get(StreamKind.Audio, 3, "Inform");
172 string videoInfo = MI.Get(StreamKind.Video, 0, "Inform");
174 info = Path.GetFileName(VideoName) + "\r\n" +
175 "容器:" + container + "\r\n" +
176 "总码率:" + bitrate + "\r\n" +
177 "大小:" + fileSize + "\r\n" +
178 "时长:" + duration + "\r\n" +
179 "\r\n" +
180 "视频(" + vid + "):" + video + "\r\n" +
181 "码率:" + vBitRate + "\r\n" +
182 "大小:" + vSize + "\r\n" +
183 "分辨率:" + width + "x" + height + "\r\n" +
184 "宽高比:" + risplayAspectRatio + "(" + risplayAspectRatio2 + ")" + "\r\n" +
185 "帧率:" + frameRate + "\r\n" +
186 "位深度:" + bitDepth + "\r\n" +
187 "像素宽高比:" + pixelAspectRatio + "\r\n" +
188 "编码库:" + encodedLibrary + "\r\n" +
189 "Profile:" + codecProfile + "\r\n" +
190 "编码时间:" + encodeTime + "\r\n" +
191 "总帧数:" + frameCount + "\r\n" +
193 "\r\n" +
194 "音频(" + aid + "):" + audio + "\r\n" +
195 "大小:" + aSize + "\r\n" +
196 "码率:" + aBitRate + "\r\n" +
197 "采样率:" + samplingRate + "\r\n" +
198 "声道数:" + channel + "\r\n" +
199 "\r\n====详细信息====\r\n" +
200 videoInfo + "\r\n" +
201 audioInfo + "\r\n"
203 MI.Close();
205 return info;
208 public string ffmuxbat(string input1, string input2, string output)
210 mux = "\"" + workPath + "\\ffmpeg.exe\" -i \"" + input1 + "\" -i \"" + input2 + "\" -sn -c copy -y \"" + output + "\"\r\n";
211 return mux;
214 public string x264bat(string input, string output)
216 //keyint设为fps的10倍
217 MediaInfo MI = new MediaInfo();
218 MI.Open(input);
219 string frameRate = MI.Get(StreamKind.Video, 0, "FrameRate");
220 double fps;
221 string keyint = "-1";
222 if (double.TryParse(frameRate, out fps))
224 fps = Math.Round(fps);
225 keyint = (fps * 10).ToString();
228 switch (mode)
230 case 1:
231 if (x264HeightNum.Value == 0 || x264WidthNum.Value == 0 || MaintainResolutionCheckBox.Checked)
233 x264 = "\"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " --crf " + x264CRFNum.Value + " --preset 8 --demuxer " + x264DemuxerComboBox.Text + " -I " + keyint + " -r 4 -b 3 --me umh -i 1 --scenecut 60 -f 1:1 --qcomp 0.5 --psy-rd 0.3:0 --aq-mode 2 --aq-strength 0.8 -o \"" + output + "\" \"" + input + "\"\r\n";
235 else
237 x264 = "\"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " --crf " + x264CRFNum.Value + " --preset 8 --demuxer " + x264DemuxerComboBox.Text + " -I " + keyint + " -r 4 -b 3 --me umh -i 1 --scenecut 60 -f 1:1 --qcomp 0.5 --psy-rd 0.3:0 --aq-mode 2 --aq-strength 0.8 --vf resize:" + x264WidthNum.Value + "," + x264HeightNum.Value + ",,,,lanczos -o \"" + output + "\" \"" + input + "\"\r\n";
239 break;
241 case 2:
242 if (x264HeightNum.Value == 0 || x264WidthNum.Value == 0 || MaintainResolutionCheckBox.Checked)
244 x264 = "\"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " -p1 -B " + x264BitrateNum.Value + " --preset 8 --demuxer " + x264DemuxerComboBox.Text + " -I " + keyint + " -r 4 -b 3 --me umh -i 1 --scenecut 60 -f 1:1 --qcomp 0.5 --psy-rd 0.3:0 --aq-mode 2 --aq-strength 0.8 -o NUL \"" + input + "\" && \"" +
245 workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " -p2 -B " + x264BitrateNum.Value + " --preset 8 --demuxer " + x264DemuxerComboBox.Text + " -I " + keyint + " -r 4 -b 3 --me umh -i 1 --scenecut 60 -f 1:1 --qcomp 0.5 --psy-rd 0.3:0 --aq-mode 2 --aq-strength 0.8 -o \"" + output + "\" \"" + input + "\"\r\n";
247 else
249 x264 = "\"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " -p1 -B " + x264BitrateNum.Value + " --preset 8 --demuxer " + x264DemuxerComboBox.Text + " -I " + keyint + " -r 4 -b 3 --me umh -i 1 --scenecut 60 -f 1:1 --qcomp 0.5 --psy-rd 0.3:0 --aq-mode 2 --aq-strength 0.8 --vf resize:" + x264WidthNum.Value + "," + x264HeightNum.Value + ",,,,lanczos -o NUL \"" + input + "\" && \"" +
250 workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " -p2 -B " + x264BitrateNum.Value + " --preset 8 --demuxer " + x264DemuxerComboBox.Text + " -I " + keyint + " -r 4 -b 3 --me umh -i 1 --scenecut 60 -f 1:1 --qcomp 0.5 --psy-rd 0.3:0 --aq-mode 2 --aq-strength 0.8 --vf resize:" + x264WidthNum.Value + "," + x264HeightNum.Value + ",,,,lanczos -o \"" + output + "\" \"" + input + "\"\r\n";
252 break;
254 case 0:
256 x264 = "\"" + workPath + "\\" + x264ExeComboBox.SelectedItem.ToString() + "\" --threads " + x264ThreadsComboBox.SelectedItem.ToString() + " " + x264CustomParameterTextBox.Text + " --demuxer " + x264DemuxerComboBox.Text + " -o \"" + output + "\" \"" + input + "\"\r\n";
258 break;
261 if (x264FpsComboBox.Text != "auto")
263 switch (x264FpsComboBox.Text)
265 case "23.976": x264 += " --fps 24000/1001"; break;
266 case "24": x264 += " --fps 24"; break;
267 case "25": x264 += " --fps 25"; break;
268 case "29.970": x264 += " --fps 30000/1001"; break;
269 case "30": x264 += " --fps 30"; break;
270 case "50": x264 += " --fps 50"; break;
271 case "59.940": x264 += " --fps 60000/1001"; break;
272 case "60": x264 += " --fps 60"; break;
273 default: x264 += " --fps " + x264FpsComboBox.Text; break;
275 x264 += "\r\n";
277 return x264;
280 public static bool stringCheck(string str, string info = "")
282 if (String.IsNullOrEmpty(str))
284 MessageBox.Show("发现空或者无效的字符串 " + info);
286 return String.IsNullOrEmpty(str);
289 public string timeminus(int h1, int m1, int s1, int h2, int m2, int s2)
291 int h = 0;
292 int m = 0;
293 int s = 0;
294 s = s2 - s1;
295 if (s < 0)
297 m = -1;
298 s = s + 60;
300 m = m + m2 - m1;
301 if (m < 0)
303 h = -1;
304 m = m + 60;
306 h = h + h2 - h1;
307 return h.ToString() + ":" + m.ToString() + ":" + s.ToString();
310 public string timeplus(int h1, int m1, int s1, int h2, int m2, int s2)
312 int h = 0;
313 int m = 0;
314 int s = 0;
315 s = s1 + s2;
316 if (s >= 60)
318 m = 1;
319 s = s - 60;
321 m = m + m1 + m2;
322 if (m >= 60)
324 h = 1;
325 m = m - 60;
327 h = h + h1 + h2;
328 return h.ToString() + ":" + m.ToString() + ":" + s.ToString();
331 public string audiobat(string input, string output)
333 int AACbr = 1000 * Convert.ToInt32(AudioBitrateComboBox.Text);
334 string br = AACbr.ToString();
335 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -i \"" + input + "\" -vn -sn -v 0 -c:a pcm_s16le -f wav pipe:|";
336 switch (AudioEncoderComboBox.SelectedIndex)
338 case 0:
339 if (AudioBitrateRadioButton.Checked)
341 ffmpeg += "\"" + workPath + "\\neroAacEnc.exe\" -ignorelength -lc -br " + br + " -if - -of \"" + output + "\"";
343 if (AudioCustomizeRadioButton.Checked)
345 ffmpeg += "\"" + workPath + "\\neroAacEnc.exe\" -ignorelength " + AudioCustomParameterTextBox.Text.ToString() + " -if - -of \"" + output + "\"";
347 break;
349 case 1:
350 if (AudioBitrateRadioButton.Checked)
352 ffmpeg += "\"" + workPath + "\\qaac.exe\" -q 2 --ignorelength -c " + AudioBitrateComboBox.Text + " - -o \"" + output + "\"";
354 if (AudioCustomizeRadioButton.Checked)
356 ffmpeg += "\"" + workPath + "\\qaac.exe\" --ignorelength " + AudioCustomParameterTextBox.Text.ToString() + " - -o \"" + output + "\"";
358 break;
360 case 2:
361 if (Path.GetExtension(output) == ".aac")
362 output = Util.ChangeExt(output, ".wav");
363 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + input + "\" -f wav \"" + output + "\"";
364 break;
366 case 3:
367 ffmpeg += "\"" + workPath + "\\refalac.exe\" --ignorelength - -o \"" + output + "\"";
368 break;
370 case 4:
371 ffmpeg += "\"" + workPath + "\\flac.exe\" -f --ignore-chunk-sizes -5 - -o \"" + output + "\"";
372 break;
374 case 5:
375 if (AudioBitrateRadioButton.Checked)
377 ffmpeg += "\"" + workPath + "\\fdkaac.exe\" --ignorelength -b " + AudioBitrateComboBox.Text + " - -o \"" + output + "\"";
379 if (AudioCustomizeRadioButton.Checked)
381 ffmpeg += "\"" + workPath + "\\fdkaac.exe\" --ignorelength " + AudioCustomParameterTextBox.Text.ToString() + " - -o \"" + output + "\"";
383 break;
384 case 6:
385 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -i \"" + input + "\" -c:a ac3 -b:a " + AudioBitrateComboBox.Text.ToString() + "k \"" + output + "\"";
386 break;
388 case 7:
389 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -i \"" + input + "\" -vn -sn -c:a copy -y -map 0:a:0 " + "\"" + output + "\"";
390 break;
392 default:
393 break;
395 aac = ffmpeg + "\r\n";
396 return aac;
399 private void btnaudio_Click(object sender, EventArgs e)
401 openFileDialog1.Filter = "音频(*.mp4;*.aac;*.mp2;*.mp3;*.m4a;*.ac3)|*.mp4;*.aac;*.mp2;*.mp3;*.m4a;*.ac3|所有文件(*.*)|*.*";
402 DialogResult result = openFileDialog1.ShowDialog();
403 if (result == DialogResult.OK)
405 nameaudio = openFileDialog1.FileName;
406 txtaudio.Text = nameaudio;
410 private void btnvideo_Click(object sender, EventArgs e)
412 openFileDialog1.Filter = "视频(*.avi;*.mp4;*.m1v;*.m2v;*.m4v;*.264;*.h264;*.hevc)|*.avi;*.mp4;*.m1v;*.m2v;*.m4v;*.264;*.h264;*.hevc|所有文件(*.*)|*.*";
413 DialogResult result = openFileDialog1.ShowDialog();
414 if (result == DialogResult.OK)
416 namevideo = openFileDialog1.FileName;
417 txtvideo.Text = namevideo;
421 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
425 private void btnout_Click(object sender, EventArgs e)
427 SaveFileDialog savefile = new SaveFileDialog();
428 savefile.Filter = "视频(*.mp4)|*.mp4";
429 DialogResult result = savefile.ShowDialog();
430 if (result == DialogResult.OK)
432 nameout = savefile.FileName;
433 txtout.Text = nameout;
437 private void btnmux_Click(object sender, EventArgs e)
439 if (namevideo == "")
441 ShowErrorMessage("请选择视频文件");
442 return;
444 //else if (nameaudio == "")
446 // MessageBox.Show("请选择音频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
448 if (nameout == "")
450 ShowErrorMessage("请选择输出文件");
451 return;
453 if (cbFPS.Text == "auto")
455 mux = "\"" + workPath + "\\mp4box.exe\" -add \"" + namevideo + "#trackID=1:par=" + Mp4BoxParComboBox.Text + ":name=\"" + " -add \"" + nameaudio + ":name=\" -new \"" + nameout + "\" \r\n cmd";
457 else
459 mux = "\"" + workPath + "\\mp4box.exe\" -add \"" + namevideo + "#trackID=1:par=" + Mp4BoxParComboBox.Text + ":fps=" + cbFPS.Text + ":name=\"" + " -add \"" + nameaudio + ":name=\" -new \"" + nameout + "\" \r\n cmd";
462 if (nameaudio == "") //如果没有音频流
464 mux = mux.Replace("-add \"\"", "");
467 batpath = workPath + "\\mux.bat";
468 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
469 LogRecord(mux);
470 Process.Start(batpath);
473 private void btnaextract_Click(object sender, EventArgs e)
475 //MP4 抽取音频1
476 ExtractAV(namevideo, "a", 0);
477 //if (namevideo == "")
479 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
481 //else
483 // //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 2 \"" + namevideo + "\"";
484 // aextract = "";
485 // aextract += Cmd.FormatPath(workPath + "\\ffmpeg.exe");
486 // aextract += " -i " + Cmd.FormatPath(namevideo);
487 // aextract += " -vn -sn -c:a:0 copy ";
488 // string outfile = Cmd.GetDir(namevideo) +
489 // Path.GetFileNameWithoutExtension(namevideo) + "_抽取音频1" + Path.GetExtension(namevideo);
490 // aextract += Cmd.FormatPath(outfile);
491 // batpath = workPath + "\\aextract.bat";
492 // File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
493 // LogRecord(aextract);
494 // System.Diagnostics.Process.Start(batpath);
498 private void ExtractAV(string namevideo, string av, int streamIndex)
500 if (string.IsNullOrEmpty(namevideo))
502 ShowErrorMessage("请选择视频文件");
503 return;
506 string ext = Path.GetExtension(namevideo);
507 //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 2 \"" + namevideo + "\"";
508 string aextract = "";
509 aextract += Util.FormatPath(workPath + "\\ffmpeg.exe");
510 aextract += " -i " + Util.FormatPath(namevideo);
511 if (av == "a")
513 aextract += " -vn -sn -c:a copy -y -map 0:a:" + streamIndex + " ";
515 MediaInfo MI = new MediaInfo();
516 MI.Open(namevideo);
517 string audioFormat = MI.Get(StreamKind.Audio, streamIndex, "Format");
518 string audioProfile = MI.Get(StreamKind.Audio, streamIndex, "Format_Profile");
519 if (!string.IsNullOrEmpty(audioFormat))
521 if (audioFormat.Contains("MPEG") && audioProfile == "Layer 3")
522 ext = ".mp3";
523 else if (audioFormat.Contains("MPEG") && audioProfile == "Layer 2")
524 ext = ".mp2";
525 else if (audioFormat.Contains("PCM")) //flv support(PCM_U8 * PCM_S16BE * PCM_MULAW * PCM_ALAW * ADPCM_SWF)
526 ext = ".wav";
527 else if (audioFormat == "AAC")
528 ext = ".aac";
529 else if (audioFormat == "AC3")
530 ext = ".ac3";
531 else if (audioFormat == "ALAC")
532 ext = ".m4a";
533 else
534 ext = ".mka";
536 else
538 ShowInfoMessage("该轨道无音频");
539 return;
542 else if (av == "v")
544 aextract += " -an -sn -c:v copy -y -map 0:v:" + streamIndex + " ";
546 else
548 throw new Exception("未知流!");
550 string suf = "_audio_";
551 if (av == "v")
553 suf = "_video_";
555 suf += "index" + streamIndex;
556 string outfile = Util.GetDir(namevideo) +
557 Path.GetFileNameWithoutExtension(namevideo) + suf + ext;
558 aextract += Util.FormatPath(outfile);
559 //aextract = vextract;
560 batpath = workPath + "\\" + av + "extract.bat";
561 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
562 LogRecord(aextract);
563 System.Diagnostics.Process.Start(batpath);
566 private void ExtractTrack(string namevideo, int streamIndex)
568 if (string.IsNullOrEmpty(namevideo))
570 ShowErrorMessage("请选择视频文件");
571 return;
574 //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 2 \"" + namevideo + "\"";
575 string aextract = "";
576 aextract += Util.FormatPath(workPath + "\\ffmpeg.exe");
577 aextract += " -i " + Util.FormatPath(namevideo);
578 aextract += " -map 0:" + streamIndex + " -c copy ";
579 string suf = "_抽取流Index" + streamIndex;
580 string outfile = Util.GetDir(namevideo) +
581 Path.GetFileNameWithoutExtension(namevideo) + suf + '.' +
582 FormatExtractor.Extract(workPath, namevideo)[streamIndex].Format;
583 aextract += Util.FormatPath(outfile);
584 batpath = workPath + "\\mkvextract.bat";
585 File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
586 LogRecord(aextract);
587 System.Diagnostics.Process.Start(batpath);
590 private void button1_Click(object sender, EventArgs e)
592 ShowInfoMessage(String.Format(" \r\n有任何建议或疑问可以通过以下方式联系小丸。\nQQ:57655408\n微博:weibo.com/xiaowan3\n百度贴吧ID:小丸到达\n\n\t\t\t发布日期:2012年10月17日\n\t\t\t- ( ゜- ゜)つロ 乾杯~"), "关于");
595 private void btnvextract_Click(object sender, EventArgs e)
597 //MP4抽取视频1
598 ExtractAV(namevideo, "v", 0);
599 //if (namevideo == "")
601 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
603 //else
605 // //vextract = "\"" + workPath + "\\mp4box.exe\" -raw 1 \"" + namevideo + "\"";
606 // vextract = "";
607 // vextract += Cmd.FormatPath(workPath + "\\ffmpeg.exe");
608 // vextract += " -i " + Cmd.FormatPath(namevideo);
609 // vextract += " -an -sn -c:v:0 copy ";
610 // string outfile = Cmd.GetDir(namevideo) +
611 // Path.GetFileNameWithoutExtension(namevideo) + "_抽取视频1" + Path.GetExtension(namevideo);
612 // vextract += Cmd.FormatPath(outfile);
613 // batpath = workPath + "\\vextract.bat";
614 // File.WriteAllText(batpath, vextract, UnicodeEncoding.Default);
615 // LogRecord(vextract);
616 // System.Diagnostics.Process.Start(batpath);
620 private void txtvideo_TextChanged(object sender, EventArgs e)
624 if (txtvideo.Text.Trim().Length > 0)
626 if (!File.Exists(txtvideo.Text.Trim()))
628 throw new Exception("输入文件: \r\n\r\n" + txtvideo.Text.Trim() + "\r\n\r\n不存在!");
630 string inputExt = Path.GetExtension(txtvideo.Text.Trim()).ToLower();
631 if (inputExt != ".avi" //Only MPEG-4 SP/ASP video and MP3 audio supported at the current time. To import AVC/H264 video, you must first extract the avi track.
632 && inputExt != ".mp4" //MPEG-4 Video
633 && inputExt != ".m1v" //MPEG-1 Video
634 && inputExt != ".m2v" //MPEG-2 Video
635 && inputExt != ".m4v" //MPEG-4 Video
636 && inputExt != ".264" //AVC/H264 Video
637 && inputExt != ".h264" //AVC/H264 Video
638 && inputExt != ".hevc") //HEVC/H265 Video
640 throw new Exception("输入文件: \r\n\r\n" + txtvideo.Text.Trim() + "\r\n\r\n是一个mp4box不支持的视频文件!");
642 if (inputExt == ".264" || inputExt == ".h264" || inputExt == ".hevc")
644 ShowWarningMessage("H.264或者HEVC流文件需要设定fps,不设置将默认为25fps");
646 namevideo = txtvideo.Text;
647 txtout.Text = Util.ChangeExt(txtvideo.Text, "_Mux.mp4");
650 catch (Exception ex)
652 txtvideo.Text = string.Empty;
653 ShowErrorMessage(ex.Message);
657 private void txtaudio_TextChanged(object sender, EventArgs e)
661 if (txtaudio.Text.Trim().Length > 0)
663 if (!File.Exists(txtaudio.Text.Trim()))
665 throw new Exception("输入文件: \r\n\r\n" + txtaudio.Text.Trim() + "\r\n\r\n不存在!");
667 string inputExt = Path.GetExtension(txtaudio.Text.Trim()).ToLower();
668 if (inputExt != ".mp4"
669 && inputExt != ".aac" //ADIF or RAW formats not supported
670 && inputExt != ".mp3"
671 && inputExt != ".m4a"
672 && inputExt != ".mp2"
673 && inputExt != ".ac3")
675 throw new Exception("输入文件: \r\n\r\n" + txtaudio.Text.Trim() + "\r\n\r\n是一个mp4box不支持的音频文件!");
677 nameaudio = txtaudio.Text;
680 catch (Exception ex)
682 txtaudio.Text = string.Empty;
683 ShowErrorMessage(ex.Message);
687 private void txtout_TextChanged(object sender, EventArgs e)
689 nameout = txtout.Text;
692 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
694 #region Delete Temp Files
696 if (SetupDeleteTempFileCheckBox.Checked && !workPath.Equals("!undefined"))
698 List<string> deleteFileList = new List<string>();
700 string systemDisk = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 3);
701 string systemTempPath = systemDisk + @"windows\temp";
703 //Delete all BAT files
704 DirectoryInfo theFolder = new DirectoryInfo(workPath);
705 foreach (FileInfo NextFile in theFolder.GetFiles())
707 if (NextFile.Extension.Equals(".bat"))
708 deleteFileList.Add(NextFile.FullName);
711 //string[] deletedfiles = { tempPic, "msg.vbs", tempavspath, "temp.avs", "clip.bat", "aextract.bat", "vextract.bat",
712 // "x264.bat", "aac.bat", "auto.bat", "mux.bat", "flv.bat", "mkvmerge.bat", "mkvextract.bat", "tmp.stat.mbtree", "tmp.stat" };
713 string[] deletedfiles = { "temp.wav", "temp.aac", "temp.mp4", "concat.txt", tempPic, tempavspath, workPath + "msg.vbs", startpath + "\\x264_2pass.log.mbtree", startpath + "\\x264_2pass.log" };
714 deleteFileList.AddRange(deletedfiles);
716 foreach (string file in deleteFileList)
718 File.Delete(file);
722 #endregion Delete Temp Files
724 #region Save Settings
726 SaveSettings();
728 #endregion Save Settings
731 private void txtvideo4_TextChanged(object sender, EventArgs e)
733 if (File.Exists(txtvideo4.Text.ToString()))
735 namevideo4 = txtvideo4.Text;
736 //string finish = namevideo4.Insert(namevideo4.LastIndexOf(".")-1,"");
737 //string ext = namevideo4.Substring(namevideo4.LastIndexOf(".") + 1, 3);
738 //finish += "_clip." + ext;
739 string finish = namevideo4.Insert(namevideo4.LastIndexOf("."), "_output");
740 txtout5.Text = finish;
744 private void txtout5_TextChanged(object sender, EventArgs e)
746 nameout5 = txtout5.Text;
749 private void btnvideo4_Click(object sender, EventArgs e)
751 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
752 DialogResult result = openFileDialog1.ShowDialog();
753 if (result == DialogResult.OK)
755 namevideo4 = openFileDialog1.FileName;
756 txtvideo4.Text = namevideo4;
760 private void btnout5_Click(object sender, EventArgs e)
762 SaveFileDialog savefile = new SaveFileDialog();
763 savefile.Filter = "视频(*.*)|*.*";
764 DialogResult result = savefile.ShowDialog();
765 if (result == DialogResult.OK)
767 nameout5 = savefile.FileName;
768 txtout5.Text = nameout5;
772 public static bool IsWindowsVistaOrNewer
774 get { return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 6); }
777 #region common
779 /// <summary>
780 /// 还原默认参数
781 /// </summary>
782 private void InitParameter()
784 x264CRFNum.Value = 24;
785 x264BitrateNum.Value = 800;
786 x264AudioParameterTextBox.Text = "--abitrate 128";
787 x264AudioModeComboBox.SelectedIndex = 0;
788 x264DemuxerComboBox.SelectedIndex = 2;
789 x264WidthNum.Value = 0;
790 x264HeightNum.Value = 0;
791 x264CustomParameterTextBox.Text = "";
792 x264PriorityComboBox.SelectedIndex = 2;
793 AudioEncoderComboBox.SelectedIndex = 0;
794 AudioCustomParameterTextBox.Text = "";
795 AudioBitrateComboBox.Text = "128";
796 OnePicAudioBitrateNum.Value = 128;
797 OnePicFPSNum.Value = 1;
798 OnePicCRFNum.Value = 24;
799 AVSScriptTextBox.Text = "";
800 BlackFPSNum.Value = 1;
801 BlackCRFNum.Value = 51;
802 BlackBitrateNum.Value = 900;
803 SetupDeleteTempFileCheckBox.Checked = true;
804 TransposeComboBox.SelectedIndex = 1;
807 private void LoadSettings()
811 //load settings
812 x264CRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264CRF"]);
813 x264BitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Bitrate"]);
814 x264AudioParameterTextBox.Text = ConfigurationManager.AppSettings["x264AudioParameter"];
815 x264AudioModeComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264AudioMode"]);
816 x264ExeComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Exe"]);
817 x264DemuxerComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Demuxer"]);
818 x264WidthNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Width"]);
819 x264HeightNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["x264Height"]);
820 x264CustomParameterTextBox.Text = ConfigurationManager.AppSettings["x264CustomParameter"];
821 x264PriorityComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Priority"]);
822 AVSScriptTextBox.Text = ConfigurationManager.AppSettings["AVSScript"];
823 AudioEncoderComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["AudioEncoder"]);
824 AudioCustomParameterTextBox.Text = ConfigurationManager.AppSettings["AudioCustomParameter"];
825 AudioBitrateComboBox.Text = ConfigurationManager.AppSettings["AudioBitrate"];
826 OnePicAudioBitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicAudioBitrate"]);
827 OnePicFPSNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicFPS"]);
828 OnePicCRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["OnePicCRF"]);
829 BlackFPSNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackFPS"]);
830 BlackCRFNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackCRF"]);
831 BlackBitrateNum.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["BlackBitrate"]);
832 SetupDeleteTempFileCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["SetupDeleteTempFile"]);
833 CheckUpdateCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["CheckUpdate"]);
834 x264ThreadsComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["x264Threads"]);
835 TrayModeCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["TrayMode"]);
836 SplashScreenCheckBox.Checked = Convert.ToBoolean(ConfigurationManager.AppSettings["SplashScreen"]);
837 SetupPlayerTextBox.Text = ConfigurationManager.AppSettings["PreviewPlayer"];
838 string SubLangExt = Convert.ToString(ConfigurationManager.AppSettings["SubLanguageExtension"]);
839 MuxFormatComboBox.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["MuxFormat"]);
840 x264BatchSubSpecialLanguage.DataSource = SubLangExt.Split(',');
841 if (x264ExeComboBox.SelectedIndex == -1)
843 x264ExeComboBox.SelectedIndex = x264ExeComboBox.Items.IndexOf("x264_32-8bit");
846 if (int.Parse(ConfigurationManager.AppSettings["LanguageIndex"]) == -1) //First Startup
848 string culture = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
849 switch (culture)
851 case "zh-CN":
852 languageComboBox.SelectedIndex = 0;
853 break;
855 case "zh-SG":
856 languageComboBox.SelectedIndex = 0;
857 break;
859 case "zh-TW":
860 languageComboBox.SelectedIndex = 1;
861 break;
863 case "zh-HK ":
864 languageComboBox.SelectedIndex = 1;
865 break;
867 case "zh-MO":
868 languageComboBox.SelectedIndex = 1;
869 break;
871 case "en-US":
872 languageComboBox.SelectedIndex = 2;
873 break;
875 case "ja-JP":
876 languageComboBox.SelectedIndex = 3;
877 break;
879 default:
880 break;
883 else
884 languageComboBox.SelectedIndex = int.Parse(ConfigurationManager.AppSettings["LanguageIndex"]);
886 if (CheckUpdateCheckBox.Checked && Util.IsConnectInternet())
888 DateTime d;
889 bool f;
890 CheckUpadateDelegate checkUpdateDelegate = CheckUpdate;
891 checkUpdateDelegate.BeginInvoke(out d, out f, new AsyncCallback(CheckUpdateCallBack), null);
893 x264ExeComboBox_SelectedIndexChanged(null, null);
895 catch (Exception)
897 throw;
901 private void SaveSettings()
903 Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
904 cfa.AppSettings.Settings["x264CRF"].Value = x264CRFNum.Value.ToString();
905 cfa.AppSettings.Settings["x264Bitrate"].Value = x264BitrateNum.Value.ToString();
906 cfa.AppSettings.Settings["x264AudioParameter"].Value = x264AudioParameterTextBox.Text;
907 cfa.AppSettings.Settings["x264AudioMode"].Value = x264AudioModeComboBox.SelectedIndex.ToString();
908 cfa.AppSettings.Settings["x264Exe"].Value = x264ExeComboBox.SelectedIndex.ToString();
909 cfa.AppSettings.Settings["x264Demuxer"].Value = x264DemuxerComboBox.SelectedIndex.ToString();
910 cfa.AppSettings.Settings["x264Width"].Value = x264WidthNum.Value.ToString();
911 cfa.AppSettings.Settings["x264Height"].Value = x264HeightNum.Value.ToString();
912 cfa.AppSettings.Settings["x264CustomParameter"].Value = x264CustomParameterTextBox.Text;
913 cfa.AppSettings.Settings["x264Priority"].Value = x264PriorityComboBox.SelectedIndex.ToString();
914 cfa.AppSettings.Settings["AVSScript"].Value = AVSScriptTextBox.Text;
915 cfa.AppSettings.Settings["AudioEncoder"].Value = AudioEncoderComboBox.SelectedIndex.ToString();
916 cfa.AppSettings.Settings["AudioCustomParameter"].Value = AudioCustomParameterTextBox.Text;
917 cfa.AppSettings.Settings["AudioParameter"].Value = AudioBitrateComboBox.Text;
918 cfa.AppSettings.Settings["OnePicAudioBitrate"].Value = OnePicAudioBitrateNum.Value.ToString();
919 cfa.AppSettings.Settings["OnePicFPS"].Value = OnePicFPSNum.Value.ToString();
920 cfa.AppSettings.Settings["OnePicCRF"].Value = OnePicCRFNum.Value.ToString();
921 cfa.AppSettings.Settings["BlackFPS"].Value = BlackFPSNum.Value.ToString();
922 cfa.AppSettings.Settings["BlackCRF"].Value = BlackCRFNum.Value.ToString();
923 cfa.AppSettings.Settings["BlackBitrate"].Value = BlackBitrateNum.Value.ToString();
924 cfa.AppSettings.Settings["SetupDeleteTempFile"].Value = SetupDeleteTempFileCheckBox.Checked.ToString();
925 cfa.AppSettings.Settings["CheckUpdate"].Value = CheckUpdateCheckBox.Checked.ToString();
926 cfa.AppSettings.Settings["TrayMode"].Value = TrayModeCheckBox.Checked.ToString();
927 cfa.AppSettings.Settings["LanguageIndex"].Value = languageComboBox.SelectedIndex.ToString();
928 cfa.AppSettings.Settings["SplashScreen"].Value = SplashScreenCheckBox.Checked.ToString();
929 cfa.AppSettings.Settings["x264Threads"].Value = x264ThreadsComboBox.SelectedIndex.ToString();
930 cfa.AppSettings.Settings["PreviewPlayer"].Value = SetupPlayerTextBox.Text;
931 cfa.AppSettings.Settings["MuxFormat"].Value = MuxFormatComboBox.SelectedIndex.ToString(); ;
932 cfa.Save();
933 ConfigurationManager.RefreshSection("appSettings"); // 刷新命名节,在下次检索它时将从磁盘重新读取它。记住应用程序要刷新节点
936 #endregion common
938 private void Form1_Load(object sender, EventArgs e)
940 SYSTEM_INFO pSI = new SYSTEM_INFO();
941 GetSystemInfo(ref pSI);
942 int processorNumber = (int)pSI.dwNumberOfProcessors;
944 x264ThreadsComboBox.Items.Add("auto");
945 for (int i = 1; i <= 32; i++)
947 x264ThreadsComboBox.Items.Add(i.ToString());
949 //Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-TW");
950 //use YAHEI in VistaOrNewer
951 //if (IsWindowsVistaOrNewer)
953 // FontFamily myFontFamily = new FontFamily("微软雅黑"); //采用哪种字体
954 // Font myFont = new Font(myFontFamily, 9, FontStyle.Regular); //字是那种字体,显示的风格
955 // this.Font = myFont;
958 //define workpath
959 startpath = System.Windows.Forms.Application.StartupPath;
960 workPath = startpath + "\\tools";
961 if (!Directory.Exists(workPath))
963 MessageBox.Show("tools文件夹没有解压喔~ 工具箱里没有工具的话运行不起来的喔~", "(这只丸子)",
964 MessageBoxButtons.OK, MessageBoxIcon.Error);
965 Environment.Exit(1);
967 //Directory.CreateDirectory(workPath);
968 //string diskSymbol = startpath.Substring(0, 1);
970 //string systemDisk = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 3);
971 //string systemTempPath = systemDisk + @"windows\temp";
972 string systemTempPath = Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.Machine);
973 tempavspath = systemTempPath + "\\temp.avs";
974 tempPic = systemTempPath + "\\marukotemp.jpg";
975 InitParameter();
977 //load x264 exe
978 DirectoryInfo folder = new DirectoryInfo(workPath);
979 List<string> x264exe = new List<string>();
980 foreach (FileInfo FileName in folder.GetFiles())
982 if ((FileName.Name.ToLower().Contains("x264") || FileName.Name.ToLower().Contains("ffmpeg")) && Path.GetExtension(FileName.Name) == ".exe")
984 x264exe.Add(FileName.Name);
987 x264exe = x264exe.OrderByDescending(i => i.Substring(7)).ToList();
988 x264ExeComboBox.Items.AddRange(x264exe.ToArray());
990 //load AVS filter
991 DirectoryInfo avspath = new DirectoryInfo(workPath + "\\avsfilter");
992 List<string> avsfilters = new List<string>();
993 foreach (FileInfo FileName in avspath.GetFiles())
995 if (Path.GetExtension(FileName.Name) == ".dll")
997 avsfilters.Add(FileName.Name);
1000 AVSFilterComboBox.Items.AddRange(avsfilters.ToArray());
1002 //ReleaseDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
1003 ReleaseDatelabel.Text = ReleaseDate.ToString("yyyy-M-d");
1005 ////load Help Text
1006 if (File.Exists(startpath + "\\help.rtf"))
1008 HelpTextBox.LoadFile(startpath + "\\help.rtf");
1011 LoadSettings();
1013 //create directory
1014 string preset = workPath + "\\preset";
1015 if (!Directory.Exists(preset))
1016 Directory.CreateDirectory(preset);
1017 DirectoryInfo TheFolder = new DirectoryInfo(preset);
1018 foreach (FileInfo FileName in TheFolder.GetFiles())
1020 VideoPresetComboBox.Items.Add(FileName.Name.Replace(".txt", ""));
1022 if (File.Exists("preset.xml"))
1024 xdoc = XDocument.Load("preset.xml");
1025 XElement xAudios = xdoc.Element("root").Element("Audio");
1026 foreach (XElement item in xAudios.Elements())
1028 AudioPresetComboBox.Items.Add(item.Attribute("Name").Value);
1029 AudioPresetComboBox.SelectedIndex = 0;
1034 private void button2_Click(object sender, EventArgs e)
1036 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
1037 DialogResult result = openFileDialog1.ShowDialog();
1038 if (result == DialogResult.OK)
1040 namevideo6 = openFileDialog1.FileName;
1041 txtvideo6.Text = namevideo6;
1045 private void button3_Click(object sender, EventArgs e)
1047 if (namevideo6 == "")
1049 ShowErrorMessage("请选择视频文件");
1051 else
1053 mkvextract = workPath + "\\ mkvextract.exe tracks \"" + namevideo6 + "\" 1:video.h264 2:audio.aac";
1054 batpath = workPath + "\\mkvextract.bat";
1055 File.WriteAllText(batpath, mkvextract, UnicodeEncoding.Default);
1056 System.Diagnostics.Process.Start(batpath);
1060 private void button4_Click(object sender, EventArgs e)
1062 openFileDialog1.Filter = "视频(*.mp4)|*.mp4|所有文件(*.*)|*.*";
1063 DialogResult result = openFileDialog1.ShowDialog();
1064 if (result == DialogResult.OK)
1066 namevideo5 = openFileDialog1.FileName;
1067 txtvideo5.Text = namevideo5;
1071 private void button5_Click(object sender, EventArgs e)
1073 openFileDialog1.Filter = "音频(*.mp3)|*.mp3|音频(*.aac)|*.aac|所有文件(*.*)|*.*";
1074 DialogResult result = openFileDialog1.ShowDialog();
1075 if (result == DialogResult.OK)
1077 nameaudio3 = openFileDialog1.FileName;
1078 txtaudio3.Text = nameaudio3;
1082 private void button6_Click(object sender, EventArgs e)
1084 SaveFileDialog savefile = new SaveFileDialog();
1085 savefile.Filter = "视频(*.mkv)|*.mkv";
1086 DialogResult result = savefile.ShowDialog();
1087 if (result == DialogResult.OK)
1089 nameout6 = savefile.FileName;
1090 txtout6.Text = nameout6;
1094 private void button7_Click(object sender, EventArgs e)
1096 if (namevideo5 == "")
1098 ShowErrorMessage("请选择视频文件");
1100 else if (nameaudio3 == "")
1102 ShowErrorMessage("请选择音频文件");
1104 else if (nameout6 == "")
1106 ShowErrorMessage("请选择输出文件");
1108 else
1110 mkvmerge = workPath + "\\mkvmerge.exe -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\"";
1111 batpath = workPath + "\\mkvmerge.bat";
1112 File.WriteAllText(batpath, mkvmerge, UnicodeEncoding.Default);
1113 System.Diagnostics.Process.Start(batpath);
1117 private void button2_Click_1(object sender, EventArgs e)
1119 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1120 DialogResult result = openFileDialog1.ShowDialog();
1121 if (result == DialogResult.OK)
1123 namevideo5 = openFileDialog1.FileName;
1124 txtvideo5.Text = namevideo5;
1128 private void button6_Click_1(object sender, EventArgs e)
1130 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
1131 DialogResult result = openFileDialog1.ShowDialog();
1132 if (result == DialogResult.OK)
1134 namevideo6 = openFileDialog1.FileName;
1135 txtvideo6.Text = namevideo6;
1139 private void button7_Click_1(object sender, EventArgs e)
1141 if (namevideo5 == "" && nameaudio3 == "")
1143 ShowErrorMessage("请选择文件");
1145 else
1147 if (txtaudio3.Text != "" && txtsub.Text != "")
1149 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\" \"" + namesub + "\"";
1151 if (txtaudio3.Text == "" && txtsub.Text == "")
1153 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\"";
1155 if (txtaudio3.Text != "" && txtsub.Text == "")
1157 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + nameaudio3 + "\"";
1159 if (txtaudio3.Text == "" && txtsub.Text != "")
1161 mkvmerge = "\"" + workPath + "\\mkvmerge.exe\" -o \"" + nameout6 + "\" \"" + namevideo5 + "\" \"" + namesub + "\"";
1163 mkvmerge += "\r\ncmd";
1164 batpath = workPath + "\\mkvmerge.bat";
1165 File.WriteAllText(batpath, mkvmerge, UnicodeEncoding.Default);
1166 LogRecord(mkvmerge);
1167 System.Diagnostics.Process.Start(batpath);
1171 private void button4_Click_1(object sender, EventArgs e)
1173 SaveFileDialog savefile = new SaveFileDialog();
1174 savefile.Filter = "视频(*.mkv)|*.mkv";
1175 DialogResult result = savefile.ShowDialog();
1176 if (result == DialogResult.OK)
1178 nameout6 = savefile.FileName;
1179 txtout6.Text = nameout6;
1183 private void button3_Click_1(object sender, EventArgs e)
1185 openFileDialog1.Filter = "音频(*.mp3;*.aac;*.ac3)|*.mp3;*.aac;*.ac3|所有文件(*.*)|*.*";
1186 DialogResult result = openFileDialog1.ShowDialog();
1187 if (result == DialogResult.OK)
1189 nameaudio3 = openFileDialog1.FileName;
1190 txtaudio3.Text = nameaudio3;
1194 private void button5_Click_1(object sender, EventArgs e)
1196 openFileDialog1.Filter = "字幕(*.ass;*.ssa;*.srt)|*.ass;*.ssa;*.srt|所有文件(*.*)|*.*";
1197 DialogResult result = openFileDialog1.ShowDialog();
1198 if (result == DialogResult.OK)
1200 namesub = openFileDialog1.FileName;
1201 txtsub.Text = namesub;
1205 private void button8_Click(object sender, EventArgs e)
1207 if (namevideo6 == "")
1209 ShowErrorMessage("请选择视频文件");
1211 else
1213 int i = namevideo6.IndexOf(".mkv");
1214 string mkvname = namevideo6.Remove(i);
1215 mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 1:\"" + mkvname + "_video.h264\" 2:\"" + mkvname + "_audio.aac\"";
1216 batpath = workPath + "\\mkvextract.bat";
1217 File.WriteAllText(batpath, mkvextract, UnicodeEncoding.Default);
1218 System.Diagnostics.Process.Start(batpath);
1222 private void txtvideo5_TextChanged(object sender, EventArgs e)
1224 if (File.Exists(txtvideo5.Text.ToString()))
1226 namevideo5 = txtvideo5.Text;
1227 string finish = namevideo5.Remove(namevideo5.LastIndexOf("."));
1228 finish += "_mkv封装.mkv";
1229 txtout6.Text = finish;
1233 private void txtaudio3_TextChanged(object sender, EventArgs e)
1235 nameaudio3 = txtaudio3.Text;
1238 private void txtsub_TextChanged(object sender, EventArgs e)
1240 namesub = txtsub.Text;
1243 private void txtout6_TextChanged_1(object sender, EventArgs e)
1245 nameout6 = txtout6.Text;
1248 private void txtvideo6_TextChanged(object sender, EventArgs e)
1250 namevideo6 = txtvideo6.Text;
1253 private void btnAutoAdd_Click(object sender, EventArgs e)
1255 openFileDialog1.Multiselect = true;
1256 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1257 DialogResult result = openFileDialog1.ShowDialog();
1258 if (result == DialogResult.OK)
1260 lbAuto.Items.AddRange(openFileDialog1.FileNames);
1264 private void btnAutoDel_Click(object sender, EventArgs e)
1266 if (lbAuto.Items.Count > 0)
1268 if (lbAuto.SelectedItems.Count > 0)
1270 int index = lbAuto.SelectedIndex;
1271 lbAuto.Items.RemoveAt(lbAuto.SelectedIndex);
1272 if (index == lbAuto.Items.Count)
1274 lbAuto.SelectedIndex = index - 1;
1276 if (index >= 0 && index < lbAuto.Items.Count && lbAuto.Items.Count > 0)
1278 lbAuto.SelectedIndex = index;
1284 private void btnAutoClear_Click(object sender, EventArgs e)
1286 lbAuto.Items.Clear();
1289 private void lbAuto_DragDrop(object sender, DragEventArgs e)
1291 ListBox listbox = (ListBox)sender;
1292 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
1294 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
1295 foreach (String s in files)
1297 listbox.Items.Add(s);
1299 return;
1301 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
1302 if (indexoftarget != ListBox.NoMatches)
1304 string temp = listbox.Items[indexoftarget].ToString();
1305 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
1306 listbox.Items[indexofsource] = temp;
1307 listbox.SelectedIndex = indexoftarget;
1311 private void lbAuto_DragEnter(object sender, DragEventArgs e)
1313 //if (e.Data.GetDataPresent(DataFormats.FileDrop))
1314 // e.Effect = DragDropEffects.All;
1315 //else e.Effect = DragDropEffects.None;
1318 private void lbAuto_DragOver(object sender, DragEventArgs e)
1320 //拖动源和放置的目的地一定是一个ListBox
1321 ListBox listbox = (ListBox)sender;
1322 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(listbox))
1324 e.Effect = DragDropEffects.Move;
1326 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
1328 e.Effect = DragDropEffects.Link;
1330 else e.Effect = DragDropEffects.None;
1333 private void lbAuto_MouseDown(object sender, MouseEventArgs e)
1335 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
1336 if (indexofsource == 65535)
1337 return;
1338 if (indexofsource != ListBox.NoMatches)
1340 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
1344 public string VideoBatch(string input, string output)
1346 bool hasAudio = false;
1347 string bat = "";
1349 //检测是否含有音频
1350 string getOutput = Util.GetFFmpegOutput(workPath, input);
1351 Regex ffReg = new Regex(@"Stream #0:\d[\s\S]+: Audio[\s\S]+");
1352 Match ffmch = ffReg.Match(getOutput);
1353 if (ffmch.Success) hasAudio = true;
1355 if (x264AudioModeComboBox.SelectedIndex == 0 && hasAudio) //如果压制音频
1357 aextract = audiobat(input, "temp.aac");
1358 x264 = x264bat(input, "temp.mp4").Replace("\r\n", "");
1360 else
1362 x264 = x264bat(input, output).Replace("\r\n", "");
1365 if (x264BatchSubCheckBox.Checked) //内嵌字幕
1367 string sub = GetSubtitlePath(input);
1369 if (sub != "")
1371 if (x264.IndexOf("--vf") == -1)
1373 x264 += " --vf subtitles --sub \"" + sub + "\"";
1375 else
1377 Regex r = new Regex("--vf\\s\\S*");
1378 Match m = r.Match(x264);
1379 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles --sub \"" + sub + "\"");
1380 if (m.NextMatch().Success)
1382 Match mnext = r.Match(x264).NextMatch();
1383 x264 = x264.Insert(mnext.Index + mnext.Value.Length, "/subtitles --sub \"" + sub + "\"");
1388 x264 += "\r\n";
1389 mux = ffmuxbat("temp.mp4", "temp.aac", output);
1391 if (x264AudioModeComboBox.SelectedIndex == 0 && hasAudio) //如果压制音频
1392 bat += aextract + x264 + mux + " \r\ndel temp.aac\r\ndel temp.mp4\r\n";
1393 else
1394 bat += x264;
1395 return bat;
1398 private void btnBatchAuto_Click(object sender, EventArgs e)
1400 if (lbAuto.Items.Count == 0)
1402 ShowErrorMessage("请输入视频!");
1403 return;
1406 if (x264ExeComboBox.SelectedIndex == -1)
1408 ShowErrorMessage("请选择X264程序");
1409 return;
1412 string bat = "";
1413 for (int i = 0; i < this.lbAuto.Items.Count; i++)
1415 string input = lbAuto.Items[i].ToString();
1416 string output;
1417 if (Directory.Exists(x264PathTextBox.Text))
1418 output = x264PathTextBox.Text + "\\" + Path.GetFileNameWithoutExtension(input) + "_batch." + VideoBatchFormatComboBox.Text;
1419 else
1420 output = Util.ChangeExt(input, "_batch." + VideoBatchFormatComboBox.Text);
1421 bat += VideoBatch(lbAuto.Items[i].ToString(), output);
1424 //batpath = workPath + "\\auto.bat";
1425 LogRecord(bat);
1426 WorkingForm wf = new WorkingForm(bat, lbAuto.Items.Count);
1427 wf.Owner = this;
1428 wf.Show();
1429 //File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
1430 //System.Diagnostics.Process.Start(batpath);
1433 private void lbffmpeg_MouseDown(object sender, MouseEventArgs e)
1435 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
1436 if (indexofsource != ListBox.NoMatches)
1438 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
1442 private void lbffmpeg_DragDrop(object sender, DragEventArgs e)
1444 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
1446 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
1447 foreach (String s in files)
1449 (sender as ListBox).Items.Add(s);
1452 ListBox listbox = (ListBox)sender;
1453 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
1454 if (indexoftarget != ListBox.NoMatches)
1456 string temp = listbox.Items[indexoftarget].ToString();
1457 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
1458 listbox.Items[indexofsource] = temp;
1459 listbox.SelectedIndex = indexoftarget;
1463 private void lbffmpeg_DragOver(object sender, DragEventArgs e)
1465 //拖动源和放置的目的地一定是一个ListBox
1466 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lbffmpeg))
1468 e.Effect = DragDropEffects.Move;
1470 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
1472 e.Effect = DragDropEffects.Link;
1474 else e.Effect = DragDropEffects.None;
1477 private void btnffmpegAdd_Click(object sender, EventArgs e)
1479 openFileDialog1.Multiselect = true;
1480 openFileDialog1.Filter = "所有文件(*.*)|*.*";
1481 DialogResult result = openFileDialog1.ShowDialog();
1482 if (result == DialogResult.OK)
1484 lbffmpeg.Items.AddRange(openFileDialog1.FileNames);
1488 private void btnffmpegDel_Click(object sender, EventArgs e)
1490 if (lbffmpeg.Items.Count > 0)
1492 if (lbffmpeg.SelectedItems.Count > 0)
1494 int index = lbffmpeg.SelectedIndex;
1495 lbffmpeg.Items.RemoveAt(lbffmpeg.SelectedIndex);
1496 if (index == lbffmpeg.Items.Count)
1498 lbffmpeg.SelectedIndex = index - 1;
1500 if (index >= 0 && index < lbffmpeg.Items.Count && lbffmpeg.Items.Count > 0)
1502 lbffmpeg.SelectedIndex = index;
1508 private void btnffmpegClear_Click(object sender, EventArgs e)
1510 lbffmpeg.Items.Clear();
1513 private void btnBatchMP4_Click(object sender, EventArgs e)
1515 if (lbffmpeg.Items.Count != 0)
1517 string finish;
1518 string ext = MuxFormatComboBox.Text;
1519 int i;
1520 ffmpeg = "";
1521 for (i = 0; i < this.lbffmpeg.Items.Count; i++)
1523 finish = lbffmpeg.Items[i].ToString().Remove(lbffmpeg.Items[i].ToString().LastIndexOf(".")) + "_" + ext + "封装." + ext;
1524 ffmpeg += "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + lbffmpeg.Items[i].ToString() + "\" -c copy \"" + finish + "\" \r\n";
1526 ffmpeg += "\r\ncmd";
1527 batpath = workPath + "\\flv.bat";
1528 File.WriteAllText(batpath, ffmpeg, UnicodeEncoding.Default);
1529 LogRecord(ffmpeg);
1530 System.Diagnostics.Process.Start(batpath);
1531 //lbffmpeg.Items.Clear();
1533 else ShowErrorMessage("请输入视频!");
1536 private void txtvideo8_TextChanged(object sender, EventArgs e)
1538 namevideo8 = txtvideo8.Text;
1541 private void btnvextract8_Click(object sender, EventArgs e)
1543 //FLV vcopy
1544 ExtractAV(namevideo8, "v", 0);
1545 //if (namevideo8 == "")
1547 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1549 //else
1551 // vextract = "\"" + workPath + "\\FLVExtractCL.exe\" -v \"" + namevideo8 + "\"";
1552 // batpath = workPath + "\\vextract.bat";
1553 // File.WriteAllText(batpath, vextract, UnicodeEncoding.Default);
1554 // LogRecord(vextract);
1555 // System.Diagnostics.Process.Start(batpath);
1559 private void btnaextract8_Click(object sender, EventArgs e)
1561 //FLV acopy
1562 ExtractAV(namevideo8, "a", 0);
1563 //if (namevideo8 == "")
1565 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1567 //else
1569 // aextract = "\"" + workPath + "\\FLVExtractCL.exe\" -a \"" + namevideo8 + "\"";
1570 // batpath = workPath + "\\aextract.bat";
1571 // File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
1572 // LogRecord(aextract);
1573 // System.Diagnostics.Process.Start(batpath);
1577 private void btnvideo8_Click(object sender, EventArgs e)
1579 openFileDialog1.Filter = "视频(*.flv;*.hlv)|*.flv;*.hlv";
1580 DialogResult result = openFileDialog1.ShowDialog();
1581 if (result == DialogResult.OK)
1583 namevideo8 = openFileDialog1.FileName;
1584 txtvideo8.Text = namevideo;
1588 private void btnpreview9_Click(object sender, EventArgs e)
1590 if (AVSScriptTextBox.Text != "")
1592 string filepath = workPath + "\\temp.avs";
1593 File.WriteAllText(filepath, AVSScriptTextBox.Text.ToString(), UnicodeEncoding.Default);
1594 if (File.Exists(SetupPlayerTextBox.Text))
1596 Process.Start(SetupPlayerTextBox.Text, filepath);
1598 else
1600 PreviewForm pf = new PreviewForm();
1601 pf.Show();
1602 pf.axWindowsMediaPlayer1.URL = filepath;
1605 else
1607 ShowErrorMessage("请输入正确的AVS脚本!");
1611 private void txtout_MouseDoubleClick(object sender, MouseEventArgs e)
1613 if (File.Exists(txtout.Text.ToString()))
1615 System.Diagnostics.Process.Start(txtout.Text.ToString());
1619 private void txtout3_MouseDoubleClick(object sender, MouseEventArgs e)
1621 if (File.Exists(AudioOutputTextBox.Text.ToString()))
1623 System.Diagnostics.Process.Start(AudioOutputTextBox.Text.ToString());
1627 private void txtout6_MouseDoubleClick(object sender, MouseEventArgs e)
1629 if (File.Exists(txtout6.Text.ToString()))
1631 System.Diagnostics.Process.Start(txtout6.Text.ToString());
1635 private void txtout9_MouseDoubleClick(object sender, MouseEventArgs e)
1637 if (File.Exists(txtout9.Text.ToString()))
1639 System.Diagnostics.Process.Start(txtout9.Text.ToString());
1643 private void txtvideo9_TextChanged(object sender, EventArgs e)
1645 if (File.Exists(txtvideo9.Text.ToString()))
1647 namevideo9 = txtvideo9.Text;
1648 string finish = namevideo9.Remove(namevideo9.LastIndexOf("."));
1649 finish += "_AVS压制.mp4";
1650 txtout9.Text = finish;
1651 GenerateAVS();
1653 //if (txtvideo9.Text != "")
1655 // if (txtAVS.Text != "")
1656 // {
1657 // txtAVS.Text = txtAVS.Text.Replace(prevideo9, txtvideo9.Text);
1658 // }
1659 // else
1660 // {
1661 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1662 // foreach (FileInfo FileName in TheFolder.GetFiles())
1663 // {
1664 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1665 // }
1666 // avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\n" + "TextSub(\"" + namesub9 + "\")\r\n";
1667 // txtAVS.Text = avs;
1668 // avs = "";
1669 // }
1670 // prevideo9 = txtvideo9.Text;
1674 private void txtsub9_TextChanged(object sender, EventArgs e)
1676 namesub9 = txtsub9.Text;
1677 GenerateAVS();
1678 //if (txtAVS.Text != "")
1680 // txtAVS.Text=txtAVS.Text.Replace(namesub9, txtsub9.Text);
1681 // namesub9 = txtsub9.Text;
1683 //else
1685 // namesub9 = txtsub9.Text;
1686 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1687 // foreach (FileInfo FileName in TheFolder.GetFiles())
1688 // {
1689 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1690 // }
1691 // avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\n" + "TextSub(\"" + namesub9 + "\")\r\n";
1692 // txtAVS.Text = avs;
1693 // avs = "";
1697 private void txtout9_TextChanged(object sender, EventArgs e)
1699 nameout9 = txtout9.Text;
1702 private void btnAVS9_Click(object sender, EventArgs e)
1704 x264DemuxerComboBox.SelectedIndex = 0; //压制AVS始终使用分离器为auto
1706 if (string.IsNullOrEmpty(nameout9))
1708 ShowErrorMessage("请选择输出文件");
1709 return;
1711 if (!AVSwithAudioCheckBox.Checked)
1713 string filepath = tempavspath;
1714 //string filepath = workpath + "\\temp.avs";
1715 File.WriteAllText(filepath, AVSScriptTextBox.Text, UnicodeEncoding.Default);
1716 auto = x264bat(filepath, nameout9);
1718 else
1720 if (!File.Exists(txtvideo9.Text))
1722 ShowErrorMessage("请选择视频文件");
1723 return;
1725 string filepath = workPath + "\\temp.avs";
1726 File.WriteAllText(filepath, AVSScriptTextBox.Text, UnicodeEncoding.Default);
1727 x264 = x264bat(filepath, "temp.mp4");
1728 //audio
1729 aextract = audiobat(namevideo9, "temp.aac");
1730 //mux
1731 mux = ffmuxbat("temp.mp4", "temp.aac", nameout9);
1732 auto = aextract + x264 + "\r\n" + mux + " \r\n";
1734 LogRecord(auto);
1735 WorkingForm wf = new WorkingForm(auto);
1736 wf.Owner = this;
1737 wf.Show();
1740 private void btnout9_Click(object sender, EventArgs e)
1742 SaveFileDialog savefile = new SaveFileDialog();
1743 savefile.Filter = "视频(*.mp4)|*.mp4";
1744 DialogResult result = savefile.ShowDialog();
1745 if (result == DialogResult.OK)
1747 txtout9.Text = nameout9 = savefile.FileName;
1751 private void btnAVSone_Click(object sender, EventArgs e)
1753 if (String.IsNullOrEmpty(nameout9))
1755 ShowErrorMessage("请选择输出文件");
1757 else
1759 string filepath = workPath + "\\temp.avs";
1760 File.WriteAllText(filepath, AVSScriptTextBox.Text, UnicodeEncoding.Default);
1761 x264 = x264bat(filepath, "temp.mp4");
1762 //audio
1763 aextract = audiobat(namevideo9, "temp.aac");
1764 //mux
1765 mux = ffmuxbat("temp.mp4", "temp.aac", nameout9);
1766 auto = aextract + x264 + "\r\n" + mux + " \r\ncmd";
1767 batpath = workPath + "\\auto.bat";
1768 File.WriteAllText(batpath, auto, UnicodeEncoding.Default);
1769 System.Diagnostics.Process.Start(batpath);
1773 private void button6_Click_2(object sender, EventArgs e)
1775 //if (Directory.Exists("avsfilter"))
1777 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1778 // foreach (FileInfo FileName in TheFolder.GetFiles())
1779 // {
1780 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
1781 // }
1783 avs += "LoadPlugin(\"avsfilter\\VSFilter.DLL\")\r\n";
1784 avs += string.Format("\r\nLWLibavVideoSource(\"{0}\",23.976,convertFPS=True)\r\nConvertToYV12()\r\nCrop(0,0,0,0)\r\nAddBorders(0,0,0,0)\r\n" + "TextSub(\"{1}\")\r\n#LanczosResize(1280,960)\r\n", namevideo9, namesub9);
1785 //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";
1786 AVSScriptTextBox.Text = avs;
1787 avs = "";
1790 private void txth264_TextChanged(object sender, EventArgs e)
1794 private void txtvideo_MouseDoubleClick(object sender, MouseEventArgs e)
1796 if (File.Exists(txtvideo.Text.ToString()))
1798 System.Diagnostics.Process.Start(txtvideo.Text.ToString());
1802 private void txtvideo4_MouseDoubleClick(object sender, MouseEventArgs e)
1804 if (File.Exists(txtvideo4.Text.ToString()))
1806 System.Diagnostics.Process.Start(txtvideo4.Text.ToString());
1810 private void txtout5_MouseDoubleClick(object sender, MouseEventArgs e)
1812 if (File.Exists(txtout5.Text.ToString()))
1814 System.Diagnostics.Process.Start(txtout5.Text.ToString());
1818 private void txtvideo8_MouseDoubleClick(object sender, MouseEventArgs e)
1820 if (File.Exists(txtvideo8.Text.ToString()))
1822 System.Diagnostics.Process.Start(txtvideo8.Text.ToString());
1826 private void txtvideo9_MouseDoubleClick(object sender, MouseEventArgs e)
1828 if (File.Exists(txtvideo9.Text.ToString()))
1830 System.Diagnostics.Process.Start(txtvideo9.Text.ToString());
1834 private void txtvideo6_MouseDoubleClick(object sender, MouseEventArgs e)
1836 if (File.Exists(txtvideo6.Text.ToString()))
1838 System.Diagnostics.Process.Start(txtvideo6.Text.ToString());
1842 private void txtvideo5_MouseDoubleClick(object sender, MouseEventArgs e)
1844 if (File.Exists(txtvideo5.Text.ToString()))
1846 System.Diagnostics.Process.Start(txtvideo5.Text.ToString());
1850 private void txtaudio3_MouseDoubleClick(object sender, MouseEventArgs e)
1852 if (File.Exists(txtaudio3.Text.ToString()))
1854 System.Diagnostics.Process.Start(txtaudio3.Text.ToString());
1858 private void timer1_Tick(object sender, EventArgs e)
1860 Process[] processes = Process.GetProcesses();
1861 for (int i = 0; i < processes.GetLength(0); i++)
1863 //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
1864 if (processes[i].ProcessName.Equals(Path.GetFileNameWithoutExtension(x264ExeComboBox.Text)))
1866 switch (x264PriorityComboBox.SelectedIndex)
1868 case 0: processes[i].PriorityClass = ProcessPriorityClass.Idle; break;
1869 case 1: processes[i].PriorityClass = ProcessPriorityClass.BelowNormal; break;
1870 case 2: processes[i].PriorityClass = ProcessPriorityClass.Normal; break;
1871 case 3: processes[i].PriorityClass = ProcessPriorityClass.AboveNormal; break;
1872 case 4: processes[i].PriorityClass = ProcessPriorityClass.High; break;
1873 case 5: processes[i].PriorityClass = ProcessPriorityClass.RealTime; break;
1879 private void btnsub9_Click(object sender, EventArgs e)
1881 openFileDialog1.Filter = "字幕(*.ass;*.ssa;*.srt)|*.ass;*.ssa;*.srt|所有文件(*.*)|*.*";
1882 DialogResult result = openFileDialog1.ShowDialog();
1883 if (result == DialogResult.OK)
1885 namesub9 = openFileDialog1.FileName;
1886 txtsub9.Text = namesub9;
1890 private void btnvideo9_Click(object sender, EventArgs e)
1892 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv;*.wmv)|*.mp4;*.flv;*.mkv;*.wmv|所有文件(*.*)|*.*";
1893 DialogResult result = openFileDialog1.ShowDialog();
1894 if (result == DialogResult.OK)
1896 namevideo9 = openFileDialog1.FileName;
1897 txtvideo9.Text = namevideo9;
1901 private void button9_Click(object sender, EventArgs e)
1903 AVSScriptTextBox.Clear();
1906 private void btnClip_Click(object sender, EventArgs e)
1908 if (namevideo4 == "")
1910 ShowErrorMessage("请选择视频文件");
1912 else if (nameout5 == "")
1914 ShowErrorMessage("请选择输出文件");
1916 else
1918 //int h1 = int.Parse(maskb.Text.ToString().Substring(0, 2));
1919 //int m1 = int.Parse(maskb.Text.ToString().Substring(3, 2));
1920 //int s1 = int.Parse(maskb.Text.ToString().Substring(6, 2));
1921 //int h2 = int.Parse(maske.Text.ToString().Substring(0, 2));
1922 //int m2 = int.Parse(maske.Text.ToString().Substring(3, 2));
1923 //int s2 = int.Parse(maske.Text.ToString().Substring(6, 2));
1924 //clip = "\"" + workPath + "\\ffmpeg.exe\" -ss " + maskb.Text + " -to " + maske.Text + " -i \"" + namevideo4 + "\" -acodec copy -vcodec copy \"" + nameout5 + "\" \r\ncmd";
1926 // "<workPath>\ffmpeg.exe" -i "<namevideo4>" -ss <maskb.Text> -to <maske.Text> -c copy "<nameout5>"
1927 clip = String.Format(@"""{0}\ffmpeg.exe"" -i ""{1}"" -ss {2} -to {3} -y -c copy ""{4}""",
1928 workPath, namevideo4, maskb.Text, maske.Text, nameout5) + Environment.NewLine + "cmd";
1929 batpath = workPath + "\\clip.bat";
1930 LogRecord(clip);
1931 File.WriteAllText(batpath, clip, UnicodeEncoding.Default);
1932 Process.Start(batpath);
1936 private void cbX264_SelectedIndexChanged(object sender, EventArgs e)
1938 StreamReader sr = new StreamReader(workPath + "\\preset\\" + VideoPresetComboBox.Text + ".txt", System.Text.Encoding.Default);
1939 x264CustomParameterTextBox.Text = sr.ReadToEnd();
1940 sr.Close();
1943 private void cbFPS_SelectedIndexChanged(object sender, EventArgs e)
1945 string ext = Path.GetExtension(namevideo).ToLower();
1946 if (cbFPS.SelectedIndex != 0 && ext != ".264" && ext != ".h264" && ext != ".hevc")
1948 ShowWarningMessage("只有扩展名为.264 .h264 .hevc的流文件设置帧率(fps)才有效");
1949 cbFPS.SelectedIndex = 0;
1953 private void btnMIopen_Click(object sender, EventArgs e)
1955 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
1956 DialogResult result = openFileDialog1.ShowDialog();
1957 if (result == DialogResult.OK)
1959 MIvideo = openFileDialog1.FileName;
1960 MediaInfoTextBox.Text = MediaInfo(MIvideo);
1964 private void btnMIplay_Click(object sender, EventArgs e)
1966 Process.Start(MIvideo);
1969 private void btnMIcopy_Click(object sender, EventArgs e)
1971 Clipboard.SetText(MItext);
1974 private void btnvideo7_Click(object sender, EventArgs e)
1976 openFileDialog1.Filter = "视频(*.mkv)|*.mkv";
1977 DialogResult result = openFileDialog1.ShowDialog();
1978 if (result == DialogResult.OK)
1980 namevideo6 = openFileDialog1.FileName;
1981 txtvideo6.Text = namevideo6;
1985 private void btnextract7_Click(object sender, EventArgs e)
1987 //MKV抽0
1988 ExtractTrack(namevideo6, 0);
1989 //if (namevideo6 == "")
1991 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1993 //else
1995 // int i = namevideo6.IndexOf(".");
1996 // string mkvname = namevideo6.Remove(i);
1997 // QQButton btn = (QQButton)sender;
1998 // switch (btn.Name)
1999 // {
2000 // case "MkvExtract1Button":
2001 // mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 1:\"" + mkvname + "_audio.aac\"";
2002 // break;
2003 // case "MkvExtract2Button":
2004 // mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 2:\"" + mkvname + "_track2\"";
2005 // break;
2006 // case "MkvExtract3Button":
2007 // mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 3:\"" + mkvname + "_track3\"";
2008 // break;
2009 // case "MkvExtract4Button":
2010 // mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 4:\"" + mkvname + "_track4\"";
2011 // break;
2012 // case "btnextract7":
2013 // mkvextract = "\"" + workPath + "\\mkvextract.exe\" tracks \"" + namevideo6 + "\" 0:\"" + mkvname + "_video.h264\"";
2014 // break;
2015 // }
2016 // batpath = workPath + "\\mkvextract.bat";
2017 // File.WriteAllText(batpath, mkvextract, UnicodeEncoding.Default);
2018 // LogRecord(mkvextract);
2019 // System.Diagnostics.Process.Start(batpath);
2023 private void MkvExtract1Button_Click(object sender, EventArgs e)
2025 //MKV 抽1
2026 ExtractTrack(namevideo6, 1);
2029 private void MkvExtract2Button_Click(object sender, EventArgs e)
2031 //MKV 抽2
2032 ExtractTrack(namevideo6, 2);
2035 private void MkvExtract3Button_Click(object sender, EventArgs e)
2037 //MKV 抽3
2038 ExtractTrack(namevideo6, 3);
2041 private void MkvExtract4Button_Click(object sender, EventArgs e)
2043 //MKV 抽4
2044 ExtractTrack(namevideo6, 4);
2047 private void txtMI_TextChanged(object sender, EventArgs e)
2049 MItext = MediaInfoTextBox.Text;
2052 private void txtAVScreate_Click(object sender, EventArgs e)
2056 private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
2058 System.Diagnostics.Process.Start("http://www.sosg.net/read.php?tid=480646");
2061 private void btnaextract2_Click(object sender, EventArgs e)
2063 //MP4 抽取音频2
2064 ExtractAV(namevideo, "a", 1);
2065 //if (namevideo == "")
2067 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2069 //else
2071 // //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 3 \"" + namevideo + "\"";
2072 // aextract = "";
2073 // aextract += Cmd.FormatPath(workPath + "\\ffmpeg.exe");
2074 // aextract += " -i " + Cmd.FormatPath(namevideo);
2075 // aextract += " -vn -sn -c:a:1 copy ";
2076 // string outfile = Cmd.GetDir(namevideo) +
2077 // Path.GetFileNameWithoutExtension(namevideo) + "_抽取音频2" + Path.GetExtension(namevideo);
2078 // aextract += Cmd.FormatPath(outfile);
2079 // batpath = workPath + "\\aextract.bat";
2080 // File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
2081 // LogRecord(aextract);
2082 // System.Diagnostics.Process.Start(batpath);
2086 private void btnaextract3_Click(object sender, EventArgs e)
2088 //MP4 抽取音频3
2089 ExtractAV(namevideo, "a", 2);
2090 //if (namevideo == "")
2092 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2094 //else
2096 // //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 4 \"" + namevideo + "\"";
2097 // aextract = "";
2098 // aextract += Cmd.FormatPath(workPath + "\\ffmpeg.exe");
2099 // aextract += " -i " + Cmd.FormatPath(namevideo);
2100 // aextract += " -vn -sn -c:a:2 copy ";
2101 // string outfile = Cmd.GetDir(namevideo) +
2102 // Path.GetFileNameWithoutExtension(namevideo) + "_抽取音频3" + Path.GetExtension(namevideo);
2103 // aextract += Cmd.FormatPath(outfile);
2104 // batpath = workPath + "\\aextract.bat";
2105 // File.WriteAllText(batpath, aextract, UnicodeEncoding.Default);
2106 // LogRecord(aextract);
2107 // System.Diagnostics.Process.Start(batpath);
2111 private void txtvideo6_TextChanged_1(object sender, EventArgs e)
2113 if (File.Exists(txtvideo6.Text.ToString()))
2115 namevideo6 = txtvideo6.Text;
2119 #region 帮助页面
2121 private void AboutBtn_Click(object sender, EventArgs e)
2123 DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
2124 QQMessageBox.Show(
2125 this,
2126 "小丸工具箱 七七版\r\n主页:http://www.maruko.in/ \r\n编译日期:" + CompileDate.ToString(),
2127 "关于",
2128 QQMessageBoxIcon.Information,
2129 QQMessageBoxButtons.OK);
2132 private void HomePageBtn_Click(object sender, EventArgs e)
2134 System.Diagnostics.Process.Start("http://www.maruko.in/");
2137 #endregion 帮助页面
2139 #region 视频页面
2141 private void x264VideoBtn_Click(object sender, EventArgs e)
2143 openFileDialog1.Filter = "视频(*.mp4;*.flv;*.mkv;*.avi;*.wmv;*.mpg;*.avs)|*.mp4;*.flv;*.mkv;*.avi;*.wmv;*.mpg;*.avs|所有文件(*.*)|*.*";
2144 DialogResult result = openFileDialog1.ShowDialog();
2145 if (result == DialogResult.OK)
2147 namevideo2 = openFileDialog1.FileName;
2148 x264VideoTextBox.Text = namevideo2;
2152 private void x264OutBtn_Click(object sender, EventArgs e)
2154 SaveFileDialog savefile = new SaveFileDialog();
2155 savefile.Filter = "MPEG-4 视频(*.mp4)|*.mp4|Flash 视频(*.flv)|*.flv|Matroska 视频(*.mkv)|*.mkv|AVI 视频(*.avi)|*.avi|H.264 流(*.raw)|*.raw";
2156 savefile.FileName = Path.GetFileName(x264OutTextBox.Text);
2157 DialogResult result = savefile.ShowDialog();
2158 if (result == DialogResult.OK)
2160 nameout2 = savefile.FileName;
2161 x264OutTextBox.Text = nameout2;
2165 private void x264SubBtn_Click(object sender, EventArgs e)
2167 openFileDialog1.Filter = "字幕(*.ass;*.ssa;*.srt)|*.ass;*.ssa;*.srt|所有文件(*.*)|*.*";
2168 DialogResult result = openFileDialog1.ShowDialog();
2169 if (result == DialogResult.OK)
2171 namesub2 = openFileDialog1.FileName;
2172 x264SubTextBox.Text = namesub2;
2176 private void x264StartBtn_Click(object sender, EventArgs e)
2178 #region validation
2180 if (string.IsNullOrEmpty(namevideo2))
2182 ShowErrorMessage("请选择视频文件");
2183 return;
2186 if (!string.IsNullOrEmpty(namesub2) && !File.Exists(namesub2))
2188 ShowErrorMessage("字幕文件不存在,请重新选择");
2189 return;
2192 if (string.IsNullOrEmpty(nameout2))
2194 ShowErrorMessage("请选择输出文件");
2195 return;
2198 if (x264ExeComboBox.SelectedIndex == -1)
2200 ShowErrorMessage("请选择X264程序");
2201 return;
2204 //防止未选择 x264 thread
2205 if (x264ThreadsComboBox.SelectedIndex == -1)
2207 x264ThreadsComboBox.SelectedIndex = 0;
2210 //如果是AVS复制到C盘根目录
2211 if (Path.GetExtension(x264VideoTextBox.Text) == ".avs")
2213 //if (File.Exists(tempavspath)) File.Delete(tempavspath);
2214 File.Copy(x264VideoTextBox.Text, tempavspath, true);
2215 namevideo2 = tempavspath;
2216 x264DemuxerComboBox.SelectedIndex = 0; //压制AVS始终使用分离器为auto
2219 #endregion validation
2221 string ext = Path.GetExtension(nameout2).ToLower();
2222 bool hasAudio = false;
2223 string tempVideo = Util.ChangeExt(namevideo2, "_temp.mp4");
2224 string tempAudio = Util.ChangeExt(namevideo2, "_temp.aac");
2225 //检测是否含有音频
2226 string getOutput = Util.GetFFmpegOutput(workPath, namevideo2);
2227 Regex ffReg = new Regex(@"Stream #0:\d[\s\S]+: Audio[\s\S]+");
2228 Match ffmch = ffReg.Match(getOutput);
2229 if (ffmch.Success) hasAudio = true;
2231 //编码文件
2232 if (x264AudioModeComboBox.SelectedIndex == 0 && hasAudio) //如果压制音频
2234 aextract = audiobat(namevideo2, tempAudio);
2235 x264 = x264bat(namevideo2, tempVideo).Replace("\r\n", "");
2237 else
2239 x264 = x264bat(namevideo2, nameout2).Replace("\r\n", "");
2241 if (x264SeekNumericUpDown.Value != 0)
2243 x264 += " --seek " + x264SeekNumericUpDown.Value.ToString();
2245 if (x264FramesNumericUpDown.Value != 0)
2247 x264 += " --frames " + x264FramesNumericUpDown.Value.ToString();
2251 //如果嵌字幕
2252 if (x264SubTextBox.Text != "")
2254 if (x264.IndexOf("--vf") == -1)
2256 x264 += " --vf subtitles --sub \"" + namesub2 + "\"";
2258 else
2260 Regex r = new Regex("--vf\\s\\S*");
2261 Match m = r.Match(x264);
2262 x264 = x264.Insert(m.Index + m.Value.Length, "/subtitles --sub \"" + namesub2 + "\"");
2263 if (m.NextMatch().Success)
2265 Match mnext = r.Match(x264).NextMatch();
2266 x264 = x264.Insert(mnext.Index + mnext.Value.Length, "/subtitles --sub \"" + namesub2 + "\"");
2270 x264 += "\r\n";
2272 //封装
2273 if (x264AudioModeComboBox.SelectedIndex == 0 && hasAudio) //如果包含音频
2275 mux = ffmuxbat(tempVideo, tempAudio, Util.ChangeExt(nameout2, ext));
2276 x264 = aextract + x264 + mux + "\r\n"
2277 + "del \"" + tempVideo + "\"\r\n"
2278 + "del \"" + tempAudio + "\"\r\n";
2280 x264 += "\r\n";
2281 LogRecord(x264);
2282 WorkingForm wf = new WorkingForm(x264);
2283 wf.Owner = this;
2284 wf.Show();
2285 //x264 += "\r\ncmd";
2286 //batpath = workpath + "\\x264.bat";
2287 //File.WriteAllText(batpath, x264, UnicodeEncoding.Default);
2288 //System.Diagnostics.Process.Start(batpath);
2291 private void x264AddPresetBtn_Click(object sender, EventArgs e)
2293 //create directory
2294 string preset = workPath + "\\preset";
2295 if (!Directory.Exists(preset)) Directory.CreateDirectory(preset);
2296 //add file
2297 batpath = workPath + "\\preset\\" + PresetNameTextBox.Text + ".txt";
2298 File.WriteAllText(batpath, x264CustomParameterTextBox.Text, UnicodeEncoding.Default);
2299 //refresh combobox
2300 VideoPresetComboBox.Items.Clear();
2301 if (Directory.Exists(workPath + "\\preset"))
2303 DirectoryInfo TheFolder = new DirectoryInfo(preset);
2304 foreach (FileInfo FileName in TheFolder.GetFiles())
2306 VideoPresetComboBox.Items.Add(FileName.Name.Replace(".txt", ""));
2309 VideoPresetComboBox.SelectedIndex = VideoPresetComboBox.FindString(PresetNameTextBox.Text);
2312 private void x264DeletePresetBtn_Click(object sender, EventArgs e)
2314 if (ShowQuestion("确定要删除这条预设参数?", "提示") == DialogResult.Yes)
2316 string preset = workPath + "\\preset";
2317 batpath = workPath + "\\preset\\" + VideoPresetComboBox.Text + ".txt";
2318 File.Delete(batpath);
2319 VideoPresetComboBox.Items.Clear();
2320 if (Directory.Exists(preset))
2322 DirectoryInfo TheFolder = new DirectoryInfo(preset);
2323 foreach (FileInfo FileName in TheFolder.GetFiles())
2325 VideoPresetComboBox.Items.Add(FileName.Name.Replace(".txt", ""));
2328 if (VideoPresetComboBox.Items.Count > 0) VideoPresetComboBox.SelectedIndex = 0;
2332 private void x264Mode2RadioButton_CheckedChanged(object sender, EventArgs e)
2334 mode = 2;
2335 lbrate.Visible = true;
2336 x264BitrateNum.Visible = true;
2337 label12.Visible = true;
2338 //x264FpsComboBox.Visible = true;
2339 //lbFPS2.Visible = true;
2340 lbwidth.Visible = true;
2341 lbheight.Visible = true;
2342 x264WidthNum.Visible = true;
2343 x264HeightNum.Visible = true;
2344 MaintainResolutionCheckBox.Visible = true;
2345 lbcrf.Visible = false;
2346 x264CRFNum.Visible = false;
2347 label4.Visible = false;
2348 x264CustomParameterTextBox.Visible = false;
2349 VideoPresetComboBox.Visible = false;
2350 x264AddPresetBtn.Visible = false;
2351 x264DeletePresetBtn.Visible = false;
2352 PresetNameTextBox.Visible = false;
2355 private void x264Mode3RadioButton_CheckedChanged(object sender, EventArgs e)
2357 mode = 0;
2358 label4.Visible = true;
2359 x264CustomParameterTextBox.Visible = true;
2360 VideoPresetComboBox.Visible = true;
2361 x264AddPresetBtn.Visible = true;
2362 x264DeletePresetBtn.Visible = true;
2363 PresetNameTextBox.Visible = true;
2364 lbwidth.Visible = false;
2365 lbheight.Visible = false;
2366 x264WidthNum.Visible = false;
2367 x264HeightNum.Visible = false;
2368 MaintainResolutionCheckBox.Visible = false;
2369 lbrate.Visible = false;
2370 x264BitrateNum.Visible = false;
2371 label12.Visible = false;
2372 lbcrf.Visible = false;
2373 x264CRFNum.Visible = false;
2374 //x264FpsComboBox.Visible = false;
2375 //lbFPS2.Visible = false;
2378 private void x264Mode1RadioButton_CheckedChanged(object sender, EventArgs e)
2380 mode = 1;
2381 lbcrf.Visible = true;
2382 x264CRFNum.Visible = true;
2383 //x264FpsComboBox.Visible = true;
2384 //lbFPS2.Visible = true;
2385 lbwidth.Visible = true;
2386 lbheight.Visible = true;
2387 x264WidthNum.Visible = true;
2388 x264HeightNum.Visible = true;
2389 MaintainResolutionCheckBox.Visible = true;
2390 lbrate.Visible = false;
2391 x264BitrateNum.Visible = false;
2392 label12.Visible = false;
2393 label4.Visible = false;
2394 x264CustomParameterTextBox.Visible = false;
2395 VideoPresetComboBox.Visible = false;
2396 x264AddPresetBtn.Visible = false;
2397 x264DeletePresetBtn.Visible = false;
2398 PresetNameTextBox.Visible = false;
2401 private void x264PriorityComboBox_SelectedIndexChanged(object sender, EventArgs e)
2403 string processName = x264ExeComboBox.Text;
2404 processName = processName.Replace(".exe", "");
2405 Process[] processes = Process.GetProcesses();
2406 //if (x264PriorityComboBox.SelectedIndex == 4 || x264PriorityComboBox.SelectedIndex == 5)
2408 // if (MessageBox.Show("优先级那么高的话会严重影响其他进程的运行速度,\r\n是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
2409 // {
2410 // x264PriorityComboBox.SelectedIndex = 2;
2411 // }
2413 //遍历电脑中的进程
2414 for (int i = 0; i < processes.GetLength(0); i++)
2416 //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
2417 if (processes[i].ProcessName.Equals(processName))
2419 switch (x264PriorityComboBox.SelectedIndex)
2421 case 0: processes[i].PriorityClass = ProcessPriorityClass.Idle; break;
2422 case 1: processes[i].PriorityClass = ProcessPriorityClass.BelowNormal; break;
2423 case 2: processes[i].PriorityClass = ProcessPriorityClass.Normal; break;
2424 case 3: processes[i].PriorityClass = ProcessPriorityClass.AboveNormal; break;
2425 case 4: processes[i].PriorityClass = ProcessPriorityClass.High; break;
2426 case 5: processes[i].PriorityClass = ProcessPriorityClass.RealTime; break;
2432 private void x264VideoTextBox_TextChanged(object sender, EventArgs e)
2434 string path = x264VideoTextBox.Text;
2435 if (File.Exists(path))
2437 namevideo2 = path;
2438 x264OutTextBox.Text = Util.ChangeExt(namevideo2, "_x264.mp4");
2440 if (Path.GetExtension(namevideo2) != ".avs")
2442 string[] subExt = { ".ass", ".ssa", ".srt" };
2443 foreach (string ext in subExt)
2445 if (File.Exists(Util.ChangeExt(namevideo2, ext)))
2447 x264SubTextBox.Text = Util.ChangeExt(namevideo2, ext);
2448 break;
2455 private void x264OutTextBox_TextChanged(object sender, EventArgs e)
2457 nameout2 = x264OutTextBox.Text;
2460 private void x264SubTextBox_TextChanged(object sender, EventArgs e)
2462 namesub2 = x264SubTextBox.Text;
2465 private void x264BatchClearBtn_Click(object sender, EventArgs e)
2467 lbAuto.Items.Clear();
2470 private void x264BatchDeleteBtn_Click(object sender, EventArgs e)
2472 if (lbAuto.Items.Count > 0)
2474 if (lbAuto.SelectedItems.Count > 0)
2476 int index = lbAuto.SelectedIndex;
2477 lbAuto.Items.RemoveAt(lbAuto.SelectedIndex);
2478 if (index == lbAuto.Items.Count)
2480 lbAuto.SelectedIndex = index - 1;
2482 if (index >= 0 && index < lbAuto.Items.Count && lbAuto.Items.Count > 0)
2484 lbAuto.SelectedIndex = index;
2490 private void x264BatchAddBtn_Click(object sender, EventArgs e)
2492 openFileDialog1.Multiselect = true;
2493 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2494 DialogResult result = openFileDialog1.ShowDialog();
2495 if (result == DialogResult.OK)
2497 lbAuto.Items.AddRange(openFileDialog1.FileNames);
2501 #endregion 视频页面
2503 #region 音频界面
2505 // <summary>
2506 /// 是否安装 Apple Application Support
2507 /// </summary>
2508 /// <returns>true:安装 false:没有安装</returns>
2509 private bool isAppleAppSupportInstalled()
2511 Microsoft.Win32.RegistryKey uninstallNode_1 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Wow6432Node\Apple Inc.\Apple Application Support"); //x64 OS
2512 Microsoft.Win32.RegistryKey uninstallNode_2 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Apple Inc.\Apple Application Support"); //x86 OS
2513 if (uninstallNode_1 != null || uninstallNode_2 != null)
2515 return true;
2517 else
2519 return false;
2523 private void AudioEncoderComboBox_SelectedIndexChanged(object sender, EventArgs e)
2525 switch (AudioEncoderComboBox.SelectedIndex)
2527 case 0:
2528 if (File.Exists(txtaudio2.Text))
2529 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.mp4");
2530 AudioBitrateComboBox.Enabled = true;
2531 AudioBitrateRadioButton.Enabled = true;
2532 AudioCustomizeRadioButton.Enabled = true;
2533 break;
2535 case 1:
2536 if (!isAppleAppSupportInstalled())
2538 if (ShowQuestion("Apple Application Support未安装.\r\n音频编码器QAAC可能无法使用.\r\n\r\n是否前往QuickTime下载页面?", "Apple Application Support未安装") == DialogResult.Yes)
2539 System.Diagnostics.Process.Start("http://www.apple.com/cn/quicktime/download");
2541 if (File.Exists(txtaudio2.Text))
2542 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.m4a");
2543 AudioBitrateComboBox.Enabled = true;
2544 AudioBitrateRadioButton.Enabled = true;
2545 AudioCustomizeRadioButton.Enabled = true;
2546 break;
2548 case 2: if (File.Exists(txtaudio2.Text))
2549 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_WAV.wav");
2550 AudioBitrateComboBox.Enabled = false;
2551 AudioBitrateRadioButton.Enabled = false;
2552 AudioCustomizeRadioButton.Enabled = false;
2553 break;
2555 case 3:
2556 if (File.Exists(txtaudio2.Text))
2557 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_ALAC.m4a");
2558 AudioBitrateComboBox.Enabled = false;
2559 AudioBitrateRadioButton.Enabled = false;
2560 AudioCustomizeRadioButton.Enabled = false;
2561 break;
2563 case 4: if (File.Exists(txtaudio2.Text))
2564 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_FLAC.flac");
2565 AudioBitrateComboBox.Enabled = false;
2566 AudioBitrateRadioButton.Enabled = false;
2567 AudioCustomizeRadioButton.Enabled = false;
2568 break;
2570 case 5:
2571 if (File.Exists(txtaudio2.Text))
2572 AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.m4a");
2573 AudioBitrateComboBox.Enabled = true;
2574 AudioBitrateRadioButton.Enabled = true;
2575 AudioCustomizeRadioButton.Enabled = true;
2576 break;
2578 default:
2579 break;
2583 private void AudioListBox_DragDrop(object sender, DragEventArgs e)
2585 ListBox listbox = (ListBox)sender;
2586 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
2588 String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
2589 foreach (String s in files)
2591 listbox.Items.Add(s);
2593 return;
2595 indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
2596 if (indexoftarget != ListBox.NoMatches)
2598 string temp = listbox.Items[indexoftarget].ToString();
2599 listbox.Items[indexoftarget] = listbox.Items[indexofsource];
2600 listbox.Items[indexofsource] = temp;
2601 listbox.SelectedIndex = indexoftarget;
2605 private void AudioListBox_DragOver(object sender, DragEventArgs e)
2607 ListBox listbox = (ListBox)sender;
2608 if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(listbox))
2610 e.Effect = DragDropEffects.Move;
2612 else if (e.Data.GetDataPresent(DataFormats.FileDrop))
2614 e.Effect = DragDropEffects.Link;
2616 else e.Effect = DragDropEffects.None;
2619 private void AudioListBox_MouseDown(object sender, MouseEventArgs e)
2621 indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
2622 if (indexofsource != ListBox.NoMatches)
2624 ((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.All);
2628 private void AudioBatchButton_Click(object sender, EventArgs e)
2630 if (AudioListBox.Items.Count != 0)
2632 string finish, outputExt, codec;
2633 aac = "";
2634 switch (AudioEncoderComboBox.SelectedIndex)
2636 case 0: outputExt = "mp4"; codec = "AAC"; break;
2637 case 1: outputExt = "m4a"; codec = "AAC"; break;
2638 case 2: outputExt = "wav"; codec = "WAV"; break;
2639 case 3: outputExt = "m4a"; codec = "ALAC"; break;
2640 case 4: outputExt = "flac"; codec = "FLAC"; break;
2641 case 5: outputExt = "m4a"; codec = "AAC"; break;
2642 default: outputExt = "aac"; codec = "AAC"; break;
2644 for (int i = 0; i < this.AudioListBox.Items.Count; i++)
2646 string outname = "_" + codec + "." + outputExt;
2647 finish = Util.ChangeExt(AudioListBox.Items[i].ToString(), outname);
2648 aac += audiobat(AudioListBox.Items[i].ToString(), finish);
2649 aac += "\r\n";
2651 aac += "\r\ncmd";
2652 batpath = workPath + "\\aac.bat";
2653 File.WriteAllText(batpath, aac, UnicodeEncoding.Default);
2654 LogRecord(aac);
2655 System.Diagnostics.Process.Start(batpath);
2657 else ShowErrorMessage("请输入文件!");
2660 private void btnaudio2_Click(object sender, EventArgs e)
2662 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2663 DialogResult result = openFileDialog1.ShowDialog();
2664 if (result == DialogResult.OK)
2666 nameaudio2 = openFileDialog1.FileName;
2667 txtaudio2.Text = nameaudio2;
2671 private void btnout3_Click(object sender, EventArgs e)
2673 SaveFileDialog savefile = new SaveFileDialog();
2674 savefile.Filter = "所有文件(*.*)|*.*";
2675 //savefile.Filter = "音频(*.aac;*.wav;*.m4a;*.flac)|*.aac*.wav;*.m4a;*.flac;";
2676 DialogResult result = savefile.ShowDialog();
2677 if (result == DialogResult.OK)
2679 switch (AudioEncoderComboBox.SelectedIndex)
2681 case 0: nameout3 = savefile.FileName + ".mp4";
2682 break;
2684 case 1: nameout3 = savefile.FileName + ".m4a";
2685 break;
2687 case 2: nameout3 = savefile.FileName + ".wav";
2688 break;
2690 case 3: nameout3 = savefile.FileName + ".m4a";
2691 break;
2693 case 4: nameout3 = savefile.FileName + ".flac";
2694 break;
2696 case 5: nameout3 = savefile.FileName + ".m4a";
2697 break;
2699 default:
2700 break;
2703 AudioOutputTextBox.Text = nameout3;
2707 private void btnaac_Click(object sender, EventArgs e)
2709 if (nameaudio2 == "")
2711 ShowErrorMessage("请选择音频文件");
2713 else if (nameout3 == "")
2715 ShowErrorMessage("请选择输出文件");
2717 else
2719 //ffmpeg = "\"" + workpath + "\\ffmpeg.exe\" -y -i \"" + nameaudio2 + "\" -f wav temp.wav";
2720 //int AACbr = 1024 * Convert.ToInt32(numq.Value.ToString());
2721 //string br = AACbr.ToString();
2722 //neroaac = "\"" + workpath + "\\neroAacEnc.exe\" -ignorelength -lc -br " + br + " -if \"temp.wav\" -of \"" + nameout3 + "\"";
2723 //aac = ffmpeg + "&&" + neroaac + "\r\ncmd";
2724 batpath = workPath + "\\aac.bat";
2725 File.WriteAllText(batpath, audiobat(nameaudio2, nameout3), UnicodeEncoding.Default);
2726 LogRecord(audiobat(nameaudio2, nameout3));
2727 System.Diagnostics.Process.Start(batpath);
2731 private void txtaudio2_TextChanged(object sender, EventArgs e)
2733 if (File.Exists(txtaudio2.Text.ToString()))
2735 nameaudio2 = txtaudio2.Text;
2736 switch (AudioEncoderComboBox.SelectedIndex)
2738 case 0: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.mp4"); break;
2739 case 1: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.m4a"); break;
2740 case 2: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_WAV.wav"); break;
2741 case 3: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_ALAC.m4a"); break;
2742 case 4: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_FLAC.flac"); break;
2743 case 5: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.m4a"); break;
2744 default: AudioOutputTextBox.Text = Util.ChangeExt(txtaudio2.Text, "_AAC.aac"); break;
2749 private void txtout3_TextChanged(object sender, EventArgs e)
2751 nameout3 = AudioOutputTextBox.Text;
2754 private void txtaudio2_MouseDoubleClick(object sender, MouseEventArgs e)
2756 if (File.Exists(txtaudio2.Text.ToString()))
2758 System.Diagnostics.Process.Start(txtaudio2.Text.ToString());
2762 private void radioButton5_CheckedChanged(object sender, EventArgs e)
2764 lbaacrate.Visible = false;
2765 lbaackbps.Visible = false;
2766 AudioBitrateComboBox.Visible = false;
2767 AudioCustomParameterTextBox.Visible = true;
2768 AudioPresetLabel.Visible = true;
2769 AudioPresetComboBox.Visible = true;
2772 private void radioButton4_CheckedChanged(object sender, EventArgs e)
2774 lbaacrate.Visible = true;
2775 lbaackbps.Visible = true;
2776 AudioBitrateComboBox.Visible = true;
2777 AudioCustomParameterTextBox.Visible = false;
2778 AudioPresetLabel.Visible = false;
2779 AudioPresetComboBox.Visible = false;
2782 private void AudioAddButton_Click(object sender, EventArgs e)
2784 openFileDialog1.Multiselect = true;
2785 openFileDialog1.Filter = "所有文件(*.*)|*.*";
2786 DialogResult result = openFileDialog1.ShowDialog();
2787 if (result == DialogResult.OK)
2789 AudioListBox.Items.AddRange(openFileDialog1.FileNames);
2793 private void AudioDeleteButton_Click(object sender, EventArgs e)
2795 if (AudioListBox.Items.Count > 0)
2797 if (AudioListBox.SelectedItems.Count > 0)
2799 int index = AudioListBox.SelectedIndex;
2800 AudioListBox.Items.RemoveAt(AudioListBox.SelectedIndex);
2801 if (index == AudioListBox.Items.Count)
2803 AudioListBox.SelectedIndex = index - 1;
2805 if (index >= 0 && index < AudioListBox.Items.Count && AudioListBox.Items.Count > 0)
2807 AudioListBox.SelectedIndex = index;
2813 private void AudioClearButton_Click(object sender, EventArgs e)
2815 AudioListBox.Items.Clear();
2818 #endregion 音频界面
2820 #region AVS页面
2822 private void GenerateAVS()
2824 //if (Directory.Exists("avsfilter"))
2826 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
2827 // foreach (FileInfo FileName in TheFolder.GetFiles())
2828 // {
2829 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
2830 // }
2832 avsBuilder.Remove(0, avsBuilder.Length);
2833 string vsfilterDLLPath = Path.Combine(workPath, @"avsfilter\VSFilter.DLL");
2834 string LSMASHSourceDLLPath = Path.Combine(workPath, @"avsfilter\LSMASHSource.DLL");
2835 string undotDLLPath = Path.Combine(workPath, @"avsfilter\UnDot.DLL");
2836 avsBuilder.AppendLine("LoadPlugin(\"" + vsfilterDLLPath + "\")");
2837 avsBuilder.AppendLine("LoadPlugin(\"" + LSMASHSourceDLLPath + "\")");
2839 if (UndotCheckBox.Checked)
2840 avsBuilder.AppendLine("LoadPlugin(\"" + undotDLLPath + "\")");
2841 avsBuilder.AppendLine("LWLibavVideoSource(\"" + namevideo9 + "\")");
2842 avsBuilder.AppendLine("ConvertToYV12()");
2843 if (UndotCheckBox.Checked)
2844 avsBuilder.AppendLine("Undot()");
2845 if (TweakCheckBox.Checked)
2846 avsBuilder.AppendLine("Tweak(" + TweakChromaNumericUpDown.Value.ToString() + ", " + TweakSaturationNumericUpDown.Value.ToString() + ", " + TweakBrightnessNumericUpDown.Value.ToString() + ", " + TweakContrastNumericUpDown.Value.ToString() + ")");
2847 if (LevelsCheckBox.Checked)
2848 avsBuilder.AppendLine("Levels(0," + LevelsNumericUpDown.Value.ToString() + ",255,0,255)");
2849 if (LanczosResizeCheckBox.Checked)
2850 avsBuilder.AppendLine("LanczosResize(" + AVSWidthNumericUpDown.Value.ToString() + "," + AVSHeightNumericUpDown.Value.ToString() + ")");
2851 if (SharpenCheckBox.Checked)
2852 avsBuilder.AppendLine("Sharpen(" + SharpenNumericUpDown.Value.ToString() + ")");
2853 if (CropCheckBox.Checked)
2854 avsBuilder.AppendLine("Crop(" + AVSCropTextBox.Text + ")");
2855 if (AddBordersCheckBox.Checked)
2856 avsBuilder.AppendLine("AddBorders(" + AddBorders1NumericUpDown.Value.ToString() + "," + AddBorders2NumericUpDown.Value.ToString() + "," + AddBorders3NumericUpDown.Value.ToString() + "," + AddBorders4NumericUpDown.Value.ToString() + ")");
2857 if (!string.IsNullOrEmpty(txtsub9.Text))
2859 if (Path.GetExtension(namesub9) == ".idx")
2860 avsBuilder.AppendLine("vobsub(\"" + namesub9 + "\")");
2861 else
2862 avsBuilder.AppendLine("TextSub(\"" + namesub9 + "\")");
2864 if (TrimCheckBox.Checked)
2865 avsBuilder.AppendLine("Trim(" + TrimStartNumericUpDown.Value.ToString() + "," + TrimEndNumericUpDown.Value.ToString() + ")");
2866 AVSScriptTextBox.Text = avsBuilder.ToString();
2869 #region 更改AVS
2871 private void TweakCheckBox_CheckedChanged(object sender, EventArgs e)
2873 GenerateAVS();
2876 private void LanczosResizeCheckBox_CheckedChanged(object sender, EventArgs e)
2878 GenerateAVS();
2881 private void AddBordersCheckBox_CheckedChanged(object sender, EventArgs e)
2883 GenerateAVS();
2886 private void CropCheckBox_CheckedChanged(object sender, EventArgs e)
2888 GenerateAVS();
2891 private void TrimCheckBox_CheckedChanged(object sender, EventArgs e)
2893 GenerateAVS();
2896 private void LevelsCheckBox_CheckedChanged(object sender, EventArgs e)
2898 GenerateAVS();
2901 private void SharpenCheckBox_CheckedChanged(object sender, EventArgs e)
2903 GenerateAVS();
2906 private void UndotCheckBox_CheckedChanged(object sender, EventArgs e)
2908 GenerateAVS();
2911 private void TweakChromaNumericUpDown_ValueChanged(object sender, EventArgs e)
2913 GenerateAVS();
2916 private void TweakSaturationNumericUpDown_ValueChanged(object sender, EventArgs e)
2918 GenerateAVS();
2921 private void TweakBrightnessNumericUpDown_ValueChanged(object sender, EventArgs e)
2923 GenerateAVS();
2926 private void TweakContrastNumericUpDown_ValueChanged(object sender, EventArgs e)
2928 GenerateAVS();
2931 private void AVSWidthNumericUpDown_ValueChanged(object sender, EventArgs e)
2933 GenerateAVS();
2936 private void AVSHeightNumericUpDown_ValueChanged(object sender, EventArgs e)
2938 GenerateAVS();
2941 private void AddBorders1NumericUpDown_ValueChanged(object sender, EventArgs e)
2943 GenerateAVS();
2946 private void AddBorders2NumericUpDown_ValueChanged(object sender, EventArgs e)
2948 GenerateAVS();
2951 private void AddBorders3NumericUpDown_ValueChanged(object sender, EventArgs e)
2953 GenerateAVS();
2956 private void AddBorders4NumericUpDown_ValueChanged(object sender, EventArgs e)
2958 GenerateAVS();
2961 private void AVSCropTextBox_TextChanged(object sender, EventArgs e)
2963 GenerateAVS();
2966 private void TrimStartNumericUpDown_ValueChanged(object sender, EventArgs e)
2968 GenerateAVS();
2971 private void TrimEndNumericUpDown_ValueChanged(object sender, EventArgs e)
2973 GenerateAVS();
2976 private void LevelsNumericUpDown_ValueChanged(object sender, EventArgs e)
2978 GenerateAVS();
2981 private void SharpenNumericUpDown_ValueChanged(object sender, EventArgs e)
2983 GenerateAVS();
2986 #endregion 更改AVS
2988 #endregion AVS页面
2990 private void ExtractMP4Button_Click(object sender, EventArgs e)
2992 openFileDialog1.Filter = "视频(*.mp4)|*.mp4|所有文件(*.*)|*.*";
2993 DialogResult result = openFileDialog1.ShowDialog();
2994 if (result == DialogResult.OK)
2996 namevideo = openFileDialog1.FileName;
2997 ExtractMP4TextBox.Text = namevideo;
3001 private void txtAVS_TextChanged(object sender, EventArgs e)
3003 Match m = Regex.Match(AVSScriptTextBox.Text, "ource\\(\"[a-zA-Z]:\\\\.+\\.\\w+\"");
3004 if (m.Success)
3006 string str = m.ToString();
3007 str = str.Replace("ource(\"", "");
3008 str = str.Replace("\"", "");
3009 str = Util.ChangeExt(str, "_AVS.mp4");
3010 txtout9.Text = str;
3014 public void Log(string path)
3016 ProcessStartInfo start = new ProcessStartInfo(path);//设置运行的命令行文件问ping.exe文件,这个文件系统会自己找到
3017 //如果是其它exe文件,则有可能需要指定详细路径,如运行winRar.exe
3018 start.CreateNoWindow = false;//不显示dos命令行窗口
3019 start.RedirectStandardOutput = true;//
3020 start.RedirectStandardInput = true;//
3021 start.UseShellExecute = false;//是否指定操作系统外壳进程启动程序
3022 Process p = Process.Start(start);
3023 StreamReader reader = p.StandardOutput;//截取输出流
3024 string line = reader.ReadLine();//每次读取一行
3025 StringBuilder log = new StringBuilder(2000);
3026 while (!reader.EndOfStream)
3028 log.Append(line + "\r\n");
3029 line = reader.ReadLine();
3031 p.WaitForExit();//等待程序执行完退出进程
3032 File.WriteAllText(startpath + "\\log.txt", log.ToString(), UnicodeEncoding.Default);
3033 p.Close();//关闭进程
3034 reader.Close();//关闭流
3037 public void LogRecord(string log)
3039 Util.ensureDirectoryExists(logPath);
3040 File.AppendAllText(logFileName,
3041 "===========" + DateTime.Now.ToString() + "===========\r\n" + log + "\r\n\r\n", UnicodeEncoding.Default);
3044 private void DeleteLogButton_Click(object sender, EventArgs e)
3046 if (Directory.Exists(logPath))
3048 Util.DeleteDirectoryIfExists(logPath, true);
3049 ShowInfoMessage("已经删除日志文件。");
3051 else ShowInfoMessage("没有找到日志文件。");
3054 private void ViewLogButton_Click(object sender, EventArgs e)
3056 if (File.Exists(logFileName))
3058 System.Diagnostics.Process.Start(logFileName);
3060 else ShowInfoMessage("没有找到日志文件。");
3063 private void x264PathButton_Click(object sender, EventArgs e)
3065 FolderBrowserDialog fbd = new FolderBrowserDialog();
3066 if (fbd.ShowDialog() == DialogResult.OK)
3067 x264PathTextBox.Text = fbd.SelectedPath;
3070 private void ExtractMP4TextBox_TextChanged(object sender, EventArgs e)
3072 namevideo = ExtractMP4TextBox.Text;
3075 private void MaintainResolutionCheckBox_CheckedChanged(object sender, EventArgs e)
3077 if (MaintainResolutionCheckBox.Checked)
3079 x264WidthNum.Value = 0;
3080 x264HeightNum.Value = 0;
3081 x264WidthNum.Enabled = false;
3082 x264HeightNum.Enabled = false;
3084 else
3086 x264WidthNum.Enabled = true;
3087 x264HeightNum.Enabled = true;
3091 #region globalization
3093 public static void SetLang(string lang, Form form, Type formType)
3095 System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
3096 if (form != null)
3098 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(formType);
3099 resources.ApplyResources(form, "$this");
3100 AppLang(form, resources);
3104 private static void AppLang(Control control, System.ComponentModel.ComponentResourceManager resources)
3106 foreach (Control c in control.Controls)
3108 resources.ApplyResources(c, c.Name);
3109 AppLang(c, resources);
3113 private void languageComboBox_SelectedIndexChanged(object sender, EventArgs e)
3115 //StreamReader sr;
3116 x264Mode1RadioButton.Checked = true;
3117 AudioBitrateRadioButton.Checked = true;
3118 int x264AudioModeComboBoxIndex = 0;
3119 switch (languageComboBox.SelectedIndex)
3121 case 0:
3122 SetLang("zh-CN", this, typeof(MainForm));
3123 this.Text = String.Format("小丸工具箱 {0}", Assembly.GetExecutingAssembly().GetName().Version.Build);
3124 x264PriorityComboBox.Items.Clear();
3125 x264PriorityComboBox.Items.AddRange(new string[] { "低", "低于标准", "普通", "高于标准", "高", "实时" });
3126 x264PriorityComboBox.SelectedIndex = 2;
3127 x264AudioModeComboBoxIndex = x264AudioModeComboBox.SelectedIndex;
3128 x264AudioModeComboBox.Items.Clear();
3129 x264AudioModeComboBox.Items.Add("压制音频");
3130 x264AudioModeComboBox.Items.Add("无音频流");
3131 x264AudioModeComboBox.SelectedIndex = x264AudioModeComboBoxIndex;
3132 x264VideoTextBox.EmptyTextTip = "可以把文件拖拽到这里";
3133 x264SubTextBox.EmptyTextTip = "双击清空字幕文件文本框";
3134 //x264OutTextBox.EmptyTextTip = "宽度和高度全为0即不改变分辨率";
3135 x264PathTextBox.EmptyTextTip = "字幕文件和视频文件在同一目录下且同名,不同名仅有语言后缀时请在右方选择或输入";
3136 //txtvideo3.EmptyTextTip = "音频参数在音频选项卡设定";
3137 ExtractMP4TextBox.EmptyTextTip = "抽取的视频或音频在原视频目录下";
3138 txtvideo8.EmptyTextTip = "抽取的视频或音频在原视频目录下";
3139 txtvideo6.EmptyTextTip = "抽取的视频或音频在原视频目录下";
3140 //load Help Text
3141 if (File.Exists(startpath + "\\help.rtf"))
3143 HelpTextBox.LoadFile(startpath + "\\help.rtf");
3145 break;
3147 case 1:
3148 SetLang("zh-TW", this, typeof(MainForm));
3149 this.Text = String.Format("小丸工具箱 {0}", Assembly.GetExecutingAssembly().GetName().Version.Build);
3150 x264PriorityComboBox.Items.Clear();
3151 x264PriorityComboBox.Items.AddRange(new string[] { "低", "在標準以下", "標準", "在標準以上", "高", "即時" });
3152 x264PriorityComboBox.SelectedIndex = 2;
3153 x264AudioModeComboBoxIndex = x264AudioModeComboBox.SelectedIndex;
3154 x264AudioModeComboBox.Items.Clear();
3155 x264AudioModeComboBox.Items.Add("壓制音頻");
3156 x264AudioModeComboBox.Items.Add("無音頻流");
3157 x264AudioModeComboBox.SelectedIndex = x264AudioModeComboBoxIndex;
3158 x264VideoTextBox.EmptyTextTip = "可以把文件拖拽到這裡";
3159 x264SubTextBox.EmptyTextTip = "雙擊清空字幕檔案文本框";
3160 //x264OutTextBox.EmptyTextTip = "寬度和高度全為0即不改變解析度";
3161 x264PathTextBox.EmptyTextTip = "字幕和視頻在同一資料夾下且同名,不同名僅有語言後綴時請在右方選擇或輸入";
3162 //txtvideo3.EmptyTextTip = "音頻參數需在音頻選項卡设定";
3163 ExtractMP4TextBox.EmptyTextTip = "新檔案生成在原資料夾";
3164 txtvideo8.EmptyTextTip = "新檔案生成在原資料夾";
3165 txtvideo6.EmptyTextTip = "新檔案生成在原資料夾";
3166 //load Help Text
3167 if (File.Exists(startpath + "\\help_zh_tw.rtf"))
3169 HelpTextBox.LoadFile(startpath + "\\help_zh_tw.rtf");
3171 break;
3173 case 2:
3174 SetLang("en-US", this, typeof(MainForm));
3175 this.Text = String.Format("Maruko Toolbox {0}", Assembly.GetExecutingAssembly().GetName().Version.Build);
3176 x264PriorityComboBox.Items.Clear();
3177 x264PriorityComboBox.Items.AddRange(new string[] { "Idle", "BelowNormal", "Normal", "AboveNormal", "High", "RealTime" });
3178 x264PriorityComboBox.SelectedIndex = 2;
3179 x264AudioModeComboBoxIndex = x264AudioModeComboBox.SelectedIndex;
3180 x264AudioModeComboBox.Items.Clear();
3181 x264AudioModeComboBox.Items.Add("with audio");
3182 x264AudioModeComboBox.Items.Add("no audio");
3183 x264AudioModeComboBox.SelectedIndex = x264AudioModeComboBoxIndex;
3184 x264VideoTextBox.EmptyTextTip = "Drag file here";
3185 x264SubTextBox.EmptyTextTip = "Clear subtitle text box by double click";
3186 //x264OutTextBox.EmptyTextTip = "Both the width and height equal zero means using original resolution";
3187 x264PathTextBox.EmptyTextTip = "Subtitle and Video must be of the same name and in the same folder";
3188 //txtvideo3.EmptyTextTip = "It is necessary to set audio parameter in the Audio tab";
3189 ExtractMP4TextBox.EmptyTextTip = "New file will be created in the original folder";
3190 txtvideo8.EmptyTextTip = "New file will be created in the original folder";
3191 txtvideo6.EmptyTextTip = "New file will be created in the original folder";
3192 //load Help Text
3193 if (File.Exists(startpath + "\\help.rtf"))
3195 HelpTextBox.LoadFile(startpath + "\\help.rtf");
3197 break;
3199 case 3:
3200 SetLang("ja-JP", this, typeof(MainForm));
3201 this.Text = String.Format("Maruko Toolbox {0}", Assembly.GetExecutingAssembly().GetName().Version.Build);
3202 x264PriorityComboBox.Items.Clear();
3203 x264PriorityComboBox.Items.AddRange(new string[] { "低", "通常以下", "通常", "通常以上", "高", "リアルタイム" });
3204 x264PriorityComboBox.SelectedIndex = 2;
3205 x264AudioModeComboBoxIndex = x264AudioModeComboBox.SelectedIndex;
3206 x264AudioModeComboBox.Items.Clear();
3207 x264AudioModeComboBox.Items.Add("オーディオ付き");
3208 x264AudioModeComboBox.Items.Add("オーディオなし");
3209 x264AudioModeComboBox.SelectedIndex = x264AudioModeComboBoxIndex;
3210 x264VideoTextBox.EmptyTextTip = "ビデオファイルをここに引きずってください";
3211 x264SubTextBox.EmptyTextTip = "ダブルクリックで字幕を削除する";
3212 //x264OutTextBox.EmptyTextTip = "Both the width and height equal zero means using original resolution";
3213 x264PathTextBox.EmptyTextTip = "字幕とビデオは同じ名前と同じフォルダにある必要があります";
3214 //txtvideo3.EmptyTextTip = "It is necessary to set audio parameter in the Audio tab";
3215 ExtractMP4TextBox.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
3216 txtvideo8.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
3217 txtvideo6.EmptyTextTip = "新しいファイルはビデオファイルのあるディレクトリに生成する";
3218 if (File.Exists(startpath + "\\help.rtf"))
3220 HelpTextBox.LoadFile(startpath + "\\help.rtf");
3222 break;
3224 default:
3225 break;
3229 #endregion globalization
3231 public static void RunProcess(string exe, string arg)
3233 Thread thread = new Thread(() =>
3235 ProcessStartInfo psi = new ProcessStartInfo(exe, arg);
3236 psi.CreateNoWindow = true;
3237 Process p = new Process();
3238 p.StartInfo = psi;
3239 p.Start();
3240 p.WaitForExit();
3241 MessageBox.Show("ts");
3242 p.Close();
3244 thread.IsBackground = true;
3245 thread.Start();
3248 private void AVSSaveButton_Click(object sender, EventArgs e)
3250 SaveFileDialog savefile = new SaveFileDialog();
3251 savefile.Filter = "AVS(*.avs)|*.avs";
3252 DialogResult result = savefile.ShowDialog();
3253 if (result == DialogResult.OK)
3255 File.WriteAllText(savefile.FileName, AVSScriptTextBox.Text, UnicodeEncoding.Default);
3259 private void MuxReplaceAudioButton_Click(object sender, EventArgs e)
3261 if (namevideo == "")
3263 ShowErrorMessage("请选择视频文件");
3264 return;
3266 if (nameaudio == "")
3268 ShowErrorMessage("请选择音频文件");
3269 return;
3271 if (nameout == "")
3273 ShowErrorMessage("请选择输出文件");
3274 return;
3276 mux = "";
3277 mux = "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + namevideo + "\" -c:v copy -an \"" + workPath + "\\video_noaudio.mp4\" \r\n";
3278 mux += "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + workPath + "\\video_noaudio.mp4\" -i \"" + nameaudio + "\" -vcodec copy -acodec copy \"" + nameout + "\" \r\n";
3279 mux += "del \"" + workPath + "\\video_noaudio.mp4\" \r\n";
3280 batpath = workPath + "\\mux.bat";
3281 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
3282 LogRecord(mux);
3283 Process.Start(batpath);
3286 #region 一图流
3288 private void AudioPicButton_Click(object sender, EventArgs e)
3290 openFileDialog1.Filter = "图片(*.jpg;*.jpeg;*.png;*.bmp;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件(*.*)|*.*";
3291 DialogResult result = openFileDialog1.ShowDialog();
3292 if (result == DialogResult.OK)
3294 AudioPicTextBox.Text = openFileDialog1.FileName;
3298 private void AudioPicAudioButton_Click(object sender, EventArgs e)
3300 openFileDialog1.Filter = "音频(*.aac;*.mp3;*.mp4;*.wav)|*.aac;*.mp3;*.mp4;*.wav|所有文件(*.*)|*.*";
3301 DialogResult result = openFileDialog1.ShowDialog();
3302 if (result == DialogResult.OK)
3304 AudioPicAudioTextBox.Text = openFileDialog1.FileName;
3308 private void AudioOnePicOutputButton_Click(object sender, EventArgs e)
3310 SaveFileDialog savefile = new SaveFileDialog();
3311 savefile.Filter = "MP4视频(*.mp4)|*.mp4|FLV视频(*.flv)|*.flv";
3312 savefile.FileName = "Single";
3313 DialogResult result = savefile.ShowDialog();
3314 if (result == DialogResult.OK)
3316 AudioOnePicOutputTextBox.Text = savefile.FileName;
3320 public int SecondsFromHHMMSS(string hhmmss)
3322 int hh = int.Parse(hhmmss.Substring(0, 2));
3323 int mm = int.Parse(hhmmss.Substring(3, 2));
3324 int ss = int.Parse(hhmmss.Substring(6, 2));
3325 return hh * 3600 + mm * 60 + ss;
3328 private void AudioOnePicButton_Click(object sender, EventArgs e)
3330 if (!File.Exists(AudioPicTextBox.Text))
3332 ShowErrorMessage("请选择图片文件");
3334 else if (!File.Exists(AudioPicAudioTextBox.Text))
3336 ShowErrorMessage("请选择音频文件");
3338 else if (AudioOnePicOutputTextBox.Text == "")
3340 ShowErrorMessage("请选择输出文件");
3342 else
3344 System.Drawing.Image img = System.Drawing.Image.FromFile(AudioPicTextBox.Text);
3345 // if not even number, chop 1 pixel out
3346 int newWidth = (img.Width % 2 == 0 ? img.Width : img.Width - 1);
3347 int newHeight = (img.Height % 2 == 0 ? img.Height : img.Height - 1);
3348 Rectangle cropArea;
3349 if (img.Width % 2 != 0 || img.Height % 2 != 0)
3351 Bitmap bmp = new Bitmap(img);
3352 cropArea = new Rectangle(0, 0, newWidth, newHeight);
3353 img = (Image)bmp.Clone(cropArea, bmp.PixelFormat);
3356 //if (img.Width % 2 != 0 || img.Height % 2 != 0)
3358 // MessageBox.Show("图片的长和宽必须是偶数。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3359 // img.Dispose();
3360 // return;
3362 //if (img.RawFormat.Equals(ImageFormat.Jpeg))
3364 // File.Copy(AudioPicTextBox.Text, tempPic, true);
3366 //else
3368 System.Drawing.Imaging.Encoder ImageEncoder = System.Drawing.Imaging.Encoder.Quality;
3369 EncoderParameter ep = new EncoderParameter(ImageEncoder, 100L);
3370 EncoderParameters eps = new EncoderParameters(1);
3371 ImageCodecInfo ImageCoderType = getImageCoderInfo("image/jpeg");
3372 eps.Param[0] = ep;
3373 img.Save(tempPic, ImageCoderType, eps);
3374 //img.Save(tempPic, ImageFormat.Jpeg);
3376 //获得音频时长
3377 MediaInfo MI = new MediaInfo();
3378 MI.Open(AudioPicAudioTextBox.Text);
3379 int seconds = SecondsFromHHMMSS(MI.Get(StreamKind.General, 0, "Duration/String3"));
3380 string ffPath = Path.Combine(workPath, "ffmpeg.exe");
3381 string neroPath = Path.Combine(workPath, "neroaacenc.exe");
3382 if (AudioCopyCheckBox.Checked)
3384 mux = "\"" + ffPath + "\" -loop 1 -r " + OnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + tempPic + "\" -c:v libx264 -crf " + OnePicCRFNum.Value.ToString() + " -y SinglePictureVideo.mp4\r\n";
3385 mux += "\"" + ffPath + "\" -i SinglePictureVideo.mp4 -i \"" + AudioPicAudioTextBox.Text + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
3386 mux += "del SinglePictureVideo.mp4\r\n";
3387 mux += "cmd";
3389 else
3391 mux = "\"" + ffPath + "\" -i \"" + AudioPicAudioTextBox.Text + "\" -f wav - |" + neroPath + " -br " + OnePicAudioBitrateNum.Value.ToString() + "000 -ignorelength -if - -of audio.mp4 -lc\r\n";
3392 mux += "\"" + ffPath + "\" -loop 1 -r " + OnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + tempPic + "\" -c:v libx264 -crf " + OnePicCRFNum.Value.ToString() + " -y SinglePictureVideo.mp4\r\n";
3393 mux += "\"" + ffPath + "\" -i SinglePictureVideo.mp4 -i audio.mp4 -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
3394 mux += "del SinglePictureVideo.mp4\r\ndel audio.mp4\r\n";
3395 mux += "cmd";
3398 string audioPath = AddExt(Path.GetFileName(AudioPicAudioTextBox.Text), "_atmp.mp4");
3399 string videoPath = AddExt(Path.GetFileName(AudioPicAudioTextBox.Text), "_vtmp.mp4");
3400 string picturePath = "c:\\" + Path.GetFileNameWithoutExtension(AudioPicTextBox.Text) + "_tmp.jpg";
3401 if (AudioCopyCheckBox.Checked)
3403 mux = "ffmpeg -loop 1 -r " + AudioOnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + picturePath + "\" -vcodec libx264 -crf 24 -y \"" + videoPath + "\"\r\n";
3404 mux += "ffmpeg -i \"" + videoPath + "\" -i \"" + AudioPicAudioTextBox.Text + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
3405 mux += "del \"" + videoPath + "\"\r\ndel \"" + picturePath + "\"\r\n";
3407 else
3409 mux = "ffmpeg -i \"" + AudioPicAudioTextBox.Text + "\" -f wav - |neroaacenc -br " + AudioOnePicAudioBitrateNum.Value.ToString() + "000 -ignorelength -if - -of \"" + audioPath + "\" -lc\r\n";
3410 mux += "ffmpeg -loop 1 -r " + AudioOnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + picturePath + "\" -vcodec libx264 -crf 24 -y \"" + videoPath + "\"\r\n";
3411 mux += "ffmpeg -i \"" + videoPath + "\" -i \"" + audioPath + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
3412 mux += "del \"" + videoPath + "\"\r\ndel \"" + audioPath + "\"\r\ndel \"" + picturePath + "\"\r\n";
3415 batpath = Path.Combine(workPath, Path.GetRandomFileName() + ".bat");
3416 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
3417 LogRecord(mux);
3418 Process.Start(batpath);
3422 private void txtMI_DragDrop(object sender, DragEventArgs e)
3424 MIvideo = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
3425 MediaInfoTextBox.Text = MediaInfo(MIvideo);
3428 private void txtMI_DragEnter(object sender, DragEventArgs e)
3430 if (e.Data.GetDataPresent(DataFormats.FileDrop))
3431 e.Effect = DragDropEffects.Link;
3432 else e.Effect = DragDropEffects.None;
3435 private void AudioPicAudioTextBox_TextChanged(object sender, EventArgs e)
3437 if (File.Exists(AudioPicAudioTextBox.Text.ToString()))
3439 AudioOnePicOutputTextBox.Text = Util.ChangeExt(AudioPicAudioTextBox.Text, "_SP.flv");
3443 /// <summary>
3444 /// 获取图片编码类型信息
3445 /// </summary>
3446 /// <param name="ImageCoderType">编码类型</param>
3447 /// <returns>ImageCodecInfo</returns>
3448 private ImageCodecInfo getImageCoderInfo(string ImageCoderType)
3450 ImageCodecInfo[] coderTypeArray = ImageCodecInfo.GetImageEncoders();
3451 foreach (ImageCodecInfo coderType in coderTypeArray)
3453 if (coderType.MimeType.Equals(ImageCoderType))
3454 return coderType;
3456 return null;
3459 #endregion 一图流
3461 #region 后黑
3463 private void BlackVideoButton_Click(object sender, EventArgs e)
3465 openFileDialog1.Filter = "FLV视频(*.flv)|*.flv";
3466 DialogResult result = openFileDialog1.ShowDialog();
3467 if (result == DialogResult.OK)
3469 BlackVideoTextBox.Text = openFileDialog1.FileName;
3473 private void BlackOutputButton_Click(object sender, EventArgs e)
3475 SaveFileDialog savefile = new SaveFileDialog();
3476 savefile.Filter = "FLV视频(*.flv)|*.flv";
3477 DialogResult result = savefile.ShowDialog();
3478 if (result == DialogResult.OK)
3480 BlackOutputTextBox.Text = savefile.FileName;
3484 private void BlackPicButton_Click(object sender, EventArgs e)
3486 openFileDialog1.Filter = "图片(*.jpg;*.jpeg;*.png;*.bmp;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件(*.*)|*.*";
3487 DialogResult result = openFileDialog1.ShowDialog();
3488 if (result == DialogResult.OK)
3490 BlackPicTextBox.Text = openFileDialog1.FileName;
3494 private void BlackStartButton_Click(object sender, EventArgs e)
3496 //验证
3497 if (!File.Exists(BlackVideoTextBox.Text) || Path.GetExtension(BlackVideoTextBox.Text) != ".flv")
3499 ShowErrorMessage("请选择FLV视频文件");
3500 return;
3503 MediaInfo MI = new MediaInfo();
3504 MI.Open(BlackVideoTextBox.Text);
3505 double videobitrate = double.Parse(MI.Get(StreamKind.General, 0, "BitRate"));
3506 double targetBitrate = (double)BlackBitrateNum.Value;
3508 if (!File.Exists(BlackPicTextBox.Text) && BlackNoPicCheckBox.Checked == false)
3510 ShowErrorMessage("请选择图片文件或勾选使用黑屏");
3511 return;
3513 if (BlackOutputTextBox.Text == "")
3515 ShowErrorMessage("请选择输出文件");
3516 return;
3519 if (videobitrate < 1000000)
3521 ShowInfoMessage("此视频不需要后黑。");
3522 return;
3524 if (videobitrate > 5000000)
3526 ShowInfoMessage("此视频码率过大,请先压制再后黑。");
3527 return;
3530 //处理图片
3531 int videoWidth = int.Parse(MI.Get(StreamKind.Video, 0, "Width"));
3532 int videoHeight = int.Parse(MI.Get(StreamKind.Video, 0, "Height"));
3533 if (BlackNoPicCheckBox.Checked)
3535 Bitmap bm = new Bitmap(videoWidth, videoHeight);
3536 Graphics g = Graphics.FromImage(bm);
3537 //g.FillRectangle(Brushes.White, new Rectangle(0, 0, 800, 600));
3538 g.Clear(Color.Black);
3539 bm.Save(tempPic, ImageFormat.Jpeg);
3540 g.Dispose();
3541 bm.Dispose();
3543 else
3545 System.Drawing.Image img = System.Drawing.Image.FromFile(BlackPicTextBox.Text);
3546 int sourceWidth = img.Width;
3547 int sourceHeight = img.Height;
3548 if (img.Width % 2 != 0 || img.Height % 2 != 0)
3550 ShowErrorMessage("图片的长和宽必须都是偶数。");
3551 img.Dispose();
3552 return;
3554 if (img.Width != videoWidth || img.Height != videoHeight)
3556 ShowErrorMessage("图片的长和宽和视频不一致。");
3557 img.Dispose();
3558 return;
3560 if (img.RawFormat.Equals(ImageFormat.Jpeg))
3562 File.Copy(BlackPicTextBox.Text, tempPic, true);
3564 else
3566 System.Drawing.Imaging.Encoder ImageEncoder = System.Drawing.Imaging.Encoder.Quality;
3567 EncoderParameter ep = new EncoderParameter(ImageEncoder, 100L);
3568 EncoderParameters eps = new EncoderParameters(1);
3569 ImageCodecInfo ImageCoderType = getImageCoderInfo("image/jpeg");
3570 eps.Param[0] = ep;
3571 img.Save(tempPic, ImageCoderType, eps);
3572 //img.Save(tempPic, ImageFormat.Jpeg);
3575 int blackSecond = 300;
3576 //计算后黑时长
3577 if (BlackSecondComboBox.Text == "auto")
3579 int seconds = SecondsFromHHMMSS(MI.Get(StreamKind.General, 0, "Duration/String3"));
3580 double s = videobitrate / 1000.0 * (double)seconds / targetBitrate - (double)seconds;
3581 blackSecond = (int)s;
3582 BlackSecondComboBox.Text = blackSecond.ToString();
3584 else
3586 blackSecond = int.Parse(Regex.Replace(BlackSecondComboBox.Text.ToString(), @"\D", "")); //排除除数字外的所有字符
3589 //批处理
3590 mux = "\"" + workPath + "\\ffmpeg\" -loop 1 -r " + BlackFPSNum.Value.ToString() + " -t " + blackSecond.ToString() + " -f image2 -i \"" + tempPic + "\" -c:v libx264 -crf " + BlackCRFNum.Value.ToString() + " -y black.flv\r\n";
3591 mux += string.Format("\"{0}\\flvbind\" \"{1}\" \"{2}\" black.flv\r\n", workPath, BlackOutputTextBox.Text, BlackVideoTextBox.Text);
3592 mux += "del black.flv\r\n";
3594 batpath = Path.Combine(workPath, Path.GetRandomFileName() + ".bat");
3595 File.WriteAllText(batpath, mux, UnicodeEncoding.Default);
3596 LogRecord(mux);
3597 Process.Start(batpath);
3600 private void BlackVideoTextBox_TextChanged(object sender, EventArgs e)
3602 string path = BlackVideoTextBox.Text;
3603 if (File.Exists(path))
3605 BlackOutputTextBox.Text = Util.ChangeExt(path, "_black.flv");
3609 #endregion 后黑
3611 private void BlackNoPicCheckBox_CheckedChanged(object sender, EventArgs e)
3613 BlackPicTextBox.Enabled = !BlackNoPicCheckBox.Checked;
3614 BlackPicButton.Enabled = !BlackNoPicCheckBox.Checked;
3617 private void BlackSecondComboBox_SelectedIndexChanged(object sender, EventArgs e)
3619 if (BlackSecondComboBox.Text != "auto")
3621 BlackBitrateNum.Enabled = false;
3623 else
3625 BlackBitrateNum.Enabled = true;
3629 private void SetDefaultButton_Click(object sender, EventArgs e)
3631 InitParameter();
3634 //Ctrl+A 可以全选文本
3635 private void MediaInfoTextBox_KeyDown(object sender, KeyEventArgs e)
3637 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
3639 ((TextBox)sender).SelectAll();
3643 private void AVSScriptTextBox_KeyDown(object sender, KeyEventArgs e)
3645 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
3647 ((TextBox)sender).SelectAll();
3651 private void x264CustomParameterTextBox_KeyDown(object sender, KeyEventArgs e)
3653 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
3655 ((TextBox)sender).SelectAll();
3659 #region CheckUpdate
3661 public delegate bool CheckUpadateDelegate(out DateTime newdate, out bool isFullUpdate);
3663 public void CheckUpdateCallBack(IAsyncResult ar)
3665 DateTime NewDate;
3666 bool isFullUpdate;
3667 AsyncResult result = (AsyncResult)ar;
3668 CheckUpadateDelegate func = (CheckUpadateDelegate)result.AsyncDelegate;
3672 bool needUpdate = func.EndInvoke(out NewDate, out isFullUpdate, ar);
3673 if (needUpdate)
3675 if (isFullUpdate)
3677 DialogResult dr = MessageBox.Show(string.Format("新版已于{0}发布,是否前往官网下载?", NewDate.ToString("yyyy-M-d")), "喜大普奔", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
3678 if (dr == DialogResult.Yes)
3680 Process.Start("http://www.maruko.in/");
3683 else
3685 DialogResult dr = MessageBox.Show(string.Format("新版已于{0}发布,是否自动升级?(文件约1.5MB)", NewDate.ToString("yyyy-M-d")), "喜大普奔", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
3686 if (dr == DialogResult.Yes)
3688 FormUpdater formUpdater = new FormUpdater(startpath, NewDate.ToString());
3689 formUpdater.ShowDialog(this);
3693 else
3695 //MessageBox.Show("已经是最新版了喵!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
3698 catch (Exception) { }
3701 public bool CheckUpdate(out DateTime NewDate, out bool isFullUpdate)
3703 WebRequest request = WebRequest.Create("http://mtbftest.sinaapp.com/version.php");
3704 WebResponse wrs = request.GetResponse();
3705 // read the response ...
3706 Stream dataStream = wrs.GetResponseStream();
3707 // Open the stream using a StreamReader for easy access.
3708 StreamReader reader = new StreamReader(dataStream);
3709 // Read the content.
3710 string responseFromServer = reader.ReadToEnd();
3711 Regex dateReg = new Regex(@"Date20\S+Date");
3712 Regex VersionReg = new Regex(@"Version\d+Version");
3713 Match dateMatch = dateReg.Match(responseFromServer);
3714 Match versionMatch = VersionReg.Match(responseFromServer);
3715 NewDate = DateTime.Parse("1990-03-08");
3716 isFullUpdate = false;
3717 if (dateMatch.Success)
3719 string date = dateMatch.Value.Replace("Date", "");
3720 string version = versionMatch.Value.Replace("Version", "");
3721 NewDate = DateTime.Parse(date);
3722 int NewVersion = int.Parse(version);
3723 int s = DateTime.Compare(NewDate, ReleaseDate);
3725 int currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Minor;
3726 if (NewVersion > currentVersion)
3728 isFullUpdate = true;
3730 else
3732 isFullUpdate = false;
3734 //DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
3735 if (s == 1) //NewDate is later than ReleaseDate
3737 return true;
3739 else
3741 return false;
3744 return false;
3747 private void CheckUpdateButton_Click(object sender, EventArgs e)
3749 if (Util.IsConnectInternet())
3751 WebRequest request = WebRequest.Create("http://mtbftest.sinaapp.com/version.php");
3752 request.Credentials = CredentialCache.DefaultCredentials;
3753 // Get the response.
3754 request.BeginGetResponse(new AsyncCallback(OnResponse), request);
3756 else
3758 ShowErrorMessage("这台电脑似乎没有联网呢~");
3762 protected void OnResponse(IAsyncResult ar)
3764 WebRequest wrq = (WebRequest)ar.AsyncState;
3765 WebResponse wrs = wrq.EndGetResponse(ar);
3766 // read the response ...
3767 Stream dataStream = wrs.GetResponseStream();
3768 // Open the stream using a StreamReader for easy access.
3769 StreamReader reader = new StreamReader(dataStream);
3770 // Read the content.
3771 string responseFromServer = reader.ReadToEnd();
3772 Regex dateReg = new Regex(@"Date20\S+Date");
3773 Regex VersionReg = new Regex(@"Version\d+Version");
3774 Match dateMatch = dateReg.Match(responseFromServer);
3775 Match versionMatch = VersionReg.Match(responseFromServer);
3776 DateTime NewDate = DateTime.Parse("1990-03-08");
3777 bool isFullUpdate = false;
3778 if (dateMatch.Success)
3780 string date = dateMatch.Value.Replace("Date", "");
3781 string version = versionMatch.Value.Replace("Version", "");
3782 NewDate = DateTime.Parse(date);
3783 int NewVersion = int.Parse(version);
3784 int s = DateTime.Compare(NewDate, ReleaseDate);
3786 int currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Minor;
3787 if (NewVersion > currentVersion)
3789 isFullUpdate = true;
3791 else
3793 isFullUpdate = false;
3795 //DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
3796 if (s == 1) //NewDate is later than ReleaseDate
3798 if (isFullUpdate)
3800 DialogResult dr = MessageBox.Show(string.Format("新版已于{0}发布,是否前往官网下载?", NewDate.ToString("yyyy-M-d")), "喜大普奔", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
3801 if (dr == DialogResult.Yes)
3803 Process.Start("http://www.maruko.in/");
3806 else
3808 DialogResult dr = MessageBox.Show(string.Format("新版已于{0}发布,是否自动升级?(文件约1.5MB)", NewDate.ToString("yyyy-M-d")), "喜大普奔", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
3809 if (dr == DialogResult.Yes)
3811 FormUpdater formUpdater = new FormUpdater(startpath, date);
3812 formUpdater.ShowDialog(this);
3816 else
3818 ShowInfoMessage("已经是最新版了喵!");
3821 else
3823 ShowInfoMessage("啊咧~似乎未能获取版本信息,请点击软件主页按钮查看最新版本。");
3827 #endregion CheckUpdate
3829 private void x264ShutdownCheckBox_CheckedChanged(object sender, EventArgs e)
3831 shutdownState = x264ShutdownCheckBox.Checked;
3834 private void TrayModeCheckBox_CheckedChanged(object sender, EventArgs e)
3836 trayMode = TrayModeCheckBox.Checked;
3839 private void ReleaseDatelabel_DoubleClick(object sender, EventArgs e)
3841 SplashForm sf = new SplashForm();
3842 sf.Owner = this;
3843 sf.Show();
3846 private void AudioCopyCheckBox_CheckedChanged(object sender, EventArgs e)
3848 OnePicAudioBitrateNum.Enabled = !AudioCopyCheckBox.Checked;
3851 private void HelpTextBox_LinkClicked(object sender, LinkClickedEventArgs e)
3853 Process.Start(e.LinkText);
3856 private void labelAudio_Click(object sender, EventArgs e)
3858 tabControl.SelectedIndex = 1;
3861 private void SetupAVSPlayerButton_Click(object sender, EventArgs e)
3863 openFileDialog1.Filter = "程序(*.exe)|*.exe|所有文件(*.*)|*.*";
3864 DialogResult result = openFileDialog1.ShowDialog();
3865 if (result == DialogResult.OK)
3867 SetupPlayerTextBox.Text = openFileDialog1.FileName;
3871 private void AVSAddFilterButton_Click(object sender, EventArgs e)
3873 string vsfilterDLLPath = Path.Combine(workPath, @"avsfilter\" + AVSFilterComboBox.Text);
3874 string text = "LoadPlugin(\"" + vsfilterDLLPath + "\")";
3875 Clipboard.SetText(text);
3876 ShowInfoMessage(text + "已经复制到剪贴板");
3879 private void AudioJoinButton_Click(object sender, EventArgs e)
3881 if (AudioListBox.Items.Count == 0)
3883 ShowErrorMessage("请输入文件!");
3884 return;
3886 else if (AudioOutputTextBox.Text == "")
3888 ShowErrorMessage("请选择输出文件");
3889 return;
3891 StringBuilder sb = new StringBuilder();
3892 ffmpeg = "";
3893 string ext = Path.GetExtension(AudioListBox.Items[0].ToString());
3894 string finish = Util.ChangeExt(AudioOutputTextBox.Text, ext);
3895 for (int i = 0; i < this.AudioListBox.Items.Count; i++)
3897 if (Path.GetExtension(AudioListBox.Items[i].ToString()) != ext)
3899 ShowErrorMessage("只允许合并相同格式文件。");
3900 return;
3902 sb.AppendLine("file '" + AudioListBox.Items[i].ToString() + "'");
3903 File.WriteAllText("concat.txt", sb.ToString());
3904 ffmpeg = "\"" + workPath + "\\ffmpeg.exe\" -f concat -i concat.txt -y -c copy " + finish;
3906 ffmpeg += "\r\ncmd";
3907 batpath = workPath + "\\concat.bat";
3908 File.WriteAllText(batpath, ffmpeg, UnicodeEncoding.Default);
3909 LogRecord(aac);
3910 System.Diagnostics.Process.Start(batpath);
3913 #region TabControl
3915 private void tabControl_DragOver(object sender, DragEventArgs e)
3917 if (e.Data.GetDataPresent(DataFormats.FileDrop))
3919 e.Effect = DragDropEffects.All;
3920 Point pt = new Point(e.X + 2, e.Y + 2);
3921 pt = PointToClient(pt);
3922 int pi = GetTabPageByTab(pt);
3923 if (pi != -1)
3925 tabControl.SelectedIndex = pi;
3928 else e.Effect = DragDropEffects.None;
3931 /// <summary>
3932 /// Finds the TabPage whose tab is contains the given point.
3933 /// </summary>
3934 /// <param name="pt">The point (given in client coordinates) to look for a TabPage.</param>
3935 /// <returns>The TabPage whose tab is at the given point (null if there isn't one).</returns>
3936 private int GetTabPageByTab(Point pt)
3938 TabPage tp = null;
3939 int pageIndex = -1;
3940 for (int i = 0; i < tabControl.TabPages.Count; i++)
3942 Rectangle a = tabControl.GetTabRect(i);
3944 if (tabControl.GetTabRect(i).Contains(pt))
3946 tp = tabControl.TabPages[i];
3947 pageIndex = i;
3948 break;
3951 return pageIndex;
3954 private void MainForm_KeyDown(object sender, KeyEventArgs e)
3956 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D1)
3958 tabControl.SelectedIndex = 0;
3960 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D2)
3962 tabControl.SelectedIndex = 1;
3964 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D3)
3966 tabControl.SelectedIndex = 2;
3968 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D4)
3970 tabControl.SelectedIndex = 3;
3972 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D5)
3974 tabControl.SelectedIndex = 4;
3976 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D6)
3978 tabControl.SelectedIndex = 5;
3980 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D7)
3982 tabControl.SelectedIndex = 6;
3984 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D8)
3986 tabControl.SelectedIndex = 7;
3988 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D9)
3990 tabControl.SelectedIndex = 8;
3994 #endregion TabControl
3996 private void gmkvextractguibButton_Click(object sender, EventArgs e)
3998 string path = workPath + "\\gMKVExtractGUI.exe";
4000 if (File.Exists(path))
4002 System.Diagnostics.Process.Start(path);
4004 else
4006 ShowErrorMessage("请检查\r\n\r\n" + path + "\r\n\r\n是否存在", "未找到程序!");
4010 private void FeedbackButton_Click(object sender, EventArgs e)
4012 FeedbackForm ff = new FeedbackForm();
4013 ff.ShowDialog();
4016 private void x264SubTextBox_DoubleClick(object sender, EventArgs e)
4018 x264SubTextBox.Clear();
4021 private void RotateButton_Click(object sender, EventArgs e)
4023 if (namevideo4 == "")
4025 ShowErrorMessage("请选择视频文件");
4027 else if (nameout5 == "")
4029 ShowErrorMessage("请选择输出文件");
4031 else
4033 clip = String.Format(@"""{0}\ffmpeg.exe"" -i ""{1}"" -vf ""transpose={2}"" -y ""{3}""",
4034 workPath, namevideo4, TransposeComboBox.SelectedIndex, nameout5) + Environment.NewLine + "cmd";
4035 batpath = workPath + "\\clip.bat";
4036 File.WriteAllText(batpath, clip, UnicodeEncoding.Default);
4037 Process.Start(batpath);
4041 private void AudioPresetComboBox_SelectedIndexChanged(object sender, EventArgs e)
4043 XElement x = xdoc.Element("root").Element("Audio").Elements().Where(_ => _.Attribute("Name").Value == AudioPresetComboBox.Text).First();
4044 AudioCustomParameterTextBox.Text = x.Value;
4047 private void lbAuto_DrawItem(object sender, DrawItemEventArgs e)
4049 if (e.Index < 0 || e.Index >= 65535)
4050 return;
4052 e.DrawBackground();
4053 SolidBrush BlueBrush = new SolidBrush(Color.Blue);
4054 SolidBrush BlackBrush = new SolidBrush(Color.Black);
4055 Color vColor = Color.Black;
4056 string input = lbAuto.Items[e.Index].ToString();
4057 if (!string.IsNullOrEmpty(GetSubtitlePath(input)))
4059 e.Graphics.DrawString(Convert.ToString(lbAuto.Items[e.Index]), e.Font, BlueBrush, e.Bounds);
4061 else
4063 e.Graphics.DrawString(Convert.ToString(lbAuto.Items[e.Index]), e.Font, BlackBrush, e.Bounds);
4068 private string GetSubtitlePath(string videoPath)
4070 string sub = "";
4071 string splang = "";
4072 string[] subExt = { ".ass", ".ssa", ".srt" };
4073 if (x264BatchSubSpecialLanguage.Text != "none")
4074 splang = "." + x264BatchSubSpecialLanguage.Text;
4075 foreach (string ext in subExt)
4077 if (File.Exists(videoPath.Remove(videoPath.LastIndexOf(".")) + splang + ext))
4079 sub = videoPath.Remove(videoPath.LastIndexOf(".")) + splang + ext;
4080 break;
4083 return sub;
4086 private void x264ExeComboBox_SelectedIndexChanged(object sender, EventArgs e)
4088 if (x264ExeComboBox.SelectedIndex == -1)
4089 return;
4091 if (x264ExeComboBox.SelectedItem.ToString().ToLower().Contains("ffmpeg"))
4093 x264Mode3RadioButton.Checked = true;
4094 x264Mode1RadioButton.Enabled = false;
4095 x264Mode2RadioButton.Enabled = false;
4097 else
4099 x264Mode1RadioButton.Checked = true;
4100 x264Mode1RadioButton.Enabled = true;
4101 x264Mode2RadioButton.Enabled = true;
4102 x264Mode3RadioButton.Enabled = true;