1
// ------------------------------------------------------------------
2 // Copyright (C) 2011-2016 Maruko Toolbox Project
4 // Authors: komaruchan <sandy_0308@hotmail.com>
5 // LunarShaddow <aflyhorse@hotmail.com>
6 // LYF <lyfjxymf@sina.com>
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 // -------------------------------------------------------------------
26 using System
.Collections
.Generic
;
27 using System
.ComponentModel
;
28 using System
.Configuration
;
29 using System
.Diagnostics
;
31 using System
.Drawing
.Imaging
;
35 using System
.Reflection
;
36 using System
.Runtime
.InteropServices
;
37 using System
.Runtime
.Remoting
.Messaging
;
39 using System
.Text
.RegularExpressions
;
40 using System
.Threading
;
41 using System
.Windows
.Forms
;
42 using System
.Xml
.Linq
;
46 public partial class MainForm
: Form
48 public string workPath
= "!undefined";
49 public bool shutdownState
= false;
50 public bool trayMode
= false;
51 private XDocument xdoc
;
53 #region Private Members Declaration
55 private StringBuilder avsBuilder
= new StringBuilder(1000);
56 private string syspath
= Environment
.GetFolderPath(Environment
.SpecialFolder
.System
).Remove(1);
57 private int indexofsource
;
58 private int indexoftarget
;
59 private byte x264mode
= 1;
60 private string clip
= "";
61 private string MIvideo
= "";
62 private string namevideo
= "";
63 private string namevideo2
= "";
64 private string namevideo4
= "";
65 private string namevideo5
= "";
66 private string namevideo6
= "";
67 private string nameaudio
= "";
68 private string nameaudio2
= "";
69 private string nameaudio3
= "";
70 private string namevideo8
= "";
71 private string namevideo9
= "video";
72 private string nameout
;
73 private string nameout2
;
74 private string nameout3
;
75 private string nameout5
;
76 private string nameout6
;
77 private string nameout9
;
78 private string namesub
;
79 private string namesub2
= "";
80 private string namesub9
= "subtitle";
81 private string MItext
= "把视频文件拖到这里";
82 private string mkvextract
;
83 private string mkvmerge
;
86 private string ffmpeg
;
88 private string aextract
;
89 private string batpath
;
91 private string startpath
;
92 private string avs
= "";
93 private string tempavspath
= "";
94 private string tempPic
= "";
95 private string logFileName
, logPath
;
96 private string tempfilepath
;
97 private DateTime ReleaseDate
= DateTime
.Parse("2015-9-10 8:0:0");
99 #endregion Private Members Declaration
101 #region CPU Porocessors Number
103 [StructLayout(LayoutKind
.Sequential
)]
104 public struct SYSTEM_INFO
107 public uint dwPageSize
;
108 public uint lpMinimumApplicationAddress
;
109 public uint lpMaximumApplicationAddress
;
110 public uint dwActiveProcessorMask
;
111 public uint dwNumberOfProcessors
;
112 public uint dwProcessorType
;
113 public uint dwAllocationGranularity
;
114 public uint dwProcessorLevel
;
115 public uint dwProcessorRevision
;
118 [DllImport("kernel32")]
119 private static extern void GetSystemInfo(ref SYSTEM_INFO pSI
);
121 #endregion CPU Porocessors Number
125 logPath
= Application
.StartupPath
+ "\\logs";
126 logFileName
= logPath
+ "\\LogFile-" + DateTime
.Now
.ToString("yyyy'-'MM'-'dd'_'HH'-'mm'-'ss") + ".log";
127 InitializeComponent();
130 public string GetMediaInfoString(string VideoName
)
132 StringBuilder info
= new StringBuilder();
133 if (File
.Exists(VideoName
))
135 MediaInfo MI
= new MediaInfo();
138 string container
= MI
.Get(StreamKind
.General
, 0, "Format");
139 string bitRate
= MI
.Get(StreamKind
.General
, 0, "BitRate/String");
140 string duration
= MI
.Get(StreamKind
.General
, 0, "Duration/String1");
141 string fileSize
= MI
.Get(StreamKind
.General
, 0, "FileSize/String");
143 string v_id
= MI
.Get(StreamKind
.Video
, 0, "ID");
144 string v_format
= MI
.Get(StreamKind
.Video
, 0, "Format");
145 string v_bitRate
= MI
.Get(StreamKind
.Video
, 0, "BitRate/String");
146 string v_size
= MI
.Get(StreamKind
.Video
, 0, "StreamSize/String");
147 string v_width
= MI
.Get(StreamKind
.Video
, 0, "Width");
148 string v_height
= MI
.Get(StreamKind
.Video
, 0, "Height");
149 string v_displayAspectRatio
= MI
.Get(StreamKind
.Video
, 0, "DisplayAspectRatio/String");
150 string v_displayAspectRatio2
= MI
.Get(StreamKind
.Video
, 0, "DisplayAspectRatio");
151 string v_frameRate
= MI
.Get(StreamKind
.Video
, 0, "FrameRate/String");
152 string v_colorSpace
= MI
.Get(StreamKind
.Video
, 0, "ColorSpace");
153 string v_chromaSubsampling
= MI
.Get(StreamKind
.Video
, 0, "ChromaSubsampling");
154 string v_bitDepth
= MI
.Get(StreamKind
.Video
, 0, "BitDepth/String");
155 string v_scanType
= MI
.Get(StreamKind
.Video
, 0, "ScanType/String");
156 string v_pixelAspectRatio
= MI
.Get(StreamKind
.Video
, 0, "PixelAspectRatio");
157 string v_encodedLibrary
= MI
.Get(StreamKind
.Video
, 0, "Encoded_Library/String");
158 string v_encodingSettings
= MI
.Get(StreamKind
.Video
, 0, "Encoded_Library_Settings");
159 string v_encodedTime
= MI
.Get(StreamKind
.Video
, 0, "Encoded_Date");
160 string v_codecProfile
= MI
.Get(StreamKind
.Video
, 0, "Codec_Profile");
161 string v_frameCount
= MI
.Get(StreamKind
.Video
, 0, "FrameCount");
164 string a_id
= MI
.Get(StreamKind
.Audio
, 0, "ID");
165 string a_format
= MI
.Get(StreamKind
.Audio
, 0, "Format");
166 string a_bitRate
= MI
.Get(StreamKind
.Audio
, 0, "BitRate/String");
167 string a_samplingRate
= MI
.Get(StreamKind
.Audio
, 0, "SamplingRate/String");
168 string a_channel
= MI
.Get(StreamKind
.Audio
, 0, "Channel(s)");
169 string a_size
= MI
.Get(StreamKind
.Audio
, 0, "StreamSize/String");
171 string audioInfo
= MI
.Get(StreamKind
.Audio
, 0, "Inform")
172 + MI
.Get(StreamKind
.Audio
, 1, "Inform")
173 + MI
.Get(StreamKind
.Audio
, 2, "Inform")
174 + MI
.Get(StreamKind
.Audio
, 3, "Inform");
175 string videoInfo
= MI
.Get(StreamKind
.Video
, 0, "Inform");
177 info
= info
.Append(Path
.GetFileName(VideoName
) + "\r\n");
178 if (!string.IsNullOrEmpty(container
))
179 info
.Append("容器:" + container
+ "\r\n");
180 if (!string.IsNullOrEmpty(bitRate
))
181 info
.Append("总码率:" + bitRate
+ "\r\n");
182 if (!string.IsNullOrEmpty(fileSize
))
183 info
.Append("大小:" + fileSize
+ "\r\n");
184 if (!string.IsNullOrEmpty(duration
))
185 info
.Append("时长:" + duration
+ "\r\n");
187 if (!string.IsNullOrEmpty(v_format
))
188 info
.Append("\r\n" + "视频(" + v_id
+ "):" + v_format
+ "\r\n");
189 if (!string.IsNullOrEmpty(v_codecProfile
))
190 info
.Append("Profile:" + v_codecProfile
+ "\r\n");
191 if (!string.IsNullOrEmpty(v_bitRate
))
192 info
.Append("码率:" + v_bitRate
+ "\r\n");
193 if (!string.IsNullOrEmpty(v_size
))
194 info
.Append("文件大小:" + v_size
+ "\r\n");
195 if (!string.IsNullOrEmpty(v_width
) && !string.IsNullOrEmpty(v_height
))
196 info
.Append("分辨率:" + v_width
+ "x" + v_height
+ "\r\n");
197 if (!string.IsNullOrEmpty(v_displayAspectRatio
) && !string.IsNullOrEmpty(v_displayAspectRatio2
))
198 info
.Append("画面比例:" + v_displayAspectRatio
+ "(" + v_displayAspectRatio2
+ ")" + "\r\n");
199 if (!string.IsNullOrEmpty(v_pixelAspectRatio
))
200 info
.Append("像素宽高比:" + v_pixelAspectRatio
+ "\r\n");
201 if (!string.IsNullOrEmpty(v_frameRate
))
202 info
.Append("帧率:" + v_frameRate
+ "\r\n");
203 if (!string.IsNullOrEmpty(v_colorSpace
))
204 info
.Append("色彩空间:" + v_colorSpace
+ "\r\n");
205 if (!string.IsNullOrEmpty(v_chromaSubsampling
))
206 info
.Append("色度抽样:" + v_chromaSubsampling
+ "\r\n");
207 if (!string.IsNullOrEmpty(v_bitDepth
))
208 info
.Append("位深度:" + v_bitDepth
+ "\r\n");
209 if (!string.IsNullOrEmpty(v_scanType
))
210 info
.Append("扫描方式:" + v_scanType
+ "\r\n");
211 if (!string.IsNullOrEmpty(v_encodedTime
))
212 info
.Append("编码时间:" + v_encodedTime
+ "\r\n");
213 if (!string.IsNullOrEmpty(v_frameCount
))
214 info
.Append("总帧数:" + v_frameCount
+ "\r\n");
215 if (!string.IsNullOrEmpty(v_encodedLibrary
))
216 info
.Append("编码库:" + v_encodedLibrary
+ "\r\n");
217 if (!string.IsNullOrEmpty(v_encodingSettings
))
218 info
.Append("编码设置:" + v_encodingSettings
+ "\r\n");
220 if (!string.IsNullOrEmpty(a_format
))
221 info
.Append("\r\n" + "音频(" + a_id
+ "):" + a_format
+ "\r\n");
222 if (!string.IsNullOrEmpty(a_size
))
223 info
.Append("大小:" + a_size
+ "\r\n");
224 if (!string.IsNullOrEmpty(a_bitRate
))
225 info
.Append("码率:" + a_bitRate
+ "\r\n");
226 if (!string.IsNullOrEmpty(a_samplingRate
))
227 info
.Append("采样率:" + a_samplingRate
+ "\r\n");
228 if (!string.IsNullOrEmpty(a_channel
))
229 info
.Append("声道数:" + a_channel
+ "\r\n");
230 info
.Append("\r\n====详细信息====\r\n" + videoInfo
+ "\r\n" + audioInfo
+ "\r\n");
234 info
.Append("文件不存在、非有效文件或者文件夹 无视频信息");
235 return info
.ToString();
238 public string ffmuxbat(string input1
, string input2
, string output
)
240 return "\"" + workPath
+ "\\ffmpeg.exe\" -i \"" + input1
+ "\" -i \"" + input2
+ "\" -sn -c copy -y \"" + output
+ "\"\r\n";
243 public string boxmuxbat(string input1
, string input2
, string output
)
245 return "\"" + workPath
+ "\\mp4box.exe\" -add \"" + input1
+ "#trackID=1:name=\" -add \"" + input2
+ "#trackID=1:name=\" -new \"" + output
+ "\"\r\n";
248 public string x264bat(string input
, string output
, int pass
= 1, string sub
= "")
250 StringBuilder sb
= new StringBuilder();
252 MediaInfo MI
= new MediaInfo();
254 string frameRate
= MI
.Get(StreamKind
.Video
, 0, "FrameRate");
256 string keyint
= "-1";
257 if (double.TryParse(frameRate
, out fps
))
259 fps
= Math
.Round(fps
);
260 keyint
= (fps
* 10).ToString();
263 if (Path
.GetExtension(input
) == ".avs")
264 sb
.Append("\"" + workPath
+ "\\avs4x26x.exe\"" + " -L ");
265 sb
.Append("\"" + Path
.Combine(workPath
, x264ExeComboBox
.SelectedItem
.ToString()) + "\"");
270 sb
.Append(" " + x264CustomParameterTextBox
.Text
);
274 sb
.Append(" --crf " + x264CRFNum
.Value
);
278 sb
.Append(" --pass " + pass
+ " --bitrate " + x264BitrateNum
.Value
+ " --stats \"" + Path
.Combine(tempfilepath
, Path
.GetFileNameWithoutExtension(output
)) + ".stats\"");
283 if (x264DemuxerComboBox
.Text
!= "auto" && x264DemuxerComboBox
.Text
!= string.Empty
)
284 sb
.Append(" --demuxer " + x264DemuxerComboBox
.Text
);
285 if (x264ThreadsComboBox
.SelectedItem
.ToString() != "auto" && x264ThreadsComboBox
.SelectedItem
.ToString() != string.Empty
)
286 sb
.Append(" --threads " + x264ThreadsComboBox
.SelectedItem
.ToString());
287 if (x264extraLine
.Text
!= string.Empty
)
288 sb
.Append(" " + x264extraLine
.Text
);
290 sb
.Append(" --preset 8 " + " -I " + keyint
+ " -r 4 -b 3 --me umh -i 1 --scenecut 60 -f 1:1 --qcomp 0.5 --psy-rd 0.3:0 --aq-mode 2 --aq-strength 0.8");
291 if (x264HeightNum
.Value
!= 0 && x264WidthNum
.Value
!= 0 && !MaintainResolutionCheckBox
.Checked
)
292 sb
.Append(" --vf resize:" + x264WidthNum
.Value
+ "," + x264HeightNum
.Value
+ ",,,,lanczos");
294 if (!string.IsNullOrEmpty(sub
))
296 string x264tmpline
= sb
.ToString();
297 if (x264tmpline
.IndexOf("--vf") == -1)
298 sb
.Append(" --vf subtitles --sub \"" + sub
+ "\"");
301 Regex r
= new Regex("--vf\\s\\S*");
302 Match m
= r
.Match(x264tmpline
);
303 sb
.Insert(m
.Index
+ 5, "subtitles/").Append(" --sub \"" + sub
+ "\"");
306 if (x264SeekNumericUpDown
.Value
!= 0)
307 sb
.Append(" --seek " + x264SeekNumericUpDown
.Value
.ToString());
308 if (x264FramesNumericUpDown
.Value
!= 0)
309 sb
.Append(" --frames " + x264FramesNumericUpDown
.Value
.ToString());
310 if (x264mode
== 2 && pass
== 1)
311 sb
.Append(" -o NUL");
312 else if (!string.IsNullOrEmpty(output
))
313 sb
.Append(" -o " + "\"" + output
+ "\"");
314 if (!string.IsNullOrEmpty(input
))
315 sb
.Append(" \"" + input
+ "\"");
316 return sb
.ToString();
319 public string x265bat(string input
, string output
, int pass
= 1)
321 StringBuilder sb
= new StringBuilder();
322 sb
.Append("\"" + workPath
+ "\\ffmpeg.exe\"" + " -i \"" + input
+ "\"");
323 if (x264HeightNum
.Value
!= 0 && x264WidthNum
.Value
!= 0 && !MaintainResolutionCheckBox
.Checked
)
324 sb
.Append(" -s " + x264WidthNum
.Value
+ "x" + x264HeightNum
.Value
);
325 sb
.Append(" -f yuv4mpegpipe -an -v 0 - | ");
326 sb
.Append(Util
.FormatPath(Path
.Combine(workPath
, x264ExeComboBox
.SelectedItem
.ToString())) + " --y4m");
331 sb
.Append(" " + x264CustomParameterTextBox
.Text
);
335 sb
.Append(" --crf " + x264CRFNum
.Value
);
339 sb
.Append(" --pass " + pass
+ " --bitrate " + x264BitrateNum
.Value
+ " --stats \"" + Path
.Combine(tempfilepath
, Path
.GetFileNameWithoutExtension(output
)) + ".stats\"");
344 if (x264extraLine
.Text
!= string.Empty
)
345 sb
.Append(" " + x264extraLine
.Text
);
347 sb
.Append(" --preset slower --tu-intra-depth 3 --tu-inter-depth 3 --rdpenalty 2 --me 3 --subme 5 --merange 44 --b-intra --no-rect --no-amp --ref 5 --weightb --bframes 8 --aq-mode 1 --aq-strength 1.0 --rd 5 --psy-rd 0.7 --psy-rdoq 5.0 --rdoq-level 1 --no-sao --no-open-gop --rc-lookahead 80 --scenecut 40 --max-merge 4 --qcomp 0.7 --no-strong-intra-smoothing --deblock -1:-1 --qg-size 16");
349 if (x264SeekNumericUpDown
.Value
!= 0)
350 sb
.Append(" --seek " + x264SeekNumericUpDown
.Value
.ToString());
351 if (x264FramesNumericUpDown
.Value
!= 0)
352 sb
.Append(" --frames " + x264FramesNumericUpDown
.Value
.ToString());
353 if (x264mode
== 2 && pass
== 1)
354 sb
.Append(" -o NUL");
355 else if (!string.IsNullOrEmpty(output
))
356 sb
.Append(" -o " + "\"" + output
+ "\"");
357 if (!string.IsNullOrEmpty(input
))
359 return sb
.ToString();
362 public static bool stringCheck(string str
, string info
= "")
364 if (string.IsNullOrEmpty(str
))
366 MessageBox
.Show("发现空或者无效的字符串 " + info
);
368 return string.IsNullOrEmpty(str
);
371 public string timeminus(int h1
, int m1
, int s1
, int h2
, int m2
, int s2
)
389 return h
.ToString() + ":" + m
.ToString() + ":" + s
.ToString();
392 public string timeplus(int h1
, int m1
, int s1
, int h2
, int m2
, int s2
)
410 return h
.ToString() + ":" + m
.ToString() + ":" + s
.ToString();
413 public string audiobat(string input
, string output
)
415 int AACbr
= 1000 * Convert
.ToInt32(AudioBitrateComboBox
.Text
);
416 string br
= AACbr
.ToString();
417 ffmpeg
= "\"" + workPath
+ "\\ffmpeg.exe\" -i \"" + input
+ "\" -vn -sn -v 0 -c:a pcm_s16le -f wav pipe:|";
418 switch (AudioEncoderComboBox
.SelectedIndex
)
421 if (AudioBitrateRadioButton
.Checked
)
423 ffmpeg
+= "\"" + workPath
+ "\\neroAacEnc.exe\" -ignorelength -lc -br " + br
+ " -if - -of \"" + output
+ "\"";
425 if (AudioCustomizeRadioButton
.Checked
)
427 ffmpeg
+= "\"" + workPath
+ "\\neroAacEnc.exe\" -ignorelength " + AudioCustomParameterTextBox
.Text
.ToString() + " -if - -of \"" + output
+ "\"";
432 if (AudioBitrateRadioButton
.Checked
)
434 ffmpeg
+= "\"" + workPath
+ "\\qaac.exe\" -q 2 --ignorelength -c " + AudioBitrateComboBox
.Text
+ " - -o \"" + output
+ "\"";
436 if (AudioCustomizeRadioButton
.Checked
)
438 ffmpeg
+= "\"" + workPath
+ "\\qaac.exe\" --ignorelength " + AudioCustomParameterTextBox
.Text
.ToString() + " - -o \"" + output
+ "\"";
443 if (Path
.GetExtension(output
) == ".aac")
444 output
= Util
.ChangeExt(output
, ".wav");
445 ffmpeg
= "\"" + workPath
+ "\\ffmpeg.exe\" -y -i \"" + input
+ "\" -f wav \"" + output
+ "\"";
449 ffmpeg
+= "\"" + workPath
+ "\\refalac.exe\" --ignorelength - -o \"" + output
+ "\"";
453 ffmpeg
+= "\"" + workPath
+ "\\flac.exe\" -f --ignore-chunk-sizes -5 - -o \"" + output
+ "\"";
457 if (AudioBitrateRadioButton
.Checked
)
459 ffmpeg
+= "\"" + workPath
+ "\\fdkaac.exe\" --ignorelength -b " + AudioBitrateComboBox
.Text
+ " - -o \"" + output
+ "\"";
461 if (AudioCustomizeRadioButton
.Checked
)
463 ffmpeg
+= "\"" + workPath
+ "\\fdkaac.exe\" --ignorelength " + AudioCustomParameterTextBox
.Text
.ToString() + " - -o \"" + output
+ "\"";
468 ffmpeg
= "\"" + workPath
+ "\\ffmpeg.exe\" -i \"" + input
+ "\" -c:a ac3 -b:a " + AudioBitrateComboBox
.Text
.ToString() + "k \"" + output
+ "\"";
474 aac
= ffmpeg
+ "\r\n";
478 private string getAudioExt()
481 switch (AudioEncoderComboBox
.SelectedIndex
)
483 case 0: ext
= ".mp4"; break;
484 case 1: ext
= ".m4a"; break;
485 case 2: ext
= ".wav"; break;
486 case 3: ext
= ".m4a"; break;
487 case 4: ext
= ".flac"; break;
488 case 5: ext
= ".m4a"; break;
489 case 6: ext
= ".ac3"; break;
490 default: ext
= ".aac"; break;
495 private void btnaudio_Click(object sender
, EventArgs e
)
497 openFileDialog1
.Filter
= "音频(*.mp4;*.aac;*.mp2;*.mp3;*.m4a;*.ac3)|*.mp4;*.aac;*.mp2;*.mp3;*.m4a;*.ac3|所有文件(*.*)|*.*";
498 DialogResult result
= openFileDialog1
.ShowDialog();
499 if (result
== DialogResult
.OK
)
501 nameaudio
= openFileDialog1
.FileName
;
502 txtaudio
.Text
= nameaudio
;
506 private void btnvideo_Click(object sender
, EventArgs e
)
508 openFileDialog1
.Filter
= "视频(*.avi;*.mp4;*.m1v;*.m2v;*.m4v;*.264;*.h264;*.hevc)|*.avi;*.mp4;*.m1v;*.m2v;*.m4v;*.264;*.h264;*.hevc|所有文件(*.*)|*.*";
509 DialogResult result
= openFileDialog1
.ShowDialog();
510 if (result
== DialogResult
.OK
)
512 namevideo
= openFileDialog1
.FileName
;
513 txtvideo
.Text
= namevideo
;
517 private void openFileDialog1_FileOk(object sender
, CancelEventArgs e
)
521 private void btnout_Click(object sender
, EventArgs e
)
523 SaveFileDialog savefile
= new SaveFileDialog();
524 savefile
.Filter
= "视频(*.mp4)|*.mp4";
525 DialogResult result
= savefile
.ShowDialog();
526 if (result
== DialogResult
.OK
)
528 nameout
= savefile
.FileName
;
529 txtout
.Text
= nameout
;
533 private void btnmux_Click(object sender
, EventArgs e
)
537 ShowErrorMessage("请选择视频文件");
540 string inputExt
= Path
.GetExtension(txtvideo
.Text
.Trim()).ToLower();
541 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.
542 && inputExt
!= ".mp4" //MPEG-4 Video
543 && inputExt
!= ".m1v" //MPEG-1 Video
544 && inputExt
!= ".m2v" //MPEG-2 Video
545 && inputExt
!= ".m4v" //MPEG-4 Video
546 && inputExt
!= ".264" //AVC/H264 Video
547 && inputExt
!= ".h264" //AVC/H264 Video
548 && inputExt
!= ".hevc") //HEVC/H265 Video
550 ShowErrorMessage("输入文件: \r\n\r\n" + txtvideo
.Text
.Trim() + "\r\n\r\n是一个mp4box不支持的视频文件!");
556 ShowErrorMessage("请选择输出文件");
559 StringBuilder sb
= new StringBuilder();
560 sb
.Append(Util
.FormatPath(workPath
+ "\\mp4box.exe") + " -add \"" + namevideo
+ "#trackID=1");
561 if (Mp4BoxParComboBox
.Text
!= "")
562 sb
.Append(":par=" + Mp4BoxParComboBox
.Text
);
563 if (cbFPS
.Text
!= "auto" && cbFPS
.Text
!= "")
564 sb
.Append(":fps=" + cbFPS
.Text
);
565 sb
.Append(":name=\""); //输入raw时删除默认添加的gpac字符串
567 sb
.Append(" -add \"" + nameaudio
+ ":name=\"");
568 sb
.Append(" -new \"" + nameout
+ "\" \r\n cmd");
570 batpath
= workPath
+ "\\mux.bat";
571 File
.WriteAllText(batpath
, mux
, Encoding
.Default
);
573 Process
.Start(batpath
);
576 private void btnaextract_Click(object sender
, EventArgs e
)
579 ExtractAV(namevideo
, "a", 0);
580 //if (namevideo == "")
582 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
586 // //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 2 \"" + namevideo + "\"";
588 // aextract += Cmd.FormatPath(workPath + "\\ffmpeg.exe");
589 // aextract += " -i " + Cmd.FormatPath(namevideo);
590 // aextract += " -vn -sn -c:a:0 copy ";
591 // string outfile = Cmd.GetDir(namevideo) +
592 // Path.GetFileNameWithoutExtension(namevideo) + "_抽取音频1" + Path.GetExtension(namevideo);
593 // aextract += Cmd.FormatPath(outfile);
594 // batpath = workPath + "\\aextract.bat";
595 // File.WriteAllText(batpath, aextract, Encoding.Default);
596 // LogRecord(aextract);
597 // Process.Start(batpath);
601 private void ExtractAV(string namevideo
, string av
, int streamIndex
)
603 if (string.IsNullOrEmpty(namevideo
))
605 ShowErrorMessage("请选择视频文件");
609 string ext
= Path
.GetExtension(namevideo
);
610 //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 2 \"" + namevideo + "\"";
611 string aextract
= "";
612 aextract
+= Util
.FormatPath(workPath
+ "\\ffmpeg.exe");
613 aextract
+= " -i " + Util
.FormatPath(namevideo
);
616 aextract
+= " -vn -sn -c:a copy -y -map 0:a:" + streamIndex
+ " ";
618 MediaInfo MI
= new MediaInfo();
620 string audioFormat
= MI
.Get(StreamKind
.Audio
, streamIndex
, "Format");
621 string audioProfile
= MI
.Get(StreamKind
.Audio
, streamIndex
, "Format_Profile");
622 if (!string.IsNullOrEmpty(audioFormat
))
624 if (audioFormat
.Contains("MPEG") && audioProfile
== "Layer 3")
626 else if (audioFormat
.Contains("MPEG") && audioProfile
== "Layer 2")
628 else if (audioFormat
.Contains("PCM")) //flv support(PCM_U8 * PCM_S16BE * PCM_MULAW * PCM_ALAW * ADPCM_SWF)
630 else if (audioFormat
== "AAC")
632 else if (audioFormat
== "AC-3")
634 else if (audioFormat
== "ALAC")
641 ShowInfoMessage("该轨道无音频");
647 aextract
+= " -an -sn -c:v copy -y -map 0:v:" + streamIndex
+ " ";
651 throw new Exception("未知流!");
653 string suf
= "_audio_";
658 suf
+= "index" + streamIndex
;
659 string outfile
= Util
.GetDir(namevideo
) +
660 Path
.GetFileNameWithoutExtension(namevideo
) + suf
+ ext
;
661 aextract
+= Util
.FormatPath(outfile
);
662 batpath
= workPath
+ "\\" + av
+ "extract.bat";
663 File
.WriteAllText(batpath
, aextract
, Encoding
.Default
);
665 Process
.Start(batpath
);
668 private string ExtractAudio(string namevideo
, string outfile
, int streamIndex
= 0)
670 if (string.IsNullOrEmpty(namevideo
))
674 string ext
= Path
.GetExtension(namevideo
);
675 //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 2 \"" + namevideo + "\"";
676 string aextract
= "";
677 aextract
+= Util
.FormatPath(workPath
+ "\\ffmpeg.exe");
678 aextract
+= " -i " + Util
.FormatPath(namevideo
);
679 aextract
+= " -vn -sn -c:a copy -y -map 0:a:" + streamIndex
+ " ";
680 MediaInfo MI
= new MediaInfo();
682 string audioFormat
= MI
.Get(StreamKind
.Audio
, streamIndex
, "Format");
683 string audioProfile
= MI
.Get(StreamKind
.Audio
, streamIndex
, "Format_Profile");
684 if (!string.IsNullOrEmpty(audioFormat
))
686 if (audioFormat
.Contains("MPEG") && audioProfile
== "Layer 3")
688 else if (audioFormat
.Contains("MPEG") && audioProfile
== "Layer 2")
690 else if (audioFormat
.Contains("PCM")) //flv support(PCM_U8 * PCM_S16BE * PCM_MULAW * PCM_ALAW * ADPCM_SWF)
692 else if (audioFormat
== "AAC")
694 else if (audioFormat
== "AC-3")
696 else if (audioFormat
== "ALAC")
705 aextract
+= Util
.FormatPath(outfile
) + "\r\n";
709 private void ExtractTrack(string namevideo
, int streamIndex
)
711 if (string.IsNullOrEmpty(namevideo
))
713 ShowErrorMessage("请选择视频文件");
717 string aextract
= "";
718 aextract
+= Util
.FormatPath(workPath
+ "\\ffmpeg.exe");
719 aextract
+= " -i " + Util
.FormatPath(namevideo
);
720 aextract
+= " -map 0:" + streamIndex
+ " -c copy ";
721 string suf
= "_抽取流Index" + streamIndex
;
722 string outfile
= Util
.GetDir(namevideo
) +
723 Path
.GetFileNameWithoutExtension(namevideo
) + suf
+ '.' +
724 FormatExtractor
.Extract(workPath
, namevideo
)[streamIndex
].Format
;
725 aextract
+= Util
.FormatPath(outfile
);
726 batpath
= workPath
+ "\\mkvextract.bat";
727 File
.WriteAllText(batpath
, aextract
, Encoding
.Default
);
729 Process
.Start(batpath
);
732 private void button1_Click(object sender
, EventArgs e
)
734 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- ( ゜- ゜)つロ 乾杯~"), "关于");
737 private void btnvextract_Click(object sender
, EventArgs e
)
740 ExtractAV(namevideo
, "v", 0);
741 //if (namevideo == "")
743 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
747 // //vextract = "\"" + workPath + "\\mp4box.exe\" -raw 1 \"" + namevideo + "\"";
749 // vextract += Cmd.FormatPath(workPath + "\\ffmpeg.exe");
750 // vextract += " -i " + Cmd.FormatPath(namevideo);
751 // vextract += " -an -sn -c:v:0 copy ";
752 // string outfile = Cmd.GetDir(namevideo) +
753 // Path.GetFileNameWithoutExtension(namevideo) + "_抽取视频1" + Path.GetExtension(namevideo);
754 // vextract += Cmd.FormatPath(outfile);
755 // batpath = workPath + "\\vextract.bat";
756 // File.WriteAllText(batpath, vextract, Encoding.Default);
757 // LogRecord(vextract);
758 // Process.Start(batpath);
762 private void txtvideo_TextChanged(object sender
, EventArgs e
)
766 if (txtvideo
.Text
.Trim().Length
> 0)
768 if (!File
.Exists(txtvideo
.Text
.Trim()))
770 throw new Exception("输入文件: \r\n\r\n" + txtvideo
.Text
.Trim() + "\r\n\r\n不存在!");
772 string inputExt
= Path
.GetExtension(txtvideo
.Text
.Trim()).ToLower();
773 //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.
774 // && inputExt != ".mp4" //MPEG-4 Video
775 // && inputExt != ".m1v" //MPEG-1 Video
776 // && inputExt != ".m2v" //MPEG-2 Video
777 // && inputExt != ".m4v" //MPEG-4 Video
778 // && inputExt != ".264" //AVC/H264 Video
779 // && inputExt != ".h264" //AVC/H264 Video
780 // && inputExt != ".hevc") //HEVC/H265 Video
782 // throw new Exception("输入文件: \r\n\r\n" + txtvideo.Text.Trim() + "\r\n\r\n是一个mp4box不支持的视频文件!");
784 if (inputExt
== ".264" || inputExt
== ".h264" || inputExt
== ".hevc")
786 ShowWarningMessage("H.264或者HEVC流文件mp4box将会自动侦测帧率\r\n如果侦测不到将默认为25fps\r\n如果你知道该文件的帧率建议手动设置");
788 namevideo
= txtvideo
.Text
;
789 txtout
.Text
= Util
.ChangeExt(txtvideo
.Text
, "_Mux.mp4");
794 txtvideo
.Text
= string.Empty
;
795 ShowErrorMessage(ex
.Message
);
799 private void txtaudio_TextChanged(object sender
, EventArgs e
)
803 if (txtaudio
.Text
.Trim().Length
> 0)
805 if (!File
.Exists(txtaudio
.Text
.Trim()))
807 throw new Exception("输入文件: \r\n\r\n" + txtaudio
.Text
.Trim() + "\r\n\r\n不存在!");
809 string inputExt
= Path
.GetExtension(txtaudio
.Text
.Trim()).ToLower();
810 if (inputExt
!= ".mp4"
811 && inputExt
!= ".aac" //ADIF or RAW formats not supported
812 && inputExt
!= ".mp3"
813 && inputExt
!= ".m4a"
814 && inputExt
!= ".mp2"
815 && inputExt
!= ".ac3")
817 throw new Exception("输入文件: \r\n\r\n" + txtaudio
.Text
.Trim() + "\r\n\r\n是一个mp4box不支持的音频文件!");
819 nameaudio
= txtaudio
.Text
;
824 txtaudio
.Text
= string.Empty
;
825 ShowErrorMessage(ex
.Message
);
829 private void txtout_TextChanged(object sender
, EventArgs e
)
831 nameout
= txtout
.Text
;
834 private void Form1_FormClosed(object sender
, FormClosedEventArgs e
)
836 #region Delete Temp Files
838 if (SetupDeleteTempFileCheckBox
.Checked
&& !workPath
.Equals("!undefined"))
840 List
<string> deleteFileList
= new List
<string>();
842 string systemDisk
= Environment
.GetFolderPath(Environment
.SpecialFolder
.System
).Substring(0, 3);
843 string systemTempPath
= systemDisk
+ @"windows\temp";
845 //Delete all BAT files
846 DirectoryInfo theFolder
= new DirectoryInfo(workPath
);
847 foreach (FileInfo NextFile
in theFolder
.GetFiles())
849 if (NextFile
.Extension
.Equals(".bat"))
850 deleteFileList
.Add(NextFile
.FullName
);
853 if (Directory
.Exists(tempfilepath
))
855 foreach (var item
in Directory
.GetFiles(tempfilepath
))
857 deleteFileList
.Add(item
);
861 string[] deletedfiles
= { "concat.txt", tempPic, tempavspath, workPath + "msg.vbs" }
;
862 deleteFileList
.AddRange(deletedfiles
);
864 foreach (string file
in deleteFileList
)
870 #endregion Delete Temp Files
872 #region Save Settings
876 #endregion Save Settings
879 private void txtvideo4_TextChanged(object sender
, EventArgs e
)
881 if (File
.Exists(txtvideo4
.Text
.ToString()))
883 namevideo4
= txtvideo4
.Text
;
884 //string finish = namevideo4.Insert(namevideo4.LastIndexOf(".")-1,"");
885 //string ext = namevideo4.Substring(namevideo4.LastIndexOf(".") + 1, 3);
886 //finish += "_clip." + ext;
887 string finish
= namevideo4
.Insert(namevideo4
.LastIndexOf("."), "_output");
888 txtout5
.Text
= finish
;
892 private void txtout5_TextChanged(object sender
, EventArgs e
)
894 nameout5
= txtout5
.Text
;
897 private void btnvideo4_Click(object sender
, EventArgs e
)
899 openFileDialog1
.Filter
= "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
900 DialogResult result
= openFileDialog1
.ShowDialog();
901 if (result
== DialogResult
.OK
)
903 namevideo4
= openFileDialog1
.FileName
;
904 txtvideo4
.Text
= namevideo4
;
908 private void btnout5_Click(object sender
, EventArgs e
)
910 SaveFileDialog savefile
= new SaveFileDialog();
911 savefile
.Filter
= "视频(*.*)|*.*";
912 DialogResult result
= savefile
.ShowDialog();
913 if (result
== DialogResult
.OK
)
915 nameout5
= savefile
.FileName
;
916 txtout5
.Text
= nameout5
;
920 public static bool IsWindowsVistaOrNewer
922 get { return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 6); }
930 private void InitParameter()
934 x264CRFNum
.Value
= 23.5m
;
935 x264BitrateNum
.Value
= 800;
936 x264AudioParameterTextBox
.Text
= "--abitrate 128";
937 x264AudioModeComboBox
.SelectedIndex
= 0;
938 x264DemuxerComboBox
.SelectedIndex
= 0;
939 x264WidthNum
.Value
= 0;
940 x264HeightNum
.Value
= 0;
941 x264CustomParameterTextBox
.Text
= "";
942 x264PriorityComboBox
.SelectedIndex
= 2;
943 x264FramesNumericUpDown
.Value
= 0;
944 x264SeekNumericUpDown
.Value
= 0;
945 x264Mode1RadioButton
.Checked
= true;
946 x264ShutdownCheckBox
.Checked
= false;
952 AudioEncoderComboBox
.SelectedIndex
= 0;
953 AudioPresetComboBox
.SelectedIndex
= 0;
954 AudioBitrateComboBox
.Text
= "128";
955 AudioBitrateRadioButton
.Checked
= true;
961 OnePicAudioBitrateNum
.Value
= 128;
962 OnePicFPSNum
.Value
= 1;
963 OnePicCRFNum
.Value
= 24;
965 BlackFPSNum
.Value
= 1;
966 BlackCRFNum
.Value
= 51;
967 BlackBitrateNum
.Value
= 900;
969 maskb
.Text
= "000000";
970 maske
.Text
= "000020";
972 TransposeComboBox
.SelectedIndex
= 1;
974 #endregion General Tab
978 cbFPS
.SelectedIndex
= 0;
979 Mp4BoxParComboBox
.SelectedIndex
= 0;
980 MuxAacEncoderComboBox
.SelectedIndex
= 0;
981 MuxFormatComboBox
.Text
= "flv";
987 AVSwithAudioCheckBox
.Checked
= false;
993 SplashScreenCheckBox
.Checked
= true;
994 TrayModeCheckBox
.Checked
= false;
995 x264PriorityComboBox
.SelectedIndex
= 2;
996 x264ThreadsComboBox
.SelectedIndex
= 0;
997 SetupDeleteTempFileCheckBox
.Checked
= true;
998 CheckUpdateCheckBox
.Checked
= true;
999 x265CheckBox
.Checked
= false;
1001 #endregion Setup Tab
1004 private void LoadSettings()
1009 x264CRFNum
.Value
= Convert
.ToDecimal(ConfigurationManager
.AppSettings
["x264CRF"]);
1010 x264BitrateNum
.Value
= Convert
.ToDecimal(ConfigurationManager
.AppSettings
["x264Bitrate"]);
1011 x264AudioParameterTextBox
.Text
= ConfigurationManager
.AppSettings
["x264AudioParameter"];
1012 x264AudioModeComboBox
.SelectedIndex
= Convert
.ToInt32(ConfigurationManager
.AppSettings
["x264AudioMode"]);
1013 if (int.Parse(ConfigurationManager
.AppSettings
["x264Exe"]) > x264ExeComboBox
.Items
.Count
- 1)
1014 x264ExeComboBox
.SelectedIndex
= 0;
1016 x264ExeComboBox
.SelectedIndex
= Convert
.ToInt32(ConfigurationManager
.AppSettings
["x264Exe"]);
1017 x264DemuxerComboBox
.SelectedIndex
= Convert
.ToInt32(ConfigurationManager
.AppSettings
["x264Demuxer"]);
1018 x264WidthNum
.Value
= Convert
.ToDecimal(ConfigurationManager
.AppSettings
["x264Width"]);
1019 x264HeightNum
.Value
= Convert
.ToDecimal(ConfigurationManager
.AppSettings
["x264Height"]);
1020 x264CustomParameterTextBox
.Text
= ConfigurationManager
.AppSettings
["x264CustomParameter"];
1021 x264PriorityComboBox
.SelectedIndex
= Convert
.ToInt32(ConfigurationManager
.AppSettings
["x264Priority"]);
1022 x264extraLine
.Text
= ConfigurationManager
.AppSettings
["x264ExtraParameter"];
1023 AVSScriptTextBox
.Text
= ConfigurationManager
.AppSettings
["AVSScript"];
1024 AudioEncoderComboBox
.SelectedIndex
= Convert
.ToInt32(ConfigurationManager
.AppSettings
["AudioEncoder"]);
1025 AudioBitrateComboBox
.Text
= ConfigurationManager
.AppSettings
["AudioBitrate"];
1026 OnePicAudioBitrateNum
.Value
= Convert
.ToDecimal(ConfigurationManager
.AppSettings
["OnePicAudioBitrate"]);
1027 OnePicFPSNum
.Value
= Convert
.ToDecimal(ConfigurationManager
.AppSettings
["OnePicFPS"]);
1028 OnePicCRFNum
.Value
= Convert
.ToDecimal(ConfigurationManager
.AppSettings
["OnePicCRF"]);
1029 BlackFPSNum
.Value
= Convert
.ToDecimal(ConfigurationManager
.AppSettings
["BlackFPS"]);
1030 BlackCRFNum
.Value
= Convert
.ToDecimal(ConfigurationManager
.AppSettings
["BlackCRF"]);
1031 BlackBitrateNum
.Value
= Convert
.ToDecimal(ConfigurationManager
.AppSettings
["BlackBitrate"]);
1032 SetupDeleteTempFileCheckBox
.Checked
= Convert
.ToBoolean(ConfigurationManager
.AppSettings
["SetupDeleteTempFile"]);
1033 CheckUpdateCheckBox
.Checked
= Convert
.ToBoolean(ConfigurationManager
.AppSettings
["CheckUpdate"]);
1034 x264ThreadsComboBox
.SelectedIndex
= Convert
.ToInt32(ConfigurationManager
.AppSettings
["x264Threads"]);
1035 x265CheckBox
.Checked
= Convert
.ToBoolean(ConfigurationManager
.AppSettings
["x265Enable"]);
1036 TrayModeCheckBox
.Checked
= Convert
.ToBoolean(ConfigurationManager
.AppSettings
["TrayMode"]);
1037 SplashScreenCheckBox
.Checked
= Convert
.ToBoolean(ConfigurationManager
.AppSettings
["SplashScreen"]);
1038 SetupPlayerTextBox
.Text
= ConfigurationManager
.AppSettings
["PreviewPlayer"];
1039 string SubLangExt
= Convert
.ToString(ConfigurationManager
.AppSettings
["SubLanguageExtension"]);
1040 MuxFormatComboBox
.SelectedIndex
= Convert
.ToInt32(ConfigurationManager
.AppSettings
["MuxFormat"]);
1041 x264BatchSubSpecialLanguage
.DataSource
= SubLangExt
.Split(',');
1042 if (x264ExeComboBox
.SelectedIndex
== -1)
1044 x264ExeComboBox
.SelectedIndex
= x264ExeComboBox
.Items
.IndexOf("x264_32-8bit");
1047 if (int.Parse(ConfigurationManager
.AppSettings
["LanguageIndex"]) == -1) //First Startup
1049 string culture
= Thread
.CurrentThread
.CurrentCulture
.Name
;
1053 languageComboBox
.SelectedIndex
= 0;
1057 languageComboBox
.SelectedIndex
= 0;
1061 languageComboBox
.SelectedIndex
= 1;
1065 languageComboBox
.SelectedIndex
= 1;
1069 languageComboBox
.SelectedIndex
= 1;
1073 languageComboBox
.SelectedIndex
= 2;
1077 languageComboBox
.SelectedIndex
= 3;
1085 languageComboBox
.SelectedIndex
= int.Parse(ConfigurationManager
.AppSettings
["LanguageIndex"]);
1087 if (CheckUpdateCheckBox
.Checked
&& Util
.IsConnectInternet())
1091 CheckUpadateDelegate checkUpdateDelegate
= CheckUpdate
;
1092 checkUpdateDelegate
.BeginInvoke(out d
, out f
, new AsyncCallback(CheckUpdateCallBack
), null);
1094 x264ExeComboBox_SelectedIndexChanged(null, null);
1102 private void SaveSettings()
1104 Configuration cfa
= ConfigurationManager
.OpenExeConfiguration(ConfigurationUserLevel
.None
);
1105 cfa
.AppSettings
.Settings
["x264CRF"].Value
= x264CRFNum
.Value
.ToString();
1106 cfa
.AppSettings
.Settings
["x264Bitrate"].Value
= x264BitrateNum
.Value
.ToString();
1107 cfa
.AppSettings
.Settings
["x264AudioParameter"].Value
= x264AudioParameterTextBox
.Text
;
1108 cfa
.AppSettings
.Settings
["x264AudioMode"].Value
= x264AudioModeComboBox
.SelectedIndex
.ToString();
1109 cfa
.AppSettings
.Settings
["x264Exe"].Value
= x264ExeComboBox
.SelectedIndex
.ToString();
1110 cfa
.AppSettings
.Settings
["x264Demuxer"].Value
= x264DemuxerComboBox
.SelectedIndex
.ToString();
1111 cfa
.AppSettings
.Settings
["x264Width"].Value
= x264WidthNum
.Value
.ToString();
1112 cfa
.AppSettings
.Settings
["x264Height"].Value
= x264HeightNum
.Value
.ToString();
1113 cfa
.AppSettings
.Settings
["x264CustomParameter"].Value
= x264CustomParameterTextBox
.Text
;
1114 cfa
.AppSettings
.Settings
["x264Priority"].Value
= x264PriorityComboBox
.SelectedIndex
.ToString();
1115 cfa
.AppSettings
.Settings
["x264ExtraParameter"].Value
= x264extraLine
.Text
;
1116 cfa
.AppSettings
.Settings
["AVSScript"].Value
= AVSScriptTextBox
.Text
;
1117 cfa
.AppSettings
.Settings
["AudioEncoder"].Value
= AudioEncoderComboBox
.SelectedIndex
.ToString();
1118 cfa
.AppSettings
.Settings
["AudioParameter"].Value
= AudioBitrateComboBox
.Text
;
1119 cfa
.AppSettings
.Settings
["OnePicAudioBitrate"].Value
= OnePicAudioBitrateNum
.Value
.ToString();
1120 cfa
.AppSettings
.Settings
["OnePicFPS"].Value
= OnePicFPSNum
.Value
.ToString();
1121 cfa
.AppSettings
.Settings
["OnePicCRF"].Value
= OnePicCRFNum
.Value
.ToString();
1122 cfa
.AppSettings
.Settings
["BlackFPS"].Value
= BlackFPSNum
.Value
.ToString();
1123 cfa
.AppSettings
.Settings
["BlackCRF"].Value
= BlackCRFNum
.Value
.ToString();
1124 cfa
.AppSettings
.Settings
["BlackBitrate"].Value
= BlackBitrateNum
.Value
.ToString();
1125 cfa
.AppSettings
.Settings
["SetupDeleteTempFile"].Value
= SetupDeleteTempFileCheckBox
.Checked
.ToString();
1126 cfa
.AppSettings
.Settings
["CheckUpdate"].Value
= CheckUpdateCheckBox
.Checked
.ToString();
1127 cfa
.AppSettings
.Settings
["TrayMode"].Value
= TrayModeCheckBox
.Checked
.ToString();
1128 cfa
.AppSettings
.Settings
["LanguageIndex"].Value
= languageComboBox
.SelectedIndex
.ToString();
1129 cfa
.AppSettings
.Settings
["SplashScreen"].Value
= SplashScreenCheckBox
.Checked
.ToString();
1130 cfa
.AppSettings
.Settings
["x264Threads"].Value
= x264ThreadsComboBox
.SelectedIndex
.ToString();
1131 cfa
.AppSettings
.Settings
["x265Enable"].Value
= x265CheckBox
.Checked
.ToString();
1132 cfa
.AppSettings
.Settings
["PreviewPlayer"].Value
= SetupPlayerTextBox
.Text
;
1133 cfa
.AppSettings
.Settings
["MuxFormat"].Value
= MuxFormatComboBox
.SelectedIndex
.ToString(); ;
1135 ConfigurationManager
.RefreshSection("appSettings"); // 刷新命名节,在下次检索它时将从磁盘重新读取它。记住应用程序要刷新节点
1140 private void PresetXml()
1142 if (!File
.Exists("preset.xml"))
1144 xdoc
= new XDocument(
1145 new XDeclaration("1.0", "utf-8", "yes"),
1146 new XElement("root",
1147 new XElement("Video",
1148 new XElement("VideoEncoder",
1149 new XElement("x264",
1150 new XElement("Parameter", "--crf 24 --preset 8 -r 6 -b 6 -i 1 --scenecut 60 -f 1:1 --qcomp 0.5 --psy-rd 0.3:0 --aq-mode 2 --aq-strength 0.8 --vf resize:960,540,,,,lanczos", new XAttribute("Name", "default")),
1151 new XElement("Parameter", "-p1 --crf 20 --aq-mode 2 --sar 32:27 --vf yadif:, --stat \"TEMP.stat\" --slow-firstpass --ref 8 --preset 8 --subme 10", new XAttribute("Name", "DVDRIP不切边,16:9")),
1152 new XElement("Parameter", "-p1 --crf 20 --aq-mode 2 --sar 40:33 --vf yadif:, --stat \"TEMP.stat\" --slow-firstpass --ref 8 --preset 8 --subme 10", new XAttribute("Name", "DVDRIP不切边,sar40:33")),
1153 new XElement("Parameter", "-p1 --crf 20 --aq-mode 2 --sar 40:33 --vf yadif:,/crop:8,0,8,0 --stat \"TEMP.stat\" --slow-firstpass --ref 8 --preset 8 --subme 10", new XAttribute("Name", "DVDRIP切边,sar40:33")),
1154 new XElement("Parameter", "--profile high --level 3.1 --level-force --device iphone", new XAttribute("Name", "iOS")),
1155 new XElement("Parameter", "--crf 25 --preset placebo --subme 10 --ref 7 --bframes 7 --qcomp 0.75 --psy-rd 0:0 --keyint infinite --min-keyint 1", new XAttribute("Name", "MAD")),
1156 new XElement("Parameter", "--profile main --level 3.0 --ref 3 --b-pyramid none --weightp 1 --vbv-maxrate 10000 --vbv-bufsize 10000 --vf resize:480,272,,,,lanczos --device psp", new XAttribute("Name", "PSP"))
1158 new XElement("x265",
1159 new XElement("Parameter", "", new XAttribute("Name", "x265default"))
1163 new XElement("Audio",
1164 new XElement("AudioEncoder",
1165 new XElement("NeroAAC",
1166 new XElement("Parameter", "-he -br 32000", new XAttribute("Name", "NeroAAC_HE-32Kbps")),
1167 new XElement("Parameter", "-he -br 48000", new XAttribute("Name", "NeroAAC_HE-48Kbps")),
1168 new XElement("Parameter", "-he -br 64000", new XAttribute("Name", "NeroAAC_HE-64Kbps")),
1169 new XElement("Parameter", "-lc -br 128000", new XAttribute("Name", "NeroAAC_LC-128Kbps")),
1170 new XElement("Parameter", "-lc -br 192000", new XAttribute("Name", "NeroAAC_LC-192Kbps")),
1171 new XElement("Parameter", "-lc -br 256000", new XAttribute("Name", "NeroAAC_LC-256Kbps")),
1172 new XElement("Parameter", "-q 1 -lc", new XAttribute("Name", "NeroAAC_LC-Q1"))
1174 new XElement("FDKAAC",
1175 new XElement("Parameter", "-m 1", new XAttribute("Name", "FDKAAC_VBR1")),
1176 new XElement("Parameter", "-m 2", new XAttribute("Name", "FDKAAC_VBR2")),
1177 new XElement("Parameter", "-m 3", new XAttribute("Name", "FDKAAC_VBR3")),
1178 new XElement("Parameter", "-m 4", new XAttribute("Name", "FDKAAC_VBR4")),
1179 new XElement("Parameter", "-m 5", new XAttribute("Name", "FDKAAC_VBR5")),
1180 new XElement("Parameter", "-p 5 -b 64", new XAttribute("Name", "FDKAAC_HE-_CBR64Kbps")),
1181 new XElement("Parameter", "-b 128", new XAttribute("Name", "FDKAAC_LC-_CBR128Kbps")),
1182 new XElement("Parameter", "-b 192", new XAttribute("Name", "FDKAAC_LC-_CBR192Kbps")),
1183 new XElement("Parameter", "-b 256", new XAttribute("Name", "FDKAAC_LC-_CBR256Kbps"))
1185 new XElement("QAAC",
1186 new XElement("Parameter", "--he -c 64 -q 2 --no-optimize", new XAttribute("Name", "QAAC_HE-CBR64Kbps")),
1187 new XElement("Parameter", "--he -v 64 -q 2 --no-optimize", new XAttribute("Name", "QAAC_HE-CVBR64Kbps")),
1188 new XElement("Parameter", "-c 128 -q 2 --no-optimize", new XAttribute("Name", "QAAC_LC-CBR128Kbps")),
1189 new XElement("Parameter", "-v 128 -q 2 --no-optimize", new XAttribute("Name", "QAAC_LC-CVBR128Kbps")),
1190 new XElement("Parameter", "-c 256 -q 2 --no-optimize", new XAttribute("Name", "QAAC_LC-CBR256Kbps")),
1191 new XElement("Parameter", "-v 256 -q 2 --no-optimize", new XAttribute("Name", "QAAC_LC-CVBR256Kbps")),
1192 new XElement("Parameter", "-V 90 -q 2 --no-optimize", new XAttribute("Name", "QAAC_TVBR_V90")),
1193 new XElement("Parameter", "-V 127 -q 2 --no-optimize", new XAttribute("Name", "QAAC_TVBR_V127"))
1199 xdoc
.Save("preset.xml");
1202 xdoc
= XDocument
.Load("preset.xml");
1205 private void LoadVideoPreset()
1207 VideoPresetComboBox
.Items
.Clear();
1208 var xlsv
= xdoc
.Element("root").Element("Video").Element("VideoEncoder").Element("x264").Elements();
1209 foreach (var item
in xlsv
)
1211 VideoPresetComboBox
.Items
.Add(item
.Attribute("Name").Value
);
1213 if (VideoPresetComboBox
.Items
.Count
> 0 && VideoPresetComboBox
.SelectedIndex
== -1)
1214 VideoPresetComboBox
.SelectedIndex
= 0;
1217 private void LoadAudioPreset()
1219 AudioPresetComboBox
.Items
.Clear();
1220 var xlsa
= xdoc
.Element("root").Element("Audio").Element("AudioEncoder").Element(AudioEncoderComboBox
.Text
).Elements();
1221 foreach (var item
in xlsa
)
1223 AudioPresetComboBox
.Items
.Add(item
.Attribute("Name").Value
);
1225 if (AudioPresetComboBox
.Items
.Count
> 0 && AudioPresetComboBox
.SelectedIndex
== -1)
1226 AudioPresetComboBox
.SelectedIndex
= 0;
1229 private void Form1_Load(object sender
, EventArgs e
)
1231 SYSTEM_INFO pSI
= new SYSTEM_INFO();
1232 GetSystemInfo(ref pSI
);
1233 int processorNumber
= (int)pSI
.dwNumberOfProcessors
;
1235 x264ThreadsComboBox
.Items
.Add("auto");
1236 for (int i
= 1; i
<= 16; i
++)
1238 x264ThreadsComboBox
.Items
.Add(i
.ToString());
1240 //Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-TW");
1241 //use YAHEI in VistaOrNewer
1242 //if (IsWindowsVistaOrNewer)
1244 // FontFamily myFontFamily = new FontFamily("微软雅黑"); //采用哪种字体
1245 // Font myFont = new Font(myFontFamily, 9, FontStyle.Regular); //字是那种字体,显示的风格
1246 // this.Font = myFont;
1250 startpath
= System
.Windows
.Forms
.Application
.StartupPath
;
1251 workPath
= startpath
+ "\\tools";
1252 if (!Directory
.Exists(workPath
))
1254 MessageBox
.Show("tools文件夹没有解压喔~ 工具箱里没有工具的话运行不起来的喔~", "(这只丸子)",
1255 MessageBoxButtons
.OK
, MessageBoxIcon
.Error
);
1256 Environment
.Exit(1);
1258 //Directory.CreateDirectory(workPath);
1259 //string diskSymbol = startpath.Substring(0, 1);
1261 //string systemDisk = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 3);
1262 //string systemTempPath = systemDisk + @"windows\temp";
1263 string systemTempPath
= Environment
.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget
.Machine
);
1264 tempavspath
= systemTempPath
+ "\\temp.avs";
1265 tempPic
= systemTempPath
+ "\\marukotemp.jpg";
1266 tempfilepath
= startpath
+ "\\temp";
1269 DirectoryInfo folder
= new DirectoryInfo(workPath
);
1270 List
<string> x264exe
= new List
<string>();
1273 bool usex265
= bool.Parse(ConfigurationManager
.AppSettings
["x265Enable"].ToString());
1274 foreach (FileInfo FileName
in folder
.GetFiles())
1276 if ((FileName
.Name
.ToLower().Contains("x264") || FileName
.Name
.ToLower().Contains(usex265
? "x265" : "xxxx")) && Path
.GetExtension(FileName
.Name
) == ".exe")
1278 x264exe
.Add(FileName
.Name
);
1281 x264exe
= x264exe
.OrderByDescending(i
=> i
.Substring(7)).ToList();
1282 x264ExeComboBox
.Items
.AddRange(x264exe
.ToArray());
1286 // avisynth未安装使用本地内置的avs
1287 if (string.IsNullOrEmpty(Util
.CheckAviSynth()))
1289 string sourceAviSynthdll
= Path
.Combine(workPath
, @"avs\AviSynth.dll");
1290 string sourceDevILdll
= Path
.Combine(workPath
, @"avs\DevIL.dll");
1291 if (File
.Exists(sourceAviSynthdll
) && File
.Exists(sourceDevILdll
))
1293 File
.Copy(sourceAviSynthdll
, Path
.Combine(workPath
, "AviSynth.dll"), true);
1294 File
.Copy(sourceDevILdll
, Path
.Combine(workPath
, "DevIL.dll"), true);
1295 LogRecord("未安装avisynth,使用本地内置avs.");
1300 File
.Delete(Path
.Combine(workPath
, "AviSynth.dll"));
1301 File
.Delete(Path
.Combine(workPath
, "DevIL.dll"));
1305 DirectoryInfo avspath
= new DirectoryInfo(workPath
+ @"\avs\plugins");
1306 List
<string> avsfilters
= new List
<string>();
1307 if (Directory
.Exists(workPath
+ @"\avs\plugins"))
1309 foreach (FileInfo FileName
in avspath
.GetFiles())
1311 if (Path
.GetExtension(FileName
.Name
) == ".dll")
1313 avsfilters
.Add(FileName
.Name
);
1316 AVSFilterComboBox
.Items
.AddRange(avsfilters
.ToArray());
1319 //ReleaseDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
1320 ReleaseDatelabel
.Text
= ReleaseDate
.ToString("yyyy-M-d");
1323 if (File
.Exists(startpath
+ "\\help.rtf"))
1325 HelpTextBox
.LoadFile(startpath
+ "\\help.rtf");
1333 private void button2_Click(object sender
, EventArgs e
)
1335 openFileDialog1
.Filter
= "视频(*.mkv)|*.mkv";
1336 DialogResult result
= openFileDialog1
.ShowDialog();
1337 if (result
== DialogResult
.OK
)
1339 namevideo6
= openFileDialog1
.FileName
;
1340 txtvideo6
.Text
= namevideo6
;
1344 private void button3_Click(object sender
, EventArgs e
)
1346 if (namevideo6
== "")
1348 ShowErrorMessage("请选择视频文件");
1352 mkvextract
= workPath
+ "\\ mkvextract.exe tracks \"" + namevideo6
+ "\" 1:video.h264 2:audio.aac";
1353 batpath
= workPath
+ "\\mkvextract.bat";
1354 File
.WriteAllText(batpath
, mkvextract
, Encoding
.Default
);
1355 Process
.Start(batpath
);
1359 private void button4_Click(object sender
, EventArgs e
)
1361 openFileDialog1
.Filter
= "视频(*.mp4)|*.mp4|所有文件(*.*)|*.*";
1362 DialogResult result
= openFileDialog1
.ShowDialog();
1363 if (result
== DialogResult
.OK
)
1365 namevideo5
= openFileDialog1
.FileName
;
1366 txtvideo5
.Text
= namevideo5
;
1370 private void button5_Click(object sender
, EventArgs e
)
1372 openFileDialog1
.Filter
= "音频(*.mp3)|*.mp3|音频(*.aac)|*.aac|所有文件(*.*)|*.*";
1373 DialogResult result
= openFileDialog1
.ShowDialog();
1374 if (result
== DialogResult
.OK
)
1376 nameaudio3
= openFileDialog1
.FileName
;
1377 txtaudio3
.Text
= nameaudio3
;
1381 private void button6_Click(object sender
, EventArgs e
)
1383 SaveFileDialog savefile
= new SaveFileDialog();
1384 savefile
.Filter
= "视频(*.mkv)|*.mkv";
1385 DialogResult result
= savefile
.ShowDialog();
1386 if (result
== DialogResult
.OK
)
1388 nameout6
= savefile
.FileName
;
1389 txtout6
.Text
= nameout6
;
1393 private void button7_Click(object sender
, EventArgs e
)
1395 if (namevideo5
== "")
1397 ShowErrorMessage("请选择视频文件");
1399 else if (nameaudio3
== "")
1401 ShowErrorMessage("请选择音频文件");
1403 else if (nameout6
== "")
1405 ShowErrorMessage("请选择输出文件");
1409 mkvmerge
= workPath
+ "\\mkvmerge.exe -o \"" + nameout6
+ "\" \"" + namevideo5
+ "\" \"" + nameaudio3
+ "\"";
1410 batpath
= workPath
+ "\\mkvmerge.bat";
1411 File
.WriteAllText(batpath
, mkvmerge
, Encoding
.Default
);
1412 Process
.Start(batpath
);
1416 private void button2_Click_1(object sender
, EventArgs e
)
1418 openFileDialog1
.Filter
= "所有文件(*.*)|*.*";
1419 DialogResult result
= openFileDialog1
.ShowDialog();
1420 if (result
== DialogResult
.OK
)
1422 namevideo5
= openFileDialog1
.FileName
;
1423 txtvideo5
.Text
= namevideo5
;
1427 private void button6_Click_1(object sender
, EventArgs e
)
1429 openFileDialog1
.Filter
= "视频(*.mkv)|*.mkv";
1430 DialogResult result
= openFileDialog1
.ShowDialog();
1431 if (result
== DialogResult
.OK
)
1433 namevideo6
= openFileDialog1
.FileName
;
1434 txtvideo6
.Text
= namevideo6
;
1438 private void button7_Click_1(object sender
, EventArgs e
)
1440 if (namevideo5
== "" && nameaudio3
== "")
1442 ShowErrorMessage("请选择文件");
1446 if (txtaudio3
.Text
!= "" && txtsub
.Text
!= "")
1448 mkvmerge
= "\"" + workPath
+ "\\mkvmerge.exe\" -o \"" + nameout6
+ "\" \"" + namevideo5
+ "\" \"" + nameaudio3
+ "\" \"" + namesub
+ "\"";
1450 if (txtaudio3
.Text
== "" && txtsub
.Text
== "")
1452 mkvmerge
= "\"" + workPath
+ "\\mkvmerge.exe\" -o \"" + nameout6
+ "\" \"" + namevideo5
+ "\"";
1454 if (txtaudio3
.Text
!= "" && txtsub
.Text
== "")
1456 mkvmerge
= "\"" + workPath
+ "\\mkvmerge.exe\" -o \"" + nameout6
+ "\" \"" + namevideo5
+ "\" \"" + nameaudio3
+ "\"";
1458 if (txtaudio3
.Text
== "" && txtsub
.Text
!= "")
1460 mkvmerge
= "\"" + workPath
+ "\\mkvmerge.exe\" -o \"" + nameout6
+ "\" \"" + namevideo5
+ "\" \"" + namesub
+ "\"";
1462 mkvmerge
+= "\r\ncmd";
1463 batpath
= workPath
+ "\\mkvmerge.bat";
1464 File
.WriteAllText(batpath
, mkvmerge
, Encoding
.Default
);
1465 LogRecord(mkvmerge
);
1466 Process
.Start(batpath
);
1470 private void button4_Click_1(object sender
, EventArgs e
)
1472 SaveFileDialog savefile
= new SaveFileDialog();
1473 savefile
.Filter
= "视频(*.mkv)|*.mkv";
1474 DialogResult result
= savefile
.ShowDialog();
1475 if (result
== DialogResult
.OK
)
1477 nameout6
= savefile
.FileName
;
1478 txtout6
.Text
= nameout6
;
1482 private void button3_Click_1(object sender
, EventArgs e
)
1484 openFileDialog1
.Filter
= "音频(*.mp3;*.aac;*.ac3)|*.mp3;*.aac;*.ac3|所有文件(*.*)|*.*";
1485 DialogResult result
= openFileDialog1
.ShowDialog();
1486 if (result
== DialogResult
.OK
)
1488 nameaudio3
= openFileDialog1
.FileName
;
1489 txtaudio3
.Text
= nameaudio3
;
1493 private void button5_Click_1(object sender
, EventArgs e
)
1495 openFileDialog1
.Filter
= "字幕(*.ass;*.ssa;*.srt)|*.ass;*.ssa;*.srt|所有文件(*.*)|*.*";
1496 DialogResult result
= openFileDialog1
.ShowDialog();
1497 if (result
== DialogResult
.OK
)
1499 namesub
= openFileDialog1
.FileName
;
1500 txtsub
.Text
= namesub
;
1504 private void button8_Click(object sender
, EventArgs e
)
1506 if (namevideo6
== "")
1508 ShowErrorMessage("请选择视频文件");
1512 int i
= namevideo6
.IndexOf(".mkv");
1513 string mkvname
= namevideo6
.Remove(i
);
1514 mkvextract
= "\"" + workPath
+ "\\mkvextract.exe\" tracks \"" + namevideo6
+ "\" 1:\"" + mkvname
+ "_video.h264\" 2:\"" + mkvname
+ "_audio.aac\"";
1515 batpath
= workPath
+ "\\mkvextract.bat";
1516 File
.WriteAllText(batpath
, mkvextract
, Encoding
.Default
);
1517 Process
.Start(batpath
);
1521 private void txtvideo5_TextChanged(object sender
, EventArgs e
)
1523 if (File
.Exists(txtvideo5
.Text
.ToString()))
1525 namevideo5
= txtvideo5
.Text
;
1526 string finish
= namevideo5
.Remove(namevideo5
.LastIndexOf("."));
1527 finish
+= "_mkv封装.mkv";
1528 txtout6
.Text
= finish
;
1532 private void txtaudio3_TextChanged(object sender
, EventArgs e
)
1534 nameaudio3
= txtaudio3
.Text
;
1537 private void txtsub_TextChanged(object sender
, EventArgs e
)
1539 namesub
= txtsub
.Text
;
1542 private void txtout6_TextChanged_1(object sender
, EventArgs e
)
1544 nameout6
= txtout6
.Text
;
1547 private void txtvideo6_TextChanged(object sender
, EventArgs e
)
1549 namevideo6
= txtvideo6
.Text
;
1552 private void btnAutoAdd_Click(object sender
, EventArgs e
)
1554 openFileDialog1
.Multiselect
= true;
1555 openFileDialog1
.Filter
= "所有文件(*.*)|*.*";
1556 DialogResult result
= openFileDialog1
.ShowDialog();
1557 if (result
== DialogResult
.OK
)
1559 lbAuto
.Items
.AddRange(openFileDialog1
.FileNames
);
1563 private void btnAutoDel_Click(object sender
, EventArgs e
)
1565 if (lbAuto
.Items
.Count
> 0)
1567 if (lbAuto
.SelectedItems
.Count
> 0)
1569 int index
= lbAuto
.SelectedIndex
;
1570 lbAuto
.Items
.RemoveAt(lbAuto
.SelectedIndex
);
1571 if (index
== lbAuto
.Items
.Count
)
1573 lbAuto
.SelectedIndex
= index
- 1;
1575 if (index
>= 0 && index
< lbAuto
.Items
.Count
&& lbAuto
.Items
.Count
> 0)
1577 lbAuto
.SelectedIndex
= index
;
1583 private void btnAutoClear_Click(object sender
, EventArgs e
)
1585 lbAuto
.Items
.Clear();
1588 private void lbAuto_DragDrop(object sender
, DragEventArgs e
)
1590 ListBox listbox
= (ListBox
)sender
;
1591 if (e
.Data
.GetDataPresent(DataFormats
.FileDrop
, false))
1593 String
[] files
= (String
[])e
.Data
.GetData(DataFormats
.FileDrop
);
1594 foreach (String s
in files
)
1596 listbox
.Items
.Add(s
);
1600 indexoftarget
= listbox
.IndexFromPoint(listbox
.PointToClient(new Point(e
.X
, e
.Y
)));
1601 if (indexoftarget
!= ListBox
.NoMatches
)
1603 string temp
= listbox
.Items
[indexoftarget
].ToString();
1604 listbox
.Items
[indexoftarget
] = listbox
.Items
[indexofsource
];
1605 listbox
.Items
[indexofsource
] = temp
;
1606 listbox
.SelectedIndex
= indexoftarget
;
1610 private void lbAuto_DragEnter(object sender
, DragEventArgs e
)
1612 //if (e.Data.GetDataPresent(DataFormats.FileDrop))
1613 // e.Effect = DragDropEffects.All;
1614 //else e.Effect = DragDropEffects.None;
1617 private void lbAuto_DragOver(object sender
, DragEventArgs e
)
1619 //拖动源和放置的目的地一定是一个ListBox
1620 ListBox listbox
= (ListBox
)sender
;
1621 if (e
.Data
.GetDataPresent(typeof(System
.String
)) && ((ListBox
)sender
).Equals(listbox
))
1623 e
.Effect
= DragDropEffects
.Move
;
1625 else if (e
.Data
.GetDataPresent(DataFormats
.FileDrop
))
1627 e
.Effect
= DragDropEffects
.Link
;
1629 else e
.Effect
= DragDropEffects
.None
;
1632 private void lbAuto_MouseDown(object sender
, MouseEventArgs e
)
1634 indexofsource
= ((ListBox
)sender
).IndexFromPoint(e
.X
, e
.Y
);
1635 if (indexofsource
== 65535)
1637 if (indexofsource
!= ListBox
.NoMatches
)
1639 ((ListBox
)sender
).DoDragDrop(((ListBox
)sender
).Items
[indexofsource
].ToString(), DragDropEffects
.All
);
1643 public string VideoBatch(string input
, string output
)
1645 bool hasAudio
= false;
1647 string inputName
= Path
.GetFileNameWithoutExtension(input
);
1648 string tempVideo
= Path
.Combine(tempfilepath
, inputName
+ "_vtemp.mp4");
1649 string tempAudio
= Path
.Combine(tempfilepath
, inputName
+ "_atemp" + getAudioExt());
1652 MediaInfo MI
= new MediaInfo();
1654 string audio
= MI
.Get(StreamKind
.Audio
, 0, "Format");
1655 if (!string.IsNullOrEmpty(audio
)) { hasAudio = true; }
1656 string sub
= (x264BatchSubCheckBox
.Checked
) ? GetSubtitlePath(input
) : string.Empty
;
1658 int audioMode
= x264AudioModeComboBox
.SelectedIndex
;
1664 aextract
= audiobat(input
, tempAudio
);
1667 aextract
= string.Empty
;
1670 if (audio
.ToLower() == "aac")
1672 tempAudio
= Path
.Combine(tempfilepath
, inputName
+ "_atemp.aac");
1673 aextract
= ExtractAudio(input
, tempAudio
);
1676 aextract
= audiobat(input
, tempAudio
);
1682 if (x264ExeComboBox
.SelectedItem
.ToString().ToLower().Contains("x264"))
1685 x264
= x264bat(input
, tempVideo
, 1, sub
) + "\r\n" +
1686 x264bat(input
, tempVideo
, 2, sub
);
1687 else x264
= x264bat(input
, tempVideo
, 0, sub
);
1688 if (audioMode
== 1 || !hasAudio
)
1689 x264
= x264
.Replace(tempVideo
, output
);
1691 else if (x264ExeComboBox
.SelectedItem
.ToString().ToLower().Contains("x265"))
1693 tempVideo
= Path
.Combine(tempfilepath
, inputName
+ "_vtemp.hevc");
1695 x264
= x265bat(input
, tempVideo
, 1) + "\r\n" +
1696 x265bat(input
, tempVideo
, 2);
1697 else x264
= x265bat(input
, tempVideo
);
1698 if (audioMode
== 1 || !hasAudio
)
1699 x264
+= "\r\n\"" + workPath
+ "\\mp4box.exe\" -add \"" + tempVideo
+ "#trackID=1:name=\" -new \"" + output
+ "\" \r\n";
1704 if (VideoBatchFormatComboBox
.Text
== "mp4")
1705 mux
= boxmuxbat(tempVideo
, tempAudio
, output
);
1707 mux
= ffmuxbat(tempVideo
, tempAudio
, output
);
1708 if (audioMode
!= 1 && hasAudio
) //如果压制音频
1709 bat
+= aextract
+ x264
+ mux
+ " \r\n";
1711 bat
+= x264
+ " \r\n";
1713 bat
+= "del \"" + tempAudio
+ "\"\r\n";
1714 bat
+= "del \"" + tempVideo
+ "\"\r\n";
1715 bat
+= "echo ===== one file is completed! =====\r\n";
1719 private void btnBatchAuto_Click(object sender
, EventArgs e
)
1721 if (lbAuto
.Items
.Count
== 0)
1723 ShowErrorMessage("请输入视频!");
1727 if (x264ExeComboBox
.SelectedIndex
== -1)
1729 ShowErrorMessage("请选择X264程序");
1733 Util
.ensureDirectoryExists(tempfilepath
);
1734 string bat
= string.Empty
;
1735 for (int i
= 0; i
< this.lbAuto
.Items
.Count
; i
++)
1737 string input
= lbAuto
.Items
[i
].ToString();
1739 if (Directory
.Exists(x264PathTextBox
.Text
))
1740 output
= x264PathTextBox
.Text
+ "\\" + Path
.GetFileNameWithoutExtension(input
) + "_batch." + VideoBatchFormatComboBox
.Text
;
1742 output
= Util
.ChangeExt(input
, "_batch." + VideoBatchFormatComboBox
.Text
);
1743 bat
+= VideoBatch(lbAuto
.Items
[i
].ToString(), output
);
1747 Thread
.CurrentThread
.CurrentUICulture
= new System
.Globalization
.CultureInfo(GetCultureName());
1748 WorkingForm wf
= new WorkingForm(bat
, lbAuto
.Items
.Count
);
1751 //batpath = workPath + "\\auto.bat";
1752 //File.WriteAllText(batpath, bat, Encoding.Default);
1753 //Process.Start(batpath);
1756 private void lbffmpeg_MouseDown(object sender
, MouseEventArgs e
)
1758 indexofsource
= ((ListBox
)sender
).IndexFromPoint(e
.X
, e
.Y
);
1759 if (indexofsource
!= ListBox
.NoMatches
)
1761 ((ListBox
)sender
).DoDragDrop(((ListBox
)sender
).Items
[indexofsource
].ToString(), DragDropEffects
.All
);
1765 private void lbffmpeg_DragDrop(object sender
, DragEventArgs e
)
1767 if (e
.Data
.GetDataPresent(DataFormats
.FileDrop
, false))
1769 String
[] files
= (String
[])e
.Data
.GetData(DataFormats
.FileDrop
);
1770 foreach (String s
in files
)
1772 (sender
as ListBox
).Items
.Add(s
);
1775 ListBox listbox
= (ListBox
)sender
;
1776 indexoftarget
= listbox
.IndexFromPoint(listbox
.PointToClient(new Point(e
.X
, e
.Y
)));
1777 if (indexoftarget
!= ListBox
.NoMatches
)
1779 string temp
= listbox
.Items
[indexoftarget
].ToString();
1780 listbox
.Items
[indexoftarget
] = listbox
.Items
[indexofsource
];
1781 listbox
.Items
[indexofsource
] = temp
;
1782 listbox
.SelectedIndex
= indexoftarget
;
1786 private void lbffmpeg_DragOver(object sender
, DragEventArgs e
)
1788 //拖动源和放置的目的地一定是一个ListBox
1789 if (e
.Data
.GetDataPresent(typeof(System
.String
)) && ((ListBox
)sender
).Equals(lbffmpeg
))
1791 e
.Effect
= DragDropEffects
.Move
;
1793 else if (e
.Data
.GetDataPresent(DataFormats
.FileDrop
))
1795 e
.Effect
= DragDropEffects
.Link
;
1797 else e
.Effect
= DragDropEffects
.None
;
1800 private void btnffmpegAdd_Click(object sender
, EventArgs e
)
1802 openFileDialog1
.Multiselect
= true;
1803 openFileDialog1
.Filter
= "所有文件(*.*)|*.*";
1804 DialogResult result
= openFileDialog1
.ShowDialog();
1805 if (result
== DialogResult
.OK
)
1807 lbffmpeg
.Items
.AddRange(openFileDialog1
.FileNames
);
1811 private void btnffmpegDel_Click(object sender
, EventArgs e
)
1813 if (lbffmpeg
.Items
.Count
> 0)
1815 if (lbffmpeg
.SelectedItems
.Count
> 0)
1817 int index
= lbffmpeg
.SelectedIndex
;
1818 lbffmpeg
.Items
.RemoveAt(lbffmpeg
.SelectedIndex
);
1819 if (index
== lbffmpeg
.Items
.Count
)
1821 lbffmpeg
.SelectedIndex
= index
- 1;
1823 if (index
>= 0 && index
< lbffmpeg
.Items
.Count
&& lbffmpeg
.Items
.Count
> 0)
1825 lbffmpeg
.SelectedIndex
= index
;
1831 private void btnffmpegClear_Click(object sender
, EventArgs e
)
1833 lbffmpeg
.Items
.Clear();
1836 private void btnBatchMP4_Click(object sender
, EventArgs e
)
1838 if (lbffmpeg
.Items
.Count
!= 0)
1840 string ext
= MuxFormatComboBox
.Text
;
1842 for (int i
= 0; i
< lbffmpeg
.Items
.Count
; i
++)
1844 string filePath
= lbffmpeg
.Items
[i
].ToString();
1845 //如果是源文件的格式和目标格式相同则跳过
1846 if (Path
.GetExtension(filePath
).Contains(ext
))
1848 string finish
= filePath
.Remove(filePath
.LastIndexOf(".") + 1) + ext
;
1852 MediaInfo MI
= new MediaInfo();
1854 string audio
= MI
.Get(StreamKind
.Audio
, 0, "Format");
1855 if (audio
.ToLower() != "aac")
1857 mux
+= "\"" + workPath
+ "\\ffmpeg.exe\" -y -i \"" + lbffmpeg
.Items
[i
].ToString() + "\" -c:v copy -c:a " + MuxAacEncoderComboBox
.Text
+ " \"" + finish
+ "\" \r\n";
1861 mux
+= "\"" + workPath
+ "\\ffmpeg.exe\" -y -i \"" + lbffmpeg
.Items
[i
].ToString() + "\" -c copy \"" + finish
+ "\" \r\n";
1865 batpath
= workPath
+ "\\mux.bat";
1866 File
.WriteAllText(batpath
, mux
, Encoding
.Default
);
1868 Process
.Start(batpath
);
1870 else ShowErrorMessage("请输入视频!");
1873 private void txtvideo8_TextChanged(object sender
, EventArgs e
)
1875 namevideo8
= txtvideo8
.Text
;
1878 private void btnvextract8_Click(object sender
, EventArgs e
)
1881 ExtractAV(namevideo8
, "v", 0);
1882 //if (namevideo8 == "")
1884 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1888 // vextract = "\"" + workPath + "\\FLVExtractCL.exe\" -v \"" + namevideo8 + "\"";
1889 // batpath = workPath + "\\vextract.bat";
1890 // File.WriteAllText(batpath, vextract, Encoding.Default);
1891 // LogRecord(vextract);
1892 // Process.Start(batpath);
1896 private void btnaextract8_Click(object sender
, EventArgs e
)
1899 ExtractAV(namevideo8
, "a", 0);
1900 //if (namevideo8 == "")
1902 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
1906 // aextract = "\"" + workPath + "\\FLVExtractCL.exe\" -a \"" + namevideo8 + "\"";
1907 // batpath = workPath + "\\aextract.bat";
1908 // File.WriteAllText(batpath, aextract, Encoding.Default);
1909 // LogRecord(aextract);
1910 // Process.Start(batpath);
1914 private void btnvideo8_Click(object sender
, EventArgs e
)
1916 openFileDialog1
.Filter
= "视频(*.flv;*.hlv)|*.flv;*.hlv";
1917 DialogResult result
= openFileDialog1
.ShowDialog();
1918 if (result
== DialogResult
.OK
)
1920 namevideo8
= openFileDialog1
.FileName
;
1921 txtvideo8
.Text
= namevideo
;
1925 private void btnpreview9_Click(object sender
, EventArgs e
)
1927 if (AVSScriptTextBox
.Text
!= "")
1929 string filepath
= workPath
+ "\\temp.avs";
1930 File
.WriteAllText(filepath
, AVSScriptTextBox
.Text
.ToString(), Encoding
.Default
);
1931 if (File
.Exists(SetupPlayerTextBox
.Text
))
1933 Process
.Start(SetupPlayerTextBox
.Text
, filepath
);
1937 PreviewForm pf
= new PreviewForm();
1939 pf
.axWindowsMediaPlayer1
.URL
= filepath
;
1944 ShowErrorMessage("请输入正确的AVS脚本!");
1948 private void txtout_MouseDoubleClick(object sender
, MouseEventArgs e
)
1950 if (File
.Exists(txtout
.Text
.ToString()))
1952 Process
.Start(txtout
.Text
.ToString());
1956 private void txtout3_MouseDoubleClick(object sender
, MouseEventArgs e
)
1958 if (File
.Exists(AudioOutputTextBox
.Text
.ToString()))
1960 Process
.Start(AudioOutputTextBox
.Text
.ToString());
1964 private void txtout6_MouseDoubleClick(object sender
, MouseEventArgs e
)
1966 if (File
.Exists(txtout6
.Text
.ToString()))
1968 Process
.Start(txtout6
.Text
.ToString());
1972 private void txtout9_MouseDoubleClick(object sender
, MouseEventArgs e
)
1974 if (File
.Exists(txtout9
.Text
.ToString()))
1976 Process
.Start(txtout9
.Text
.ToString());
1980 private void txtvideo9_TextChanged(object sender
, EventArgs e
)
1982 if (File
.Exists(txtvideo9
.Text
.ToString()))
1984 namevideo9
= txtvideo9
.Text
;
1985 string finish
= namevideo9
.Remove(namevideo9
.LastIndexOf("."));
1986 finish
+= "_AVS压制.mp4";
1987 txtout9
.Text
= finish
;
1990 //if (txtvideo9.Text != "")
1992 // if (txtAVS.Text != "")
1994 // txtAVS.Text = txtAVS.Text.Replace(prevideo9, txtvideo9.Text);
1998 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
1999 // foreach (FileInfo FileName in TheFolder.GetFiles())
2001 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
2003 // avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\n" + "TextSub(\"" + namesub9 + "\")\r\n";
2004 // txtAVS.Text = avs;
2007 // prevideo9 = txtvideo9.Text;
2011 private void txtsub9_TextChanged(object sender
, EventArgs e
)
2013 namesub9
= txtsub9
.Text
;
2015 //if (txtAVS.Text != "")
2017 // txtAVS.Text=txtAVS.Text.Replace(namesub9, txtsub9.Text);
2018 // namesub9 = txtsub9.Text;
2022 // namesub9 = txtsub9.Text;
2023 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
2024 // foreach (FileInfo FileName in TheFolder.GetFiles())
2026 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
2028 // avs += "\r\nDirectShowSource(\"" + namevideo9 + "\",23.976,convertFPS=True)\r\nConvertToYV12()\r\n" + "TextSub(\"" + namesub9 + "\")\r\n";
2029 // txtAVS.Text = avs;
2034 private void txtout9_TextChanged(object sender
, EventArgs e
)
2036 nameout9
= txtout9
.Text
;
2039 private void btnAVS9_Click(object sender
, EventArgs e
)
2041 x264DemuxerComboBox
.SelectedIndex
= 0; //压制AVS始终使用分离器为auto
2043 if (string.IsNullOrEmpty(nameout9
))
2045 ShowErrorMessage("请选择输出文件");
2049 if (Path
.GetExtension(nameout9
).ToLower() != ".mp4")
2051 ShowErrorMessage("仅支持MP4输出", "不支持的输出格式");
2055 if (File
.Exists(txtout9
.Text
.Trim()))
2057 DialogResult dgs
= ShowQuestion("目标文件:\r\n\r\n" + txtout9
.Text
.Trim() + "\r\n\r\n已经存在,是否覆盖继续压制?", "目标文件已经存在");
2058 if (dgs
== DialogResult
.No
) return;
2061 if (string.IsNullOrEmpty(Util
.CheckAviSynth()) && string.IsNullOrEmpty(Util
.CheckinternalAviSynth()))
2063 if (ShowQuestion("检测到本机未安装avisynth无法继续压制,是否去下载安装", "avisynth未安装") == DialogResult
.Yes
)
2064 Process
.Start("http://sourceforge.net/projects/avisynth2/");
2068 string inputName
= Path
.GetFileNameWithoutExtension(namevideo9
);
2069 string tempVideo
= Path
.Combine(tempfilepath
, inputName
+ "_vtemp.mp4");
2070 string tempAudio
= Path
.Combine(tempfilepath
, inputName
+ "_atemp" + getAudioExt());
2071 Util
.ensureDirectoryExists(tempfilepath
);
2073 string filepath
= tempavspath
;
2074 //string filepath = workpath + "\\temp.avs";
2075 File
.WriteAllText(filepath
, AVSScriptTextBox
.Text
, Encoding
.Default
);
2078 bool hasAudio
= false;
2079 MediaInfo MI
= new MediaInfo();
2080 MI
.Open(namevideo9
);
2081 string audio
= MI
.Get(StreamKind
.Audio
, 0, "Format");
2082 if (!string.IsNullOrEmpty(audio
)) { hasAudio = true; }
2085 if (AVSwithAudioCheckBox
.Checked
&& hasAudio
)
2087 if (!File
.Exists(txtvideo9
.Text
))
2089 ShowErrorMessage("请选择视频文件");
2092 aextract
= audiobat(namevideo9
, tempAudio
);
2095 aextract
= string.Empty
;
2098 if (x264ExeComboBox
.SelectedItem
.ToString().ToLower().Contains("x264"))
2101 x264
= x264bat(filepath
, tempVideo
, 1) + "\r\n" +
2102 x264bat(filepath
, tempVideo
, 2);
2103 else x264
= x264bat(filepath
, tempVideo
);
2104 if (!AVSwithAudioCheckBox
.Checked
|| !hasAudio
)
2105 x264
= x264
.Replace(tempVideo
, nameout9
);
2107 else if (x264ExeComboBox
.SelectedItem
.ToString().ToLower().Contains("x265"))
2109 tempVideo
= Path
.Combine(tempfilepath
, inputName
+ "_vtemp.hevc");
2111 x264
= x265bat(filepath
, tempVideo
, 1) + "\r\n" +
2112 x265bat(filepath
, tempVideo
, 2);
2113 else x264
= x265bat(filepath
, tempVideo
);
2114 if (!AVSwithAudioCheckBox
.Checked
|| !hasAudio
)
2116 x264
+= "\r\n\"" + workPath
+ "\\mp4box.exe\" -add \"" + tempVideo
+ "#trackID=1:name=\" -new \"" + nameout9
+ "\" \r\n";
2117 x264
+= "del \"" + tempVideo
+ "\"";
2121 if (AVSwithAudioCheckBox
.Checked
&& hasAudio
) //如果包含音频
2122 mux
= boxmuxbat(tempVideo
, tempAudio
, nameout9
);
2126 auto
= aextract
+ x264
+ "\r\n" + mux
+ " \r\n";
2127 auto
+= "\r\necho ===== one file is completed! =====\r\n";
2129 Thread
.CurrentThread
.CurrentUICulture
= new System
.Globalization
.CultureInfo(GetCultureName());
2130 WorkingForm wf
= new WorkingForm(auto
);
2133 //auto += "\r\ncmd";
2134 //batpath = workPath + "\\x264avs.bat";
2135 //File.WriteAllText(batpath, auto, Encoding.Default);
2136 //Process.Start(batpath);
2139 private void btnout9_Click(object sender
, EventArgs e
)
2141 SaveFileDialog savefile
= new SaveFileDialog();
2142 savefile
.Filter
= "视频(*.mp4)|*.mp4";
2143 DialogResult result
= savefile
.ShowDialog();
2144 if (result
== DialogResult
.OK
)
2146 txtout9
.Text
= nameout9
= savefile
.FileName
;
2150 private void button6_Click_2(object sender
, EventArgs e
)
2152 //if (Directory.Exists("avsfilter"))
2154 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
2155 // foreach (FileInfo FileName in TheFolder.GetFiles())
2157 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
2160 avs
+= "LoadPlugin(\"avs\\plugins\\VSFilter.DLL\")\r\n";
2161 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
);
2162 //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";
2163 AVSScriptTextBox
.Text
= avs
;
2167 private void txth264_TextChanged(object sender
, EventArgs e
)
2171 private void txtvideo_MouseDoubleClick(object sender
, MouseEventArgs e
)
2173 if (File
.Exists(txtvideo
.Text
.ToString()))
2175 Process
.Start(txtvideo
.Text
.ToString());
2179 private void txtvideo4_MouseDoubleClick(object sender
, MouseEventArgs e
)
2181 if (File
.Exists(txtvideo4
.Text
.ToString()))
2183 Process
.Start(txtvideo4
.Text
.ToString());
2187 private void txtout5_MouseDoubleClick(object sender
, MouseEventArgs e
)
2189 if (File
.Exists(txtout5
.Text
.ToString()))
2191 Process
.Start(txtout5
.Text
.ToString());
2195 private void txtvideo8_MouseDoubleClick(object sender
, MouseEventArgs e
)
2197 if (File
.Exists(txtvideo8
.Text
.ToString()))
2199 Process
.Start(txtvideo8
.Text
.ToString());
2203 private void txtvideo9_MouseDoubleClick(object sender
, MouseEventArgs e
)
2205 if (File
.Exists(txtvideo9
.Text
.ToString()))
2207 Process
.Start(txtvideo9
.Text
.ToString());
2211 private void txtvideo6_MouseDoubleClick(object sender
, MouseEventArgs e
)
2213 if (File
.Exists(txtvideo6
.Text
.ToString()))
2215 Process
.Start(txtvideo6
.Text
.ToString());
2219 private void txtvideo5_MouseDoubleClick(object sender
, MouseEventArgs e
)
2221 if (File
.Exists(txtvideo5
.Text
.ToString()))
2223 Process
.Start(txtvideo5
.Text
.ToString());
2227 private void txtaudio3_MouseDoubleClick(object sender
, MouseEventArgs e
)
2229 if (File
.Exists(txtaudio3
.Text
.ToString()))
2231 Process
.Start(txtaudio3
.Text
.ToString());
2235 private void timer1_Tick(object sender
, EventArgs e
)
2237 Process
[] processes
= Process
.GetProcesses();
2238 for (int i
= 0; i
< processes
.GetLength(0); i
++)
2240 //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
2241 if (processes
[i
].ProcessName
.Equals(Path
.GetFileNameWithoutExtension(x264ExeComboBox
.Text
)))
2243 switch (x264PriorityComboBox
.SelectedIndex
)
2245 case 0: processes
[i
].PriorityClass
= ProcessPriorityClass
.Idle
; break;
2246 case 1: processes
[i
].PriorityClass
= ProcessPriorityClass
.BelowNormal
; break;
2247 case 2: processes
[i
].PriorityClass
= ProcessPriorityClass
.Normal
; break;
2248 case 3: processes
[i
].PriorityClass
= ProcessPriorityClass
.AboveNormal
; break;
2249 case 4: processes
[i
].PriorityClass
= ProcessPriorityClass
.High
; break;
2250 case 5: processes
[i
].PriorityClass
= ProcessPriorityClass
.RealTime
; break;
2256 private void btnsub9_Click(object sender
, EventArgs e
)
2258 openFileDialog1
.Filter
= "字幕(*.ass;*.ssa;*.srt)|*.ass;*.ssa;*.srt|所有文件(*.*)|*.*";
2259 DialogResult result
= openFileDialog1
.ShowDialog();
2260 if (result
== DialogResult
.OK
)
2262 namesub9
= openFileDialog1
.FileName
;
2263 txtsub9
.Text
= namesub9
;
2267 private void btnvideo9_Click(object sender
, EventArgs e
)
2269 openFileDialog1
.Filter
= "视频(*.mp4;*.flv;*.mkv;*.wmv)|*.mp4;*.flv;*.mkv;*.wmv|所有文件(*.*)|*.*";
2270 DialogResult result
= openFileDialog1
.ShowDialog();
2271 if (result
== DialogResult
.OK
)
2273 namevideo9
= openFileDialog1
.FileName
;
2274 txtvideo9
.Text
= namevideo9
;
2278 private void button9_Click(object sender
, EventArgs e
)
2280 AVSScriptTextBox
.Clear();
2283 private void btnClip_Click(object sender
, EventArgs e
)
2285 if (namevideo4
== "")
2287 ShowErrorMessage("请选择视频文件");
2289 else if (nameout5
== "")
2291 ShowErrorMessage("请选择输出文件");
2295 //int h1 = int.Parse(maskb.Text.ToString().Substring(0, 2));
2296 //int m1 = int.Parse(maskb.Text.ToString().Substring(3, 2));
2297 //int s1 = int.Parse(maskb.Text.ToString().Substring(6, 2));
2298 //int h2 = int.Parse(maske.Text.ToString().Substring(0, 2));
2299 //int m2 = int.Parse(maske.Text.ToString().Substring(3, 2));
2300 //int s2 = int.Parse(maske.Text.ToString().Substring(6, 2));
2301 //clip = "\"" + workPath + "\\ffmpeg.exe\" -ss " + maskb.Text + " -to " + maske.Text + " -i \"" + namevideo4 + "\" -acodec copy -vcodec copy \"" + nameout5 + "\" \r\ncmd";
2303 // "<workPath>\ffmpeg.exe" -i "<namevideo4>" -ss <maskb.Text> -to <maske.Text> -c copy "<nameout5>"
2304 clip
= string.Format(@"""{0}\ffmpeg.exe"" -i ""{1}"" -ss {2} -to {3} -y -c copy ""{4}""",
2305 workPath
, namevideo4
, maskb
.Text
, maske
.Text
, nameout5
) + Environment
.NewLine
+ "cmd";
2306 batpath
= workPath
+ "\\clip.bat";
2308 File
.WriteAllText(batpath
, clip
, Encoding
.Default
);
2309 Process
.Start(batpath
);
2313 private void cbX264_SelectedIndexChanged(object sender
, EventArgs e
)
2315 XElement xel
= xdoc
.Element("root").Element("Video").Element("VideoEncoder").Element("x264").Elements()
2316 .Where(x
=> x
.Attribute("Name").Value
== VideoPresetComboBox
.Text
).First();
2317 x264CustomParameterTextBox
.Text
= xel
.Value
;
2320 private void cbFPS_SelectedIndexChanged(object sender
, EventArgs e
)
2322 string ext
= Path
.GetExtension(namevideo
).ToLower();
2323 if (cbFPS
.SelectedIndex
!= 0 && ext
!= ".264" && ext
!= ".h264" && ext
!= ".hevc")
2325 ShowWarningMessage("只有扩展名为.264 .h264 .hevc的流文件设置帧率(fps)才有效");
2326 cbFPS
.SelectedIndex
= 0;
2330 private void btnMIopen_Click(object sender
, EventArgs e
)
2332 openFileDialog1
.Filter
= "视频(*.mp4;*.flv;*.mkv)|*.mp4;*.flv;*.mkv|所有文件(*.*)|*.*";
2333 DialogResult result
= openFileDialog1
.ShowDialog();
2334 if (result
== DialogResult
.OK
)
2336 MIvideo
= openFileDialog1
.FileName
;
2337 MediaInfoTextBox
.Text
= GetMediaInfoString(MIvideo
);
2341 private void btnMIplay_Click(object sender
, EventArgs e
)
2345 Process
.Start(MIvideo
);
2351 private void btnMIcopy_Click(object sender
, EventArgs e
)
2353 Clipboard
.SetText(MItext
);
2356 private void btnvideo7_Click(object sender
, EventArgs e
)
2358 openFileDialog1
.Filter
= "视频(*.mkv)|*.mkv";
2359 DialogResult result
= openFileDialog1
.ShowDialog();
2360 if (result
== DialogResult
.OK
)
2362 namevideo6
= openFileDialog1
.FileName
;
2363 txtvideo6
.Text
= namevideo6
;
2367 private void btnextract7_Click(object sender
, EventArgs e
)
2370 ExtractTrack(namevideo6
, 0);
2373 private void MkvExtract1Button_Click(object sender
, EventArgs e
)
2376 ExtractTrack(namevideo6
, 1);
2379 private void MkvExtract2Button_Click(object sender
, EventArgs e
)
2382 ExtractTrack(namevideo6
, 2);
2385 private void MkvExtract3Button_Click(object sender
, EventArgs e
)
2388 ExtractTrack(namevideo6
, 3);
2391 private void MkvExtract4Button_Click(object sender
, EventArgs e
)
2394 ExtractTrack(namevideo6
, 4);
2397 private void txtMI_TextChanged(object sender
, EventArgs e
)
2399 MItext
= MediaInfoTextBox
.Text
;
2402 private void txtAVScreate_Click(object sender
, EventArgs e
)
2406 private void linkLabel2_LinkClicked(object sender
, LinkLabelLinkClickedEventArgs e
)
2408 Process
.Start("http://www.sosg.net/read.php?tid=480646");
2411 private void btnaextract2_Click(object sender
, EventArgs e
)
2414 ExtractAV(namevideo
, "a", 1);
2415 //if (namevideo == "")
2417 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2421 // //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 3 \"" + namevideo + "\"";
2423 // aextract += Cmd.FormatPath(workPath + "\\ffmpeg.exe");
2424 // aextract += " -i " + Cmd.FormatPath(namevideo);
2425 // aextract += " -vn -sn -c:a:1 copy ";
2426 // string outfile = Cmd.GetDir(namevideo) +
2427 // Path.GetFileNameWithoutExtension(namevideo) + "_抽取音频2" + Path.GetExtension(namevideo);
2428 // aextract += Cmd.FormatPath(outfile);
2429 // batpath = workPath + "\\aextract.bat";
2430 // File.WriteAllText(batpath, aextract, Encoding.Default);
2431 // LogRecord(aextract);
2432 // Process.Start(batpath);
2436 private void btnaextract3_Click(object sender
, EventArgs e
)
2439 ExtractAV(namevideo
, "a", 2);
2440 //if (namevideo == "")
2442 // MessageBox.Show("请选择视频文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
2446 // //aextract = "\"" + workPath + "\\mp4box.exe\" -raw 4 \"" + namevideo + "\"";
2448 // aextract += Cmd.FormatPath(workPath + "\\ffmpeg.exe");
2449 // aextract += " -i " + Cmd.FormatPath(namevideo);
2450 // aextract += " -vn -sn -c:a:2 copy ";
2451 // string outfile = Cmd.GetDir(namevideo) +
2452 // Path.GetFileNameWithoutExtension(namevideo) + "_抽取音频3" + Path.GetExtension(namevideo);
2453 // aextract += Cmd.FormatPath(outfile);
2454 // batpath = workPath + "\\aextract.bat";
2455 // File.WriteAllText(batpath, aextract, Encoding.Default);
2456 // LogRecord(aextract);
2457 // Process.Start(batpath);
2461 private void txtvideo6_TextChanged_1(object sender
, EventArgs e
)
2463 if (File
.Exists(txtvideo6
.Text
.ToString()))
2465 namevideo6
= txtvideo6
.Text
;
2471 private void AboutBtn_Click(object sender
, EventArgs e
)
2473 DateTime CompileDate
= File
.GetLastWriteTime(this.GetType().Assembly
.Location
); //获得程序编译时间
2476 "小丸工具箱 七七版\r\n主页:http://www.maruko.in/ \r\n编译日期:" + CompileDate
.ToString(),
2478 QQMessageBoxIcon
.Information
,
2479 QQMessageBoxButtons
.OK
);
2482 private void HomePageBtn_Click(object sender
, EventArgs e
)
2484 Process
.Start("http://www.maruko.in/");
2491 private void x264VideoBtn_Click(object sender
, EventArgs e
)
2493 openFileDialog1
.Filter
= "视频(*.mp4;*.flv;*.mkv;*.avi;*.wmv;*.mpg;*.avs)|*.mp4;*.flv;*.mkv;*.avi;*.wmv;*.mpg;*.avs|所有文件(*.*)|*.*";
2494 DialogResult result
= openFileDialog1
.ShowDialog();
2495 if (result
== DialogResult
.OK
)
2497 namevideo2
= openFileDialog1
.FileName
;
2498 x264VideoTextBox
.Text
= namevideo2
;
2502 private void x264OutBtn_Click(object sender
, EventArgs e
)
2504 SaveFileDialog savefile
= new SaveFileDialog();
2505 savefile
.Filter
= "MPEG-4 视频(*.mp4)|*.mp4|Flash 视频(*.flv)|*.flv|Matroska 视频(*.mkv)|*.mkv|AVI 视频(*.avi)|*.avi|H.264 流(*.raw)|*.raw";
2506 savefile
.FileName
= Path
.GetFileName(x264OutTextBox
.Text
);
2507 DialogResult result
= savefile
.ShowDialog();
2508 if (result
== DialogResult
.OK
)
2510 nameout2
= savefile
.FileName
;
2511 x264OutTextBox
.Text
= nameout2
;
2515 private void x264SubBtn_Click(object sender
, EventArgs e
)
2517 openFileDialog1
.Filter
= "字幕(*.ass;*.ssa;*.srt)|*.ass;*.ssa;*.srt|所有文件(*.*)|*.*";
2518 DialogResult result
= openFileDialog1
.ShowDialog();
2519 if (result
== DialogResult
.OK
)
2521 namesub2
= openFileDialog1
.FileName
;
2522 x264SubTextBox
.Text
= namesub2
;
2526 private void x264StartBtn_Click(object sender
, EventArgs e
)
2530 if (string.IsNullOrEmpty(namevideo2
))
2532 ShowErrorMessage("请选择视频文件");
2536 if (!string.IsNullOrEmpty(namesub2
) && !File
.Exists(namesub2
))
2538 ShowErrorMessage("字幕文件不存在,请重新选择");
2542 if (string.IsNullOrEmpty(nameout2
))
2544 ShowErrorMessage("请选择输出文件");
2548 if (x264ExeComboBox
.SelectedIndex
== -1)
2550 ShowErrorMessage("请选择X264程序");
2554 if (AudioEncoderComboBox
.SelectedIndex
!= 0 && AudioEncoderComboBox
.SelectedIndex
!= 1 && AudioEncoderComboBox
.SelectedIndex
!= 5)
2556 ShowWarningMessage("音频页面中的编码器未采用AAC将可能导致压制失败,建议将编码器改为QAAC、NeroAAC或FDKAAC。");
2560 if (x264ThreadsComboBox
.SelectedIndex
== -1)
2562 x264ThreadsComboBox
.SelectedIndex
= 0;
2566 if (File
.Exists(x264OutTextBox
.Text
.Trim()))
2568 DialogResult dgs
= ShowQuestion("目标文件:\r\n\r\n" + x264OutTextBox
.Text
.Trim() + "\r\n\r\n已经存在,是否覆盖继续压制?", "目标文件已经存在");
2569 if (dgs
== DialogResult
.No
) return;
2573 if (Path
.GetExtension(x264VideoTextBox
.Text
) == ".avs")
2575 if (string.IsNullOrEmpty(Util
.CheckAviSynth()) && string.IsNullOrEmpty(Util
.CheckinternalAviSynth()))
2577 if (ShowQuestion("检测到本机未安装avisynth无法继续压制,是否去下载安装", "avisynth未安装") == DialogResult
.Yes
)
2578 Process
.Start("http://sourceforge.net/projects/avisynth2/");
2581 //if (File.Exists(tempavspath)) File.Delete(tempavspath);
2582 File
.Copy(x264VideoTextBox
.Text
, tempavspath
, true);
2583 namevideo2
= tempavspath
;
2584 x264DemuxerComboBox
.SelectedIndex
= 0; //压制AVS始终使用分离器为auto
2587 #endregion validation
2589 string ext
= Path
.GetExtension(nameout2
).ToLower();
2590 bool hasAudio
= false;
2591 string inputName
= Path
.GetFileNameWithoutExtension(namevideo2
);
2592 string tempVideo
= Path
.Combine(tempfilepath
, inputName
+ "_vtemp.mp4");
2593 string tempAudio
= Path
.Combine(tempfilepath
, inputName
+ "_atemp" + getAudioExt());
2594 Util
.ensureDirectoryExists(tempfilepath
);
2599 MediaInfo MI
= new MediaInfo();
2600 MI
.Open(namevideo2
);
2601 string audio
= MI
.Get(StreamKind
.Audio
, 0, "Format");
2602 if (!string.IsNullOrEmpty(audio
))
2604 int audioMode
= x264AudioModeComboBox
.SelectedIndex
;
2605 if (!hasAudio
&& x264AudioModeComboBox
.SelectedIndex
!= 1)
2607 DialogResult r
= ShowQuestion("原视频不包含音频流,音频模式是否改为无音频流?", "提示");
2608 if (r
== DialogResult
.Yes
)
2614 aextract
= audiobat(namevideo2
, tempAudio
);
2617 aextract
= string.Empty
;
2620 if (audio
.ToLower() == "aac")
2622 tempAudio
= Path
.Combine(tempfilepath
, inputName
+ "_atemp.aac");
2623 aextract
= ExtractAudio(namevideo2
, tempAudio
);
2627 ShowInfoMessage("因音频编码非AAC故无法复制音频流,音频将被重编码。");
2628 aextract
= audiobat(namevideo2
, tempAudio
);
2638 if (x264ExeComboBox
.SelectedItem
.ToString().ToLower().Contains("x264"))
2641 x264
= x264bat(namevideo2
, tempVideo
, 1, namesub2
) + "\r\n" +
2642 x264bat(namevideo2
, tempVideo
, 2, namesub2
);
2643 else x264
= x264bat(namevideo2
, tempVideo
, 0, namesub2
);
2645 x264
= x264
.Replace(tempVideo
, nameout2
);
2647 else if (x264ExeComboBox
.SelectedItem
.ToString().ToLower().Contains("x265"))
2649 tempVideo
= Path
.Combine(tempfilepath
, inputName
+ "_vtemp.hevc");
2652 ShowErrorMessage("不支持的格式输出,x265当前工具箱仅支持MP4输出");
2656 x264
= x265bat(namevideo2
, tempVideo
, 1) + "\r\n" +
2657 x265bat(namevideo2
, tempVideo
, 2);
2658 else x264
= x265bat(namevideo2
, tempVideo
, 0);
2661 x264
+= "\r\n\"" + workPath
+ "\\mp4box.exe\" -add \"" + tempVideo
+ "#trackID=1:name=\" -new \"" + Util
.ChangeExt(nameout2
, ".mp4") + "\" \r\n";
2662 x264
+= "del \"" + tempVideo
+ "\"";
2675 mux
= boxmuxbat(tempVideo
, tempAudio
, Util
.ChangeExt(nameout2
, ext
));
2677 mux
= ffmuxbat(tempVideo
, tempAudio
, Util
.ChangeExt(nameout2
, ext
));
2678 x264
= aextract
+ x264
+ mux
+ "\r\n"
2679 + "del \"" + tempVideo
+ "\"\r\n"
2680 + "del \"" + tempAudio
+ "\"\r\n";
2682 x264
+= "\r\necho ===== one file is completed! =====\r\n";
2687 Thread
.CurrentThread
.CurrentUICulture
= new System
.Globalization
.CultureInfo(GetCultureName());
2688 WorkingForm wf
= new WorkingForm(x264
);
2691 //x264 += "\r\ncmd";
2692 //batpath = workPath + "\\x264.bat";
2693 //File.WriteAllText(batpath, x264, Encoding.Default);
2694 //Process.Start(batpath);
2697 private void x264AddPresetBtn_Click(object sender
, EventArgs e
)
2701 string vPresetName
= InputBox
.Show("请输入这个预设名称", "请为预置配置命名", "新预置名称");
2702 if (!string.IsNullOrEmpty(vPresetName
))
2704 var xl
= xdoc
.Element("root").Element("Video").Element("VideoEncoder").Element("x264");
2705 XElement xelnew
= new XElement("Parameter", x264CustomParameterTextBox
.Text
,
2706 new XAttribute("Name", vPresetName
));
2707 foreach (var item
in xl
.Elements())
2709 if (item
.Attribute("Name").Value
== vPresetName
)
2711 ShowErrorMessage("预设名称已经存在", "预设名称重复");
2716 xdoc
.Save("preset.xml");
2718 VideoPresetComboBox
.SelectedIndex
= VideoPresetComboBox
.FindString(vPresetName
);
2721 catch (Exception ex
)
2723 ShowErrorMessage("添加失败! Reason: " + ex
.Message
);
2727 private void x264DeletePresetBtn_Click(object sender
, EventArgs e
)
2729 if (ShowQuestion("确定要删除这条预设参数?", "提示") == DialogResult
.Yes
)
2733 var xls
= xdoc
.Element("root").Element("Video").Element("VideoEncoder").Element("x264").Elements();
2734 foreach (var item
in xls
)
2736 if (item
.Attribute("Name").Value
== VideoPresetComboBox
.Text
)
2739 xdoc
.Save("preset.xml");
2742 catch (Exception ex
)
2744 ShowErrorMessage("删除失败! Reason: " + ex
.Message
);
2749 private void x264Mode2RadioButton_CheckedChanged(object sender
, EventArgs e
)
2752 lbrate
.Visible
= true;
2753 x264BitrateNum
.Visible
= true;
2754 label12
.Visible
= true;
2755 //x264FpsComboBox.Visible = true;
2756 //lbFPS2.Visible = true;
2757 lbwidth
.Visible
= true;
2758 lbheight
.Visible
= true;
2759 x264WidthNum
.Visible
= true;
2760 x264HeightNum
.Visible
= true;
2761 MaintainResolutionCheckBox
.Visible
= true;
2762 lbcrf
.Visible
= false;
2763 x264CRFNum
.Visible
= false;
2764 label4
.Visible
= false;
2765 x264CustomParameterTextBox
.Visible
= false;
2766 VideoPresetComboBox
.Visible
= false;
2767 x264AddPresetBtn
.Visible
= false;
2768 x264DeletePresetBtn
.Visible
= false;
2771 private void x264Mode3RadioButton_CheckedChanged(object sender
, EventArgs e
)
2774 label4
.Visible
= true;
2775 x264CustomParameterTextBox
.Visible
= true;
2776 VideoPresetComboBox
.Visible
= true;
2777 x264AddPresetBtn
.Visible
= true;
2778 x264DeletePresetBtn
.Visible
= true;
2779 lbwidth
.Visible
= false;
2780 lbheight
.Visible
= false;
2781 x264WidthNum
.Visible
= false;
2782 x264HeightNum
.Visible
= false;
2783 MaintainResolutionCheckBox
.Visible
= false;
2784 lbrate
.Visible
= false;
2785 x264BitrateNum
.Visible
= false;
2786 label12
.Visible
= false;
2787 lbcrf
.Visible
= false;
2788 x264CRFNum
.Visible
= false;
2789 //x264FpsComboBox.Visible = false;
2790 //lbFPS2.Visible = false;
2793 private void x264Mode1RadioButton_CheckedChanged(object sender
, EventArgs e
)
2796 lbcrf
.Visible
= true;
2797 x264CRFNum
.Visible
= true;
2798 //x264FpsComboBox.Visible = true;
2799 //lbFPS2.Visible = true;
2800 lbwidth
.Visible
= true;
2801 lbheight
.Visible
= true;
2802 x264WidthNum
.Visible
= true;
2803 x264HeightNum
.Visible
= true;
2804 MaintainResolutionCheckBox
.Visible
= true;
2805 lbrate
.Visible
= false;
2806 x264BitrateNum
.Visible
= false;
2807 label12
.Visible
= false;
2808 label4
.Visible
= false;
2809 x264CustomParameterTextBox
.Visible
= false;
2810 VideoPresetComboBox
.Visible
= false;
2811 x264AddPresetBtn
.Visible
= false;
2812 x264DeletePresetBtn
.Visible
= false;
2815 private void x264PriorityComboBox_SelectedIndexChanged(object sender
, EventArgs e
)
2817 string processName
= x264ExeComboBox
.Text
;
2818 processName
= processName
.Replace(".exe", "");
2819 Process
[] processes
= Process
.GetProcesses();
2820 //if (x264PriorityComboBox.SelectedIndex == 4 || x264PriorityComboBox.SelectedIndex == 5)
2822 // if (MessageBox.Show("优先级那么高的话会严重影响其他进程的运行速度,\r\n是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
2824 // x264PriorityComboBox.SelectedIndex = 2;
2828 for (int i
= 0; i
< processes
.GetLength(0); i
++)
2830 //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
2831 if (processes
[i
].ProcessName
.Equals(processName
))
2833 switch (x264PriorityComboBox
.SelectedIndex
)
2835 case 0: processes
[i
].PriorityClass
= ProcessPriorityClass
.Idle
; break;
2836 case 1: processes
[i
].PriorityClass
= ProcessPriorityClass
.BelowNormal
; break;
2837 case 2: processes
[i
].PriorityClass
= ProcessPriorityClass
.Normal
; break;
2838 case 3: processes
[i
].PriorityClass
= ProcessPriorityClass
.AboveNormal
; break;
2839 case 4: processes
[i
].PriorityClass
= ProcessPriorityClass
.High
; break;
2840 case 5: processes
[i
].PriorityClass
= ProcessPriorityClass
.RealTime
; break;
2846 private void x264VideoTextBox_TextChanged(object sender
, EventArgs e
)
2848 string path
= x264VideoTextBox
.Text
;
2849 if (File
.Exists(path
))
2853 string encType
= x264ExeComboBox
.SelectedItem
.ToString().Contains("x265") ? "x265" : "x264";
2854 x264OutTextBox
.Text
= Util
.ChangeExt(namevideo2
, string.Format("_{0}.mp4", encType
));
2855 while (namevideo2
.Equals(x264OutTextBox
.Text
) || File
.Exists(x264OutTextBox
.Text
))
2857 x264OutTextBox
.Text
= Util
.ChangeExt(namevideo2
, string.Format("_new_file({0})_{1}.mp4", num
, encType
));
2861 if (Path
.GetExtension(namevideo2
) != ".avs" && encType
== "x264")
2863 string[] subExt
= { ".ass", ".ssa", ".srt" }
;
2864 foreach (string ext
in subExt
)
2866 if (File
.Exists(Util
.ChangeExt(namevideo2
, ext
)))
2868 x264SubTextBox
.Text
= Util
.ChangeExt(namevideo2
, ext
);
2872 x264SubTextBox
.Text
= string.Empty
;
2879 private void x264OutTextBox_TextChanged(object sender
, EventArgs e
)
2881 nameout2
= x264OutTextBox
.Text
;
2884 private void x264SubTextBox_TextChanged(object sender
, EventArgs e
)
2886 namesub2
= x264SubTextBox
.Text
;
2889 private void x264BatchClearBtn_Click(object sender
, EventArgs e
)
2891 lbAuto
.Items
.Clear();
2894 private void x264BatchDeleteBtn_Click(object sender
, EventArgs e
)
2896 if (lbAuto
.Items
.Count
> 0)
2898 if (lbAuto
.SelectedItems
.Count
> 0)
2900 int index
= lbAuto
.SelectedIndex
;
2901 lbAuto
.Items
.RemoveAt(lbAuto
.SelectedIndex
);
2902 if (index
== lbAuto
.Items
.Count
)
2904 lbAuto
.SelectedIndex
= index
- 1;
2906 if (index
>= 0 && index
< lbAuto
.Items
.Count
&& lbAuto
.Items
.Count
> 0)
2908 lbAuto
.SelectedIndex
= index
;
2914 private void x264BatchAddBtn_Click(object sender
, EventArgs e
)
2916 openFileDialog1
.Multiselect
= true;
2917 openFileDialog1
.Filter
= "所有文件(*.*)|*.*";
2918 DialogResult result
= openFileDialog1
.ShowDialog();
2919 if (result
== DialogResult
.OK
)
2921 lbAuto
.Items
.AddRange(openFileDialog1
.FileNames
);
2930 /// 是否安装 Apple Application Support
2932 /// <returns>true:安装 false:没有安装</returns>
2933 private bool isAppleAppSupportInstalled()
2935 Microsoft
.Win32
.RegistryKey uninstallNode_1
= Microsoft
.Win32
.Registry
.LocalMachine
.OpenSubKey(@"Software\Wow6432Node\Apple Inc.\Apple Application Support"); //x64 OS
2936 Microsoft
.Win32
.RegistryKey uninstallNode_2
= Microsoft
.Win32
.Registry
.LocalMachine
.OpenSubKey(@"Software\Apple Inc.\Apple Application Support"); //x86 OS
2937 if (uninstallNode_1
!= null || uninstallNode_2
!= null)
2947 private void AudioEncoderComboBox_SelectedIndexChanged(object sender
, EventArgs e
)
2949 switch (AudioEncoderComboBox
.SelectedIndex
)
2952 if (File
.Exists(txtaudio2
.Text
))
2953 AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_AAC.mp4");
2954 AudioBitrateComboBox
.Enabled
= true;
2955 AudioBitrateRadioButton
.Enabled
= true;
2956 AudioCustomizeRadioButton
.Enabled
= true;
2957 if (AudioCustomizeRadioButton
.Checked
)
2959 audioDeleteBt
.Visible
= true;
2960 audioAddBt
.Visible
= true;
2965 if (!isAppleAppSupportInstalled())
2967 if (ShowQuestion("Apple Application Support未安装.\r\n音频编码器QAAC可能无法使用.\r\n\r\n是否前往QuickTime下载页面?", "Apple Application Support未安装") == DialogResult
.Yes
)
2968 Process
.Start("http://www.apple.com/cn/quicktime/download");
2970 if (File
.Exists(txtaudio2
.Text
))
2971 AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_AAC.m4a");
2972 AudioBitrateComboBox
.Enabled
= true;
2973 AudioBitrateRadioButton
.Enabled
= true;
2974 AudioCustomizeRadioButton
.Enabled
= true;
2975 if (AudioCustomizeRadioButton
.Checked
)
2977 audioDeleteBt
.Visible
= true;
2978 audioAddBt
.Visible
= true;
2983 if (File
.Exists(txtaudio2
.Text
))
2984 AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_WAV.wav");
2985 AudioBitrateComboBox
.Enabled
= false;
2986 AudioBitrateRadioButton
.Enabled
= false;
2987 AudioCustomizeRadioButton
.Enabled
= false;
2988 audioDeleteBt
.Visible
= false;
2989 audioAddBt
.Visible
= false;
2993 if (File
.Exists(txtaudio2
.Text
))
2994 AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_ALAC.m4a");
2995 AudioBitrateComboBox
.Enabled
= false;
2996 AudioBitrateRadioButton
.Enabled
= false;
2997 AudioCustomizeRadioButton
.Enabled
= false;
2998 audioDeleteBt
.Visible
= false;
2999 audioAddBt
.Visible
= false;
3003 if (File
.Exists(txtaudio2
.Text
))
3004 AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_FLAC.flac");
3005 AudioBitrateComboBox
.Enabled
= false;
3006 AudioBitrateRadioButton
.Enabled
= false;
3007 AudioCustomizeRadioButton
.Enabled
= false;
3008 audioDeleteBt
.Visible
= false;
3009 audioAddBt
.Visible
= false;
3013 if (File
.Exists(txtaudio2
.Text
))
3014 AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_AAC.m4a");
3015 AudioBitrateComboBox
.Enabled
= true;
3016 AudioBitrateRadioButton
.Enabled
= true;
3017 AudioCustomizeRadioButton
.Enabled
= true;
3018 if (AudioCustomizeRadioButton
.Checked
)
3020 audioDeleteBt
.Visible
= true;
3021 audioAddBt
.Visible
= true;
3026 if (File
.Exists(txtaudio2
.Text
))
3027 AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_AC3.ac3");
3028 AudioBitrateComboBox
.Enabled
= true;
3029 AudioBitrateRadioButton
.Enabled
= true;
3030 AudioCustomizeRadioButton
.Enabled
= false;
3031 audioDeleteBt
.Visible
= false;
3032 audioAddBt
.Visible
= false;
3039 XElement xAudios
= xdoc
.Element("root").Element("Audio").Element("AudioEncoder").Element(AudioEncoderComboBox
.Text
);
3040 if (xAudios
!= null)
3042 AudioPresetComboBox
.Items
.Clear();
3043 AudioCustomParameterTextBox
.Text
= string.Empty
;
3044 foreach (XElement item
in xAudios
.Elements())
3046 AudioPresetComboBox
.Items
.Add(item
.Attribute("Name").Value
);
3047 AudioPresetComboBox
.SelectedIndex
= 0;
3052 AudioPresetComboBox
.Items
.Clear();
3053 AudioCustomParameterTextBox
.Text
= string.Empty
;
3058 private void AudioListBox_DragDrop(object sender
, DragEventArgs e
)
3060 ListBox listbox
= (ListBox
)sender
;
3061 if (e
.Data
.GetDataPresent(DataFormats
.FileDrop
, false))
3063 String
[] files
= (String
[])e
.Data
.GetData(DataFormats
.FileDrop
);
3064 foreach (String s
in files
)
3066 listbox
.Items
.Add(s
);
3070 indexoftarget
= listbox
.IndexFromPoint(listbox
.PointToClient(new Point(e
.X
, e
.Y
)));
3071 if (indexoftarget
!= ListBox
.NoMatches
)
3073 string temp
= listbox
.Items
[indexoftarget
].ToString();
3074 listbox
.Items
[indexoftarget
] = listbox
.Items
[indexofsource
];
3075 listbox
.Items
[indexofsource
] = temp
;
3076 listbox
.SelectedIndex
= indexoftarget
;
3080 private void AudioListBox_DragOver(object sender
, DragEventArgs e
)
3082 ListBox listbox
= (ListBox
)sender
;
3083 if (e
.Data
.GetDataPresent(typeof(System
.String
)) && ((ListBox
)sender
).Equals(listbox
))
3085 e
.Effect
= DragDropEffects
.Move
;
3087 else if (e
.Data
.GetDataPresent(DataFormats
.FileDrop
))
3089 e
.Effect
= DragDropEffects
.Link
;
3091 else e
.Effect
= DragDropEffects
.None
;
3094 private void AudioListBox_MouseDown(object sender
, MouseEventArgs e
)
3096 indexofsource
= ((ListBox
)sender
).IndexFromPoint(e
.X
, e
.Y
);
3097 if (indexofsource
!= ListBox
.NoMatches
)
3099 ((ListBox
)sender
).DoDragDrop(((ListBox
)sender
).Items
[indexofsource
].ToString(), DragDropEffects
.All
);
3103 private void AudioBatchButton_Click(object sender
, EventArgs e
)
3105 if (AudioListBox
.Items
.Count
!= 0)
3107 string finish
, outputExt
, codec
;
3109 switch (AudioEncoderComboBox
.SelectedIndex
)
3111 case 0: outputExt
= "mp4"; codec
= "AAC"; break;
3112 case 1: outputExt
= "m4a"; codec
= "AAC"; break;
3113 case 2: outputExt
= "wav"; codec
= "WAV"; break;
3114 case 3: outputExt
= "m4a"; codec
= "ALAC"; break;
3115 case 4: outputExt
= "flac"; codec
= "FLAC"; break;
3116 case 5: outputExt
= "m4a"; codec
= "AAC"; break;
3117 case 6: outputExt
= "ac3"; codec
= "AC3"; break;
3118 default: outputExt
= "aac"; codec
= "AAC"; break;
3120 for (int i
= 0; i
< this.AudioListBox
.Items
.Count
; i
++)
3122 string outname
= "_" + codec
+ "." + outputExt
;
3123 finish
= Util
.ChangeExt(AudioListBox
.Items
[i
].ToString(), outname
);
3124 aac
+= audiobat(AudioListBox
.Items
[i
].ToString(), finish
);
3128 batpath
= workPath
+ "\\aac.bat";
3129 File
.WriteAllText(batpath
, aac
, Encoding
.Default
);
3131 Process
.Start(batpath
);
3133 else ShowErrorMessage("请输入文件!");
3136 private void btnaudio2_Click(object sender
, EventArgs e
)
3138 openFileDialog1
.Filter
= "所有文件(*.*)|*.*";
3139 DialogResult result
= openFileDialog1
.ShowDialog();
3140 if (result
== DialogResult
.OK
)
3142 nameaudio2
= openFileDialog1
.FileName
;
3143 txtaudio2
.Text
= nameaudio2
;
3147 private void btnout3_Click(object sender
, EventArgs e
)
3149 SaveFileDialog savefile
= new SaveFileDialog();
3150 savefile
.Filter
= "所有文件(*.*)|*.*";
3151 //savefile.Filter = "音频(*.aac;*.wav;*.m4a;*.flac)|*.aac*.wav;*.m4a;*.flac;";
3152 DialogResult result
= savefile
.ShowDialog();
3153 if (result
== DialogResult
.OK
)
3155 nameout3
= savefile
.FileName
+ getAudioExt();
3156 AudioOutputTextBox
.Text
= nameout3
;
3160 private void btnaac_Click(object sender
, EventArgs e
)
3162 if (nameaudio2
== "")
3164 ShowErrorMessage("请选择音频文件");
3166 else if (nameout3
== "")
3168 ShowErrorMessage("请选择输出文件");
3172 batpath
= workPath
+ "\\aac.bat";
3173 File
.WriteAllText(batpath
, audiobat(nameaudio2
, nameout3
), Encoding
.Default
);
3174 LogRecord(audiobat(nameaudio2
, nameout3
));
3175 Process
.Start(batpath
);
3179 private void txtaudio2_TextChanged(object sender
, EventArgs e
)
3181 if (File
.Exists(txtaudio2
.Text
.ToString()))
3183 nameaudio2
= txtaudio2
.Text
;
3184 switch (AudioEncoderComboBox
.SelectedIndex
)
3186 case 0: AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_AAC.mp4"); break;
3187 case 1: AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_AAC.m4a"); break;
3188 case 2: AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_WAV.wav"); break;
3189 case 3: AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_ALAC.m4a"); break;
3190 case 4: AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_FLAC.flac"); break;
3191 case 5: AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_AAC.m4a"); break;
3192 case 6: AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_AC3.ac3"); break;
3193 default: AudioOutputTextBox
.Text
= Util
.ChangeExt(txtaudio2
.Text
, "_AAC.aac"); break;
3198 private void txtout3_TextChanged(object sender
, EventArgs e
)
3200 nameout3
= AudioOutputTextBox
.Text
;
3203 private void txtaudio2_MouseDoubleClick(object sender
, MouseEventArgs e
)
3205 if (File
.Exists(txtaudio2
.Text
.ToString()))
3207 Process
.Start(txtaudio2
.Text
.ToString());
3211 private void radioButton5_CheckedChanged(object sender
, EventArgs e
)
3213 lbaacrate
.Visible
= false;
3214 lbaackbps
.Visible
= false;
3215 AudioBitrateComboBox
.Visible
= false;
3216 AudioCustomParameterTextBox
.Visible
= true;
3217 AudioPresetLabel
.Visible
= true;
3218 AudioPresetComboBox
.Visible
= true;
3219 audioDeleteBt
.Visible
= true;
3220 audioAddBt
.Visible
= true;
3223 private void radioButton4_CheckedChanged(object sender
, EventArgs e
)
3225 lbaacrate
.Visible
= true;
3226 lbaackbps
.Visible
= true;
3227 AudioBitrateComboBox
.Visible
= true;
3228 AudioCustomParameterTextBox
.Visible
= false;
3229 AudioPresetLabel
.Visible
= false;
3230 AudioPresetComboBox
.Visible
= false;
3231 audioDeleteBt
.Visible
= false;
3232 audioAddBt
.Visible
= false;
3235 private void AudioAddButton_Click(object sender
, EventArgs e
)
3237 openFileDialog1
.Multiselect
= true;
3238 openFileDialog1
.Filter
= "所有文件(*.*)|*.*";
3239 DialogResult result
= openFileDialog1
.ShowDialog();
3240 if (result
== DialogResult
.OK
)
3242 AudioListBox
.Items
.AddRange(openFileDialog1
.FileNames
);
3246 private void AudioDeleteButton_Click(object sender
, EventArgs e
)
3248 if (AudioListBox
.Items
.Count
> 0)
3250 if (AudioListBox
.SelectedItems
.Count
> 0)
3252 int index
= AudioListBox
.SelectedIndex
;
3253 AudioListBox
.Items
.RemoveAt(AudioListBox
.SelectedIndex
);
3254 if (index
== AudioListBox
.Items
.Count
)
3256 AudioListBox
.SelectedIndex
= index
- 1;
3258 if (index
>= 0 && index
< AudioListBox
.Items
.Count
&& AudioListBox
.Items
.Count
> 0)
3260 AudioListBox
.SelectedIndex
= index
;
3266 private void AudioClearButton_Click(object sender
, EventArgs e
)
3268 AudioListBox
.Items
.Clear();
3275 private void GenerateAVS()
3277 //if (Directory.Exists("avsfilter"))
3279 // DirectoryInfo TheFolder = new DirectoryInfo("avsfilter");
3280 // foreach (FileInfo FileName in TheFolder.GetFiles())
3282 // avs += "LoadPlugin(\"" + workpath + "\\avsfilter\\" + FileName + "\")\r\n";
3285 avsBuilder
.Remove(0, avsBuilder
.Length
);
3286 string vsfilterDLLPath
= Path
.Combine(workPath
, @"avs\plugins\VSFilter.DLL");
3287 string LSMASHSourceDLLPath
= Path
.Combine(workPath
, @"avs\plugins\LSMASHSource.DLL");
3288 string undotDLLPath
= Path
.Combine(workPath
, @"avs\plugins\UnDot.DLL");
3289 avsBuilder
.AppendLine("LoadPlugin(\"" + vsfilterDLLPath
+ "\")");
3290 avsBuilder
.AppendLine("LoadPlugin(\"" + LSMASHSourceDLLPath
+ "\")");
3291 string extInput
= Path
.GetExtension(namevideo9
).ToLower();
3293 if (UndotCheckBox
.Checked
)
3294 avsBuilder
.AppendLine("LoadPlugin(\"" + undotDLLPath
+ "\")");
3295 if (extInput
== ".mp4"
3296 || extInput
== ".mov"
3297 || extInput
== ".qt"
3298 || extInput
== ".3gp"
3299 || extInput
== ".3g2")
3300 avsBuilder
.AppendLine("LSMASHVideoSource(\"" + namevideo9
+ "\")");
3302 avsBuilder
.AppendLine("LWLibavVideoSource(\"" + namevideo9
+ "\")");
3303 avsBuilder
.AppendLine("ConvertToYV12()");
3304 if (UndotCheckBox
.Checked
)
3305 avsBuilder
.AppendLine("Undot()");
3306 if (TweakCheckBox
.Checked
)
3307 avsBuilder
.AppendLine("Tweak(" + TweakChromaNumericUpDown
.Value
.ToString() + ", " + TweakSaturationNumericUpDown
.Value
.ToString() + ", " + TweakBrightnessNumericUpDown
.Value
.ToString() + ", " + TweakContrastNumericUpDown
.Value
.ToString() + ")");
3308 if (LevelsCheckBox
.Checked
)
3309 avsBuilder
.AppendLine("Levels(0," + LevelsNumericUpDown
.Value
.ToString() + ",255,0,255)");
3310 if (LanczosResizeCheckBox
.Checked
)
3311 avsBuilder
.AppendLine("LanczosResize(" + AVSWidthNumericUpDown
.Value
.ToString() + "," + AVSHeightNumericUpDown
.Value
.ToString() + ")");
3312 if (SharpenCheckBox
.Checked
)
3313 avsBuilder
.AppendLine("Sharpen(" + SharpenNumericUpDown
.Value
.ToString() + ")");
3314 if (CropCheckBox
.Checked
)
3315 avsBuilder
.AppendLine("Crop(" + AVSCropTextBox
.Text
+ ")");
3316 if (AddBordersCheckBox
.Checked
)
3317 avsBuilder
.AppendLine("AddBorders(" + AddBorders1NumericUpDown
.Value
.ToString() + "," + AddBorders2NumericUpDown
.Value
.ToString() + "," + AddBorders3NumericUpDown
.Value
.ToString() + "," + AddBorders4NumericUpDown
.Value
.ToString() + ")");
3318 if (!string.IsNullOrEmpty(txtsub9
.Text
))
3320 if (Path
.GetExtension(namesub9
) == ".idx")
3321 avsBuilder
.AppendLine("vobsub(\"" + namesub9
+ "\")");
3323 avsBuilder
.AppendLine("TextSub(\"" + namesub9
+ "\")");
3325 if (TrimCheckBox
.Checked
)
3326 avsBuilder
.AppendLine("Trim(" + TrimStartNumericUpDown
.Value
.ToString() + "," + TrimEndNumericUpDown
.Value
.ToString() + ")");
3327 AVSScriptTextBox
.Text
= avsBuilder
.ToString();
3332 private void TweakCheckBox_CheckedChanged(object sender
, EventArgs e
)
3337 private void LanczosResizeCheckBox_CheckedChanged(object sender
, EventArgs e
)
3342 private void AddBordersCheckBox_CheckedChanged(object sender
, EventArgs e
)
3347 private void CropCheckBox_CheckedChanged(object sender
, EventArgs e
)
3352 private void TrimCheckBox_CheckedChanged(object sender
, EventArgs e
)
3357 private void LevelsCheckBox_CheckedChanged(object sender
, EventArgs e
)
3362 private void SharpenCheckBox_CheckedChanged(object sender
, EventArgs e
)
3367 private void UndotCheckBox_CheckedChanged(object sender
, EventArgs e
)
3372 private void TweakChromaNumericUpDown_ValueChanged(object sender
, EventArgs e
)
3377 private void TweakSaturationNumericUpDown_ValueChanged(object sender
, EventArgs e
)
3382 private void TweakBrightnessNumericUpDown_ValueChanged(object sender
, EventArgs e
)
3387 private void TweakContrastNumericUpDown_ValueChanged(object sender
, EventArgs e
)
3392 private void AVSWidthNumericUpDown_ValueChanged(object sender
, EventArgs e
)
3397 private void AVSHeightNumericUpDown_ValueChanged(object sender
, EventArgs e
)
3402 private void AddBorders1NumericUpDown_ValueChanged(object sender
, EventArgs e
)
3407 private void AddBorders2NumericUpDown_ValueChanged(object sender
, EventArgs e
)
3412 private void AddBorders3NumericUpDown_ValueChanged(object sender
, EventArgs e
)
3417 private void AddBorders4NumericUpDown_ValueChanged(object sender
, EventArgs e
)
3422 private void AVSCropTextBox_TextChanged(object sender
, EventArgs e
)
3427 private void TrimStartNumericUpDown_ValueChanged(object sender
, EventArgs e
)
3432 private void TrimEndNumericUpDown_ValueChanged(object sender
, EventArgs e
)
3437 private void LevelsNumericUpDown_ValueChanged(object sender
, EventArgs e
)
3442 private void SharpenNumericUpDown_ValueChanged(object sender
, EventArgs e
)
3451 private void ExtractMP4Button_Click(object sender
, EventArgs e
)
3453 openFileDialog1
.Filter
= "视频(*.mp4)|*.mp4|所有文件(*.*)|*.*";
3454 DialogResult result
= openFileDialog1
.ShowDialog();
3455 if (result
== DialogResult
.OK
)
3457 namevideo
= openFileDialog1
.FileName
;
3458 ExtractMP4TextBox
.Text
= namevideo
;
3462 private void txtAVS_TextChanged(object sender
, EventArgs e
)
3464 Match m
= Regex
.Match(AVSScriptTextBox
.Text
, "ource\\(\"[a-zA-Z]:\\\\.+\\.\\w+\"");
3467 string str
= m
.ToString();
3468 str
= str
.Replace("ource(\"", "");
3469 str
= str
.Replace("\"", "");
3470 str
= Util
.ChangeExt(str
, "_AVS.mp4");
3475 public void Log(string path
)
3477 ProcessStartInfo start
= new ProcessStartInfo(path
);//设置运行的命令行文件问ping.exe文件,这个文件系统会自己找到
3478 //如果是其它exe文件,则有可能需要指定详细路径,如运行winRar.exe
3479 start
.CreateNoWindow
= false;//不显示dos命令行窗口
3480 start
.RedirectStandardOutput
= true;//
3481 start
.RedirectStandardInput
= true;//
3482 start
.UseShellExecute
= false;//是否指定操作系统外壳进程启动程序
3483 Process p
= Process
.Start(start
);
3484 StreamReader reader
= p
.StandardOutput
;//截取输出流
3485 string line
= reader
.ReadLine();//每次读取一行
3486 StringBuilder log
= new StringBuilder(2000);
3487 while (!reader
.EndOfStream
)
3489 log
.Append(line
+ "\r\n");
3490 line
= reader
.ReadLine();
3492 p
.WaitForExit();//等待程序执行完退出进程
3493 File
.WriteAllText(startpath
+ "\\log.txt", log
.ToString(), Encoding
.Default
);
3495 reader
.Close();//关闭流
3498 public void LogRecord(string log
)
3500 Util
.ensureDirectoryExists(logPath
);
3501 File
.AppendAllText(logFileName
,
3502 "===========" + DateTime
.Now
.ToString() + "===========\r\n" + log
+ "\r\n\r\n", Encoding
.Default
);
3505 private void DeleteLogButton_Click(object sender
, EventArgs e
)
3507 if (Directory
.Exists(logPath
))
3509 Util
.DeleteDirectoryIfExists(logPath
, true);
3510 ShowInfoMessage("已经删除日志文件。");
3512 else ShowInfoMessage("没有找到日志文件。");
3515 private void ViewLogButton_Click(object sender
, EventArgs e
)
3517 if (File
.Exists(logFileName
))
3519 Process
.Start(logFileName
);
3521 else ShowInfoMessage("没有找到日志文件。");
3524 private void x264PathButton_Click(object sender
, EventArgs e
)
3526 FolderBrowserDialog fbd
= new FolderBrowserDialog();
3527 if (fbd
.ShowDialog() == DialogResult
.OK
)
3528 x264PathTextBox
.Text
= fbd
.SelectedPath
;
3531 private void ExtractMP4TextBox_TextChanged(object sender
, EventArgs e
)
3533 namevideo
= ExtractMP4TextBox
.Text
;
3536 private void MaintainResolutionCheckBox_CheckedChanged(object sender
, EventArgs e
)
3538 if (MaintainResolutionCheckBox
.Checked
)
3540 x264WidthNum
.Value
= 0;
3541 x264HeightNum
.Value
= 0;
3542 x264WidthNum
.Enabled
= false;
3543 x264HeightNum
.Enabled
= false;
3547 x264WidthNum
.Enabled
= true;
3548 x264HeightNum
.Enabled
= true;
3552 #region globalization
3554 public static void SetLang(string lang
, Form form
, Type formType
)
3556 Thread
.CurrentThread
.CurrentUICulture
= new System
.Globalization
.CultureInfo(lang
);
3559 ComponentResourceManager resources
= new ComponentResourceManager(formType
);
3560 resources
.ApplyResources(form
, "$this");
3561 AppLang(form
, resources
);
3565 private static void AppLang(Control control
, ComponentResourceManager resources
)
3567 foreach (Control c
in control
.Controls
)
3569 resources
.ApplyResources(c
, c
.Name
);
3570 AppLang(c
, resources
);
3574 private void languageComboBox_SelectedIndexChanged(object sender
, EventArgs e
)
3577 x264Mode1RadioButton
.Checked
= true;
3578 AudioBitrateRadioButton
.Checked
= true;
3579 int x264AudioModeComboBoxIndex
= 0;
3580 switch (languageComboBox
.SelectedIndex
)
3583 SetLang("zh-CN", this, typeof(MainForm
));
3584 this.Text
= string.Format("小丸工具箱 {0}", Assembly
.GetExecutingAssembly().GetName().Version
.Build
);
3585 x264PriorityComboBox
.Items
.Clear();
3586 x264PriorityComboBox
.Items
.AddRange(new string[] { "低", "低于标准", "普通", "高于标准", "高", "实时" }
);
3587 x264PriorityComboBox
.SelectedIndex
= 2;
3588 x264AudioModeComboBoxIndex
= x264AudioModeComboBox
.SelectedIndex
;
3589 x264AudioModeComboBox
.Items
.Clear();
3590 x264AudioModeComboBox
.Items
.Add("压制音频");
3591 x264AudioModeComboBox
.Items
.Add("无音频流");
3592 x264AudioModeComboBox
.Items
.Add("复制音频流");
3593 x264AudioModeComboBox
.SelectedIndex
= x264AudioModeComboBoxIndex
;
3594 x264VideoTextBox
.EmptyTextTip
= "可以把文件拖拽到这里";
3595 x264SubTextBox
.EmptyTextTip
= "双击清空字幕文件文本框";
3596 //x264OutTextBox.EmptyTextTip = "宽度和高度全为0即不改变分辨率";
3597 x264PathTextBox
.EmptyTextTip
= "字幕文件和视频文件在同一目录下且同名,不同名仅有语言后缀时请在右方选择或输入";
3598 //txtvideo3.EmptyTextTip = "音频参数在音频选项卡设定";
3599 ExtractMP4TextBox
.EmptyTextTip
= "抽取的视频或音频在原视频目录下";
3600 txtvideo8
.EmptyTextTip
= "抽取的视频或音频在原视频目录下";
3601 txtvideo6
.EmptyTextTip
= "抽取的视频或音频在原视频目录下";
3603 if (File
.Exists(startpath
+ "\\help.rtf"))
3605 HelpTextBox
.LoadFile(startpath
+ "\\help.rtf");
3610 SetLang("zh-TW", this, typeof(MainForm
));
3611 this.Text
= string.Format("小丸工具箱 {0}", Assembly
.GetExecutingAssembly().GetName().Version
.Build
);
3612 x264PriorityComboBox
.Items
.Clear();
3613 x264PriorityComboBox
.Items
.AddRange(new string[] { "低", "在標準以下", "標準", "在標準以上", "高", "即時" }
);
3614 x264PriorityComboBox
.SelectedIndex
= 2;
3615 x264AudioModeComboBoxIndex
= x264AudioModeComboBox
.SelectedIndex
;
3616 x264AudioModeComboBox
.Items
.Clear();
3617 x264AudioModeComboBox
.Items
.Add("壓制音頻");
3618 x264AudioModeComboBox
.Items
.Add("無音頻流");
3619 x264AudioModeComboBox
.Items
.Add("拷貝音頻流");
3620 x264AudioModeComboBox
.SelectedIndex
= x264AudioModeComboBoxIndex
;
3621 x264VideoTextBox
.EmptyTextTip
= "可以把文件拖拽到這裡";
3622 x264SubTextBox
.EmptyTextTip
= "雙擊清空字幕檔案文本框";
3623 //x264OutTextBox.EmptyTextTip = "寬度和高度全為0即不改變解析度";
3624 x264PathTextBox
.EmptyTextTip
= "字幕和視頻在同一資料夾下且同名,不同名僅有語言後綴時請在右方選擇或輸入";
3625 //txtvideo3.EmptyTextTip = "音頻參數需在音頻選項卡设定";
3626 ExtractMP4TextBox
.EmptyTextTip
= "新檔案生成在原資料夾";
3627 txtvideo8
.EmptyTextTip
= "新檔案生成在原資料夾";
3628 txtvideo6
.EmptyTextTip
= "新檔案生成在原資料夾";
3630 if (File
.Exists(startpath
+ "\\help_zh_tw.rtf"))
3632 HelpTextBox
.LoadFile(startpath
+ "\\help_zh_tw.rtf");
3637 SetLang("en-US", this, typeof(MainForm
));
3638 this.Text
= string.Format("Maruko Toolbox {0}", Assembly
.GetExecutingAssembly().GetName().Version
.Build
);
3639 x264PriorityComboBox
.Items
.Clear();
3640 x264PriorityComboBox
.Items
.AddRange(new string[] { "Idle", "BelowNormal", "Normal", "AboveNormal", "High", "RealTime" }
);
3641 x264PriorityComboBox
.SelectedIndex
= 2;
3642 x264AudioModeComboBoxIndex
= x264AudioModeComboBox
.SelectedIndex
;
3643 x264AudioModeComboBox
.Items
.Clear();
3644 x264AudioModeComboBox
.Items
.Add("with audio");
3645 x264AudioModeComboBox
.Items
.Add("no audio");
3646 x264AudioModeComboBox
.Items
.Add("copy audio");
3647 x264AudioModeComboBox
.SelectedIndex
= x264AudioModeComboBoxIndex
;
3648 x264VideoTextBox
.EmptyTextTip
= "Drag file here";
3649 x264SubTextBox
.EmptyTextTip
= "Clear subtitle text box by double click";
3650 //x264OutTextBox.EmptyTextTip = "Both the width and height equal zero means using original resolution";
3651 x264PathTextBox
.EmptyTextTip
= "Subtitle and Video must be of the same name and in the same folder";
3652 //txtvideo3.EmptyTextTip = "It is necessary to set audio parameter in the Audio tab";
3653 ExtractMP4TextBox
.EmptyTextTip
= "New file will be created in the original folder";
3654 txtvideo8
.EmptyTextTip
= "New file will be created in the original folder";
3655 txtvideo6
.EmptyTextTip
= "New file will be created in the original folder";
3657 if (File
.Exists(startpath
+ "\\help.rtf"))
3659 HelpTextBox
.LoadFile(startpath
+ "\\help.rtf");
3664 SetLang("ja-JP", this, typeof(MainForm
));
3665 this.Text
= string.Format("Maruko Toolbox {0}", Assembly
.GetExecutingAssembly().GetName().Version
.Build
);
3666 x264PriorityComboBox
.Items
.Clear();
3667 x264PriorityComboBox
.Items
.AddRange(new string[] { "低", "通常以下", "通常", "通常以上", "高", "リアルタイム" }
);
3668 x264PriorityComboBox
.SelectedIndex
= 2;
3669 x264AudioModeComboBoxIndex
= x264AudioModeComboBox
.SelectedIndex
;
3670 x264AudioModeComboBox
.Items
.Clear();
3671 x264AudioModeComboBox
.Items
.Add("オーディオ付き");
3672 x264AudioModeComboBox
.Items
.Add("オーディオなし");
3673 x264AudioModeComboBox
.Items
.Add("オーディオ コピー");
3674 x264AudioModeComboBox
.SelectedIndex
= x264AudioModeComboBoxIndex
;
3675 x264VideoTextBox
.EmptyTextTip
= "ビデオファイルをここに引きずってください";
3676 x264SubTextBox
.EmptyTextTip
= "ダブルクリックで字幕を削除する";
3677 //x264OutTextBox.EmptyTextTip = "Both the width and height equal zero means using original resolution";
3678 x264PathTextBox
.EmptyTextTip
= "字幕とビデオは同じ名前と同じフォルダにある必要があります";
3679 //txtvideo3.EmptyTextTip = "It is necessary to set audio parameter in the Audio tab";
3680 ExtractMP4TextBox
.EmptyTextTip
= "新しいファイルはビデオファイルのあるディレクトリに生成する";
3681 txtvideo8
.EmptyTextTip
= "新しいファイルはビデオファイルのあるディレクトリに生成する";
3682 txtvideo6
.EmptyTextTip
= "新しいファイルはビデオファイルのあるディレクトリに生成する";
3683 if (File
.Exists(startpath
+ "\\help.rtf"))
3685 HelpTextBox
.LoadFile(startpath
+ "\\help.rtf");
3694 private string GetCultureName()
3696 string name
= "zh-CN";
3697 switch (languageComboBox
.SelectedIndex
)
3721 #endregion globalization
3723 public static void RunProcess(string exe
, string arg
)
3725 Thread thread
= new Thread(() =>
3727 ProcessStartInfo psi
= new ProcessStartInfo(exe
, arg
);
3728 psi
.CreateNoWindow
= true;
3729 Process p
= new Process();
3733 MessageBox
.Show("ts");
3736 thread
.IsBackground
= true;
3740 private void AVSSaveButton_Click(object sender
, EventArgs e
)
3742 SaveFileDialog savefile
= new SaveFileDialog();
3743 savefile
.Filter
= "AVS(*.avs)|*.avs";
3744 DialogResult result
= savefile
.ShowDialog();
3745 if (result
== DialogResult
.OK
)
3747 File
.WriteAllText(savefile
.FileName
, AVSScriptTextBox
.Text
, Encoding
.Default
);
3751 private void MuxReplaceAudioButton_Click(object sender
, EventArgs e
)
3753 if (namevideo
== "")
3755 ShowErrorMessage("请选择视频文件");
3758 if (nameaudio
== "")
3760 ShowErrorMessage("请选择音频文件");
3765 ShowErrorMessage("请选择输出文件");
3769 //mux = "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + namevideo + "\" -c:v copy -an \"" + workPath + "\\video_noaudio.mp4\" \r\n";
3770 //mux += "\"" + workPath + "\\ffmpeg.exe\" -y -i \"" + workPath + "\\video_noaudio.mp4\" -i \"" + nameaudio + "\" -vcodec copy -acodec copy \"" + nameout + "\" \r\n";
3771 //mux += "del \"" + workPath + "\\video_noaudio.mp4\" \r\n";
3772 mux
= "\"" + workPath
+ "\\ffmpeg.exe\" -y -i \"" + namevideo
+ "\" -i \"" + nameaudio
+ "\" -map 0:v -c:v copy -map 1:0 -c:a copy \"" + txtout
.Text
+ "\" \r\n";
3773 batpath
= workPath
+ "\\mux.bat";
3774 File
.WriteAllText(batpath
, mux
, Encoding
.Default
);
3776 Process
.Start(batpath
);
3781 private void AudioPicButton_Click(object sender
, EventArgs e
)
3783 openFileDialog1
.Filter
= "图片(*.jpg;*.jpeg;*.png;*.bmp;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件(*.*)|*.*";
3784 DialogResult result
= openFileDialog1
.ShowDialog();
3785 if (result
== DialogResult
.OK
)
3787 AudioPicTextBox
.Text
= openFileDialog1
.FileName
;
3791 private void AudioPicAudioButton_Click(object sender
, EventArgs e
)
3793 openFileDialog1
.Filter
= "音频(*.aac;*.mp3;*.mp4;*.wav)|*.aac;*.mp3;*.mp4;*.wav|所有文件(*.*)|*.*";
3794 DialogResult result
= openFileDialog1
.ShowDialog();
3795 if (result
== DialogResult
.OK
)
3797 AudioPicAudioTextBox
.Text
= openFileDialog1
.FileName
;
3801 private void AudioOnePicOutputButton_Click(object sender
, EventArgs e
)
3803 SaveFileDialog savefile
= new SaveFileDialog();
3804 savefile
.Filter
= "MP4视频(*.mp4)|*.mp4|FLV视频(*.flv)|*.flv";
3805 savefile
.FileName
= "Single";
3806 DialogResult result
= savefile
.ShowDialog();
3807 if (result
== DialogResult
.OK
)
3809 AudioOnePicOutputTextBox
.Text
= savefile
.FileName
;
3813 public int SecondsFromHHMMSS(string hhmmss
)
3815 int hh
= int.Parse(hhmmss
.Substring(0, 2));
3816 int mm
= int.Parse(hhmmss
.Substring(3, 2));
3817 int ss
= int.Parse(hhmmss
.Substring(6, 2));
3818 return hh
* 3600 + mm
* 60 + ss
;
3821 private void AudioOnePicButton_Click(object sender
, EventArgs e
)
3823 if (!File
.Exists(AudioPicTextBox
.Text
))
3825 ShowErrorMessage("请选择图片文件");
3827 else if (!File
.Exists(AudioPicAudioTextBox
.Text
))
3829 ShowErrorMessage("请选择音频文件");
3831 else if (AudioOnePicOutputTextBox
.Text
== "")
3833 ShowErrorMessage("请选择输出文件");
3837 System
.Drawing
.Image img
= System
.Drawing
.Image
.FromFile(AudioPicTextBox
.Text
);
3838 // if not even number, chop 1 pixel out
3839 int newWidth
= (img
.Width
% 2 == 0 ? img
.Width
: img
.Width
- 1);
3840 int newHeight
= (img
.Height
% 2 == 0 ? img
.Height
: img
.Height
- 1);
3842 if (img
.Width
% 2 != 0 || img
.Height
% 2 != 0)
3844 Bitmap bmp
= new Bitmap(img
);
3845 cropArea
= new Rectangle(0, 0, newWidth
, newHeight
);
3846 img
= (Image
)bmp
.Clone(cropArea
, bmp
.PixelFormat
);
3849 //if (img.Width % 2 != 0 || img.Height % 2 != 0)
3851 // MessageBox.Show("图片的长和宽必须是偶数。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3855 //if (img.RawFormat.Equals(ImageFormat.Jpeg))
3857 // File.Copy(AudioPicTextBox.Text, tempPic, true);
3861 System
.Drawing
.Imaging
.Encoder ImageEncoder
= System
.Drawing
.Imaging
.Encoder
.Quality
;
3862 EncoderParameter ep
= new EncoderParameter(ImageEncoder
, 100L);
3863 EncoderParameters eps
= new EncoderParameters(1);
3864 ImageCodecInfo ImageCoderType
= getImageCoderInfo("image/jpeg");
3866 img
.Save(tempPic
, ImageCoderType
, eps
);
3867 //img.Save(tempPic, ImageFormat.Jpeg);
3870 MediaInfo MI
= new MediaInfo();
3871 MI
.Open(AudioPicAudioTextBox
.Text
);
3872 int seconds
= SecondsFromHHMMSS(MI
.Get(StreamKind
.General
, 0, "Duration/String3"));
3873 string ffPath
= Path
.Combine(workPath
, "ffmpeg.exe");
3874 string neroPath
= Path
.Combine(workPath
, "neroaacenc.exe");
3875 if (AudioCopyCheckBox
.Checked
)
3877 mux
= "\"" + ffPath
+ "\" -loop 1 -r " + OnePicFPSNum
.Value
.ToString() + " -t " + seconds
.ToString() + " -f image2 -i \"" + tempPic
+ "\" -c:v libx264 -crf " + OnePicCRFNum
.Value
.ToString() + " -y SinglePictureVideo.mp4\r\n";
3878 mux
+= "\"" + ffPath
+ "\" -i SinglePictureVideo.mp4 -i \"" + AudioPicAudioTextBox
.Text
+ "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox
.Text
+ "\"\r\n";
3879 mux
+= "del SinglePictureVideo.mp4\r\n";
3884 mux
= "\"" + ffPath
+ "\" -i \"" + AudioPicAudioTextBox
.Text
+ "\" -f wav - |" + neroPath
+ " -br " + OnePicAudioBitrateNum
.Value
.ToString() + "000 -ignorelength -if - -of audio.mp4 -lc\r\n";
3885 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";
3886 mux
+= "\"" + ffPath
+ "\" -i SinglePictureVideo.mp4 -i audio.mp4 -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox
.Text
+ "\"\r\n";
3887 mux
+= "del SinglePictureVideo.mp4\r\ndel audio.mp4\r\n";
3891 string audioPath = AddExt(Path.GetFileName(AudioPicAudioTextBox.Text), "_atmp.mp4");
3892 string videoPath = AddExt(Path.GetFileName(AudioPicAudioTextBox.Text), "_vtmp.mp4");
3893 string picturePath = "c:\\" + Path.GetFileNameWithoutExtension(AudioPicTextBox.Text) + "_tmp.jpg";
3894 if (AudioCopyCheckBox.Checked)
3896 mux = "ffmpeg -loop 1 -r " + AudioOnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + picturePath + "\" -vcodec libx264 -crf 24 -y \"" + videoPath + "\"\r\n";
3897 mux += "ffmpeg -i \"" + videoPath + "\" -i \"" + AudioPicAudioTextBox.Text + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
3898 mux += "del \"" + videoPath + "\"\r\ndel \"" + picturePath + "\"\r\n";
3902 mux = "ffmpeg -i \"" + AudioPicAudioTextBox.Text + "\" -f wav - |neroaacenc -br " + AudioOnePicAudioBitrateNum.Value.ToString() + "000 -ignorelength -if - -of \"" + audioPath + "\" -lc\r\n";
3903 mux += "ffmpeg -loop 1 -r " + AudioOnePicFPSNum.Value.ToString() + " -t " + seconds.ToString() + " -f image2 -i \"" + picturePath + "\" -vcodec libx264 -crf 24 -y \"" + videoPath + "\"\r\n";
3904 mux += "ffmpeg -i \"" + videoPath + "\" -i \"" + audioPath + "\" -c:v copy -c:a copy -y \"" + AudioOnePicOutputTextBox.Text + "\"\r\n";
3905 mux += "del \"" + videoPath + "\"\r\ndel \"" + audioPath + "\"\r\ndel \"" + picturePath + "\"\r\n";
3908 batpath
= Path
.Combine(workPath
, Path
.GetRandomFileName() + ".bat");
3909 File
.WriteAllText(batpath
, mux
, Encoding
.Default
);
3911 Process
.Start(batpath
);
3915 private void txtMI_DragDrop(object sender
, DragEventArgs e
)
3917 MIvideo
= ((System
.Array
)e
.Data
.GetData(DataFormats
.FileDrop
)).GetValue(0).ToString();
3918 MediaInfoTextBox
.Text
= GetMediaInfoString(MIvideo
);
3921 private void txtMI_DragEnter(object sender
, DragEventArgs e
)
3923 if (e
.Data
.GetDataPresent(DataFormats
.FileDrop
))
3924 e
.Effect
= DragDropEffects
.Link
;
3925 else e
.Effect
= DragDropEffects
.None
;
3928 private void AudioPicAudioTextBox_TextChanged(object sender
, EventArgs e
)
3930 if (File
.Exists(AudioPicAudioTextBox
.Text
.ToString()))
3932 AudioOnePicOutputTextBox
.Text
= Util
.ChangeExt(AudioPicAudioTextBox
.Text
, "_SP.flv");
3939 /// <param name="ImageCoderType">编码类型</param>
3940 /// <returns>ImageCodecInfo</returns>
3941 private ImageCodecInfo
getImageCoderInfo(string ImageCoderType
)
3943 ImageCodecInfo
[] coderTypeArray
= ImageCodecInfo
.GetImageEncoders();
3944 foreach (ImageCodecInfo coderType
in coderTypeArray
)
3946 if (coderType
.MimeType
.Equals(ImageCoderType
))
3956 private void BlackVideoButton_Click(object sender
, EventArgs e
)
3958 openFileDialog1
.Filter
= "FLV视频(*.flv)|*.flv";
3959 DialogResult result
= openFileDialog1
.ShowDialog();
3960 if (result
== DialogResult
.OK
)
3962 BlackVideoTextBox
.Text
= openFileDialog1
.FileName
;
3966 private void BlackOutputButton_Click(object sender
, EventArgs e
)
3968 SaveFileDialog savefile
= new SaveFileDialog();
3969 savefile
.Filter
= "FLV视频(*.flv)|*.flv";
3970 DialogResult result
= savefile
.ShowDialog();
3971 if (result
== DialogResult
.OK
)
3973 BlackOutputTextBox
.Text
= savefile
.FileName
;
3977 private void BlackPicButton_Click(object sender
, EventArgs e
)
3979 openFileDialog1
.Filter
= "图片(*.jpg;*.jpeg;*.png;*.bmp;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件(*.*)|*.*";
3980 DialogResult result
= openFileDialog1
.ShowDialog();
3981 if (result
== DialogResult
.OK
)
3983 BlackPicTextBox
.Text
= openFileDialog1
.FileName
;
3987 private void BlackStartButton_Click(object sender
, EventArgs e
)
3990 if (!File
.Exists(BlackVideoTextBox
.Text
) || Path
.GetExtension(BlackVideoTextBox
.Text
) != ".flv")
3992 ShowErrorMessage("请选择FLV视频文件");
3996 MediaInfo MI
= new MediaInfo();
3997 MI
.Open(BlackVideoTextBox
.Text
);
3998 double videobitrate
= double.Parse(MI
.Get(StreamKind
.General
, 0, "BitRate"));
3999 double targetBitrate
= (double)BlackBitrateNum
.Value
;
4001 if (!File
.Exists(BlackPicTextBox
.Text
) && BlackNoPicCheckBox
.Checked
== false)
4003 ShowErrorMessage("请选择图片文件或勾选使用黑屏");
4006 if (BlackOutputTextBox
.Text
== "")
4008 ShowErrorMessage("请选择输出文件");
4012 if (videobitrate
< 1000000)
4014 ShowInfoMessage("此视频不需要后黑。");
4017 if (videobitrate
> 5000000)
4019 ShowInfoMessage("此视频码率过大,请先压制再后黑。");
4024 int videoWidth
= int.Parse(MI
.Get(StreamKind
.Video
, 0, "Width"));
4025 int videoHeight
= int.Parse(MI
.Get(StreamKind
.Video
, 0, "Height"));
4026 if (BlackNoPicCheckBox
.Checked
)
4028 Bitmap bm
= new Bitmap(videoWidth
, videoHeight
);
4029 Graphics g
= Graphics
.FromImage(bm
);
4030 //g.FillRectangle(Brushes.White, new Rectangle(0, 0, 800, 600));
4031 g
.Clear(Color
.Black
);
4032 bm
.Save(tempPic
, ImageFormat
.Jpeg
);
4038 System
.Drawing
.Image img
= System
.Drawing
.Image
.FromFile(BlackPicTextBox
.Text
);
4039 int sourceWidth
= img
.Width
;
4040 int sourceHeight
= img
.Height
;
4041 if (img
.Width
% 2 != 0 || img
.Height
% 2 != 0)
4043 ShowErrorMessage("图片的长和宽必须都是偶数。");
4047 if (img
.Width
!= videoWidth
|| img
.Height
!= videoHeight
)
4049 ShowErrorMessage("图片的长和宽和视频不一致。");
4053 if (img
.RawFormat
.Equals(ImageFormat
.Jpeg
))
4055 File
.Copy(BlackPicTextBox
.Text
, tempPic
, true);
4059 System
.Drawing
.Imaging
.Encoder ImageEncoder
= System
.Drawing
.Imaging
.Encoder
.Quality
;
4060 EncoderParameter ep
= new EncoderParameter(ImageEncoder
, 100L);
4061 EncoderParameters eps
= new EncoderParameters(1);
4062 ImageCodecInfo ImageCoderType
= getImageCoderInfo("image/jpeg");
4064 img
.Save(tempPic
, ImageCoderType
, eps
);
4065 //img.Save(tempPic, ImageFormat.Jpeg);
4068 int blackSecond
= 300;
4070 if (BlackSecondComboBox
.Text
== "auto")
4072 int seconds
= SecondsFromHHMMSS(MI
.Get(StreamKind
.General
, 0, "Duration/String3"));
4073 double s
= videobitrate
/ 1000.0 * (double)seconds
/ targetBitrate
- (double)seconds
;
4074 blackSecond
= (int)s
;
4075 BlackSecondComboBox
.Text
= blackSecond
.ToString();
4079 blackSecond
= int.Parse(Regex
.Replace(BlackSecondComboBox
.Text
.ToString(), @"\D", "")); //排除除数字外的所有字符
4083 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";
4084 mux
+= string.Format("\"{0}\\flvbind\" \"{1}\" \"{2}\" black.flv\r\n", workPath
, BlackOutputTextBox
.Text
, BlackVideoTextBox
.Text
);
4085 mux
+= "del black.flv\r\n";
4087 batpath
= Path
.Combine(workPath
, Path
.GetRandomFileName() + ".bat");
4088 File
.WriteAllText(batpath
, mux
, Encoding
.Default
);
4090 Process
.Start(batpath
);
4093 private void BlackVideoTextBox_TextChanged(object sender
, EventArgs e
)
4095 string path
= BlackVideoTextBox
.Text
;
4096 if (File
.Exists(path
))
4098 BlackOutputTextBox
.Text
= Util
.ChangeExt(path
, "_black.flv");
4104 private void BlackNoPicCheckBox_CheckedChanged(object sender
, EventArgs e
)
4106 BlackPicTextBox
.Enabled
= !BlackNoPicCheckBox
.Checked
;
4107 BlackPicButton
.Enabled
= !BlackNoPicCheckBox
.Checked
;
4110 private void BlackSecondComboBox_SelectedIndexChanged(object sender
, EventArgs e
)
4112 if (BlackSecondComboBox
.Text
!= "auto")
4114 BlackBitrateNum
.Enabled
= false;
4118 BlackBitrateNum
.Enabled
= true;
4122 private void SetDefaultButton_Click(object sender
, EventArgs e
)
4124 DialogResult dr
= ShowQuestion(string.Format("是否将所有界面参数恢复到默认设置?"), "提示");
4125 if (dr
== DialogResult
.Yes
)
4128 ShowInfoMessage("恢复默认设置完成!");
4133 private void MediaInfoTextBox_KeyDown(object sender
, KeyEventArgs e
)
4135 if (e
.Modifiers
== Keys
.Control
&& e
.KeyCode
== Keys
.A
)
4137 ((TextBox
)sender
).SelectAll();
4141 private void AVSScriptTextBox_KeyDown(object sender
, KeyEventArgs e
)
4143 if (e
.Modifiers
== Keys
.Control
&& e
.KeyCode
== Keys
.A
)
4145 ((TextBox
)sender
).SelectAll();
4149 private void x264CustomParameterTextBox_KeyDown(object sender
, KeyEventArgs e
)
4151 if (e
.Modifiers
== Keys
.Control
&& e
.KeyCode
== Keys
.A
)
4153 ((TextBox
)sender
).SelectAll();
4159 public delegate bool CheckUpadateDelegate(out DateTime newdate
, out bool isFullUpdate
);
4161 public void CheckUpdateCallBack(IAsyncResult ar
)
4165 AsyncResult result
= (AsyncResult
)ar
;
4166 CheckUpadateDelegate func
= (CheckUpadateDelegate
)result
.AsyncDelegate
;
4170 bool needUpdate
= func
.EndInvoke(out NewDate
, out isFullUpdate
, ar
);
4175 DialogResult dr
= ShowQuestion(string.Format("新版已于{0}发布,是否前往官网下载?", NewDate
.ToString("yyyy-M-d")), "喜大普奔");
4176 if (dr
== DialogResult
.Yes
)
4178 Process
.Start("http://www.maruko.in/");
4183 DialogResult dr
= ShowQuestion(string.Format("新版已于{0}发布,是否自动升级?(文件约1.5MB)", NewDate
.ToString("yyyy-M-d")), "喜大普奔");
4184 if (dr
== DialogResult
.Yes
)
4186 FormUpdater formUpdater
= new FormUpdater(startpath
, NewDate
.ToString());
4187 formUpdater
.ShowDialog(this);
4193 //MessageBox.Show("已经是最新版了喵!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
4196 catch (Exception
) { }
4199 public bool CheckUpdate(out DateTime NewDate
, out bool isFullUpdate
)
4201 WebRequest request
= WebRequest
.Create("http://mtbftest.sinaapp.com/version.php");
4202 WebResponse wrs
= request
.GetResponse();
4203 // read the response ...
4204 Stream dataStream
= wrs
.GetResponseStream();
4205 // Open the stream using a StreamReader for easy access.
4206 StreamReader reader
= new StreamReader(dataStream
);
4207 // Read the content.
4208 string responseFromServer
= reader
.ReadToEnd();
4209 Regex dateReg
= new Regex(@"Date20\S+Date");
4210 Regex VersionReg
= new Regex(@"Version\d+Version");
4211 Match dateMatch
= dateReg
.Match(responseFromServer
);
4212 Match versionMatch
= VersionReg
.Match(responseFromServer
);
4213 NewDate
= DateTime
.Parse("1990-03-08");
4214 isFullUpdate
= false;
4215 if (dateMatch
.Success
)
4217 string date
= dateMatch
.Value
.Replace("Date", "");
4218 string version
= versionMatch
.Value
.Replace("Version", "");
4219 NewDate
= DateTime
.Parse(date
);
4220 int NewVersion
= int.Parse(version
);
4221 int s
= DateTime
.Compare(NewDate
, ReleaseDate
);
4223 int currentVersion
= Assembly
.GetExecutingAssembly().GetName().Version
.Minor
;
4224 if (NewVersion
> currentVersion
)
4226 isFullUpdate
= true;
4230 isFullUpdate
= false;
4232 //DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
4233 if (s
== 1) //NewDate is later than ReleaseDate
4245 private void CheckUpdateButton_Click(object sender
, EventArgs e
)
4247 if (Util
.IsConnectInternet())
4249 WebRequest request
= WebRequest
.Create("http://mtbftest.sinaapp.com/version.php");
4250 request
.Credentials
= CredentialCache
.DefaultCredentials
;
4251 // Get the response.
4252 request
.BeginGetResponse(new AsyncCallback(OnResponse
), request
);
4256 ShowErrorMessage("这台电脑似乎没有联网呢~");
4260 protected void OnResponse(IAsyncResult ar
)
4262 WebRequest wrq
= (WebRequest
)ar
.AsyncState
;
4263 WebResponse wrs
= wrq
.EndGetResponse(ar
);
4264 // read the response ...
4265 Stream dataStream
= wrs
.GetResponseStream();
4266 // Open the stream using a StreamReader for easy access.
4267 StreamReader reader
= new StreamReader(dataStream
);
4268 // Read the content.
4269 string responseFromServer
= reader
.ReadToEnd();
4270 Regex dateReg
= new Regex(@"Date20\S+Date");
4271 Regex VersionReg
= new Regex(@"Version\d+Version");
4272 Match dateMatch
= dateReg
.Match(responseFromServer
);
4273 Match versionMatch
= VersionReg
.Match(responseFromServer
);
4274 DateTime NewDate
= DateTime
.Parse("1990-03-08");
4275 bool isFullUpdate
= false;
4276 if (dateMatch
.Success
)
4278 string date
= dateMatch
.Value
.Replace("Date", "");
4279 string version
= versionMatch
.Value
.Replace("Version", "");
4280 NewDate
= DateTime
.Parse(date
);
4281 int NewVersion
= int.Parse(version
);
4282 int s
= DateTime
.Compare(NewDate
, ReleaseDate
);
4284 int currentVersion
= System
.Reflection
.Assembly
.GetExecutingAssembly().GetName().Version
.Minor
;
4285 if (NewVersion
> currentVersion
)
4287 isFullUpdate
= true;
4291 isFullUpdate
= false;
4293 //DateTime CompileDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //获得程序编译时间
4294 if (s
== 1) //NewDate is later than ReleaseDate
4298 DialogResult dr
= ShowQuestion(string.Format("新版已于{0}发布,是否前往官网下载?", NewDate
.ToString("yyyy-M-d")), "喜大普奔");
4299 if (dr
== DialogResult
.Yes
)
4301 Process
.Start("http://www.maruko.in/");
4306 DialogResult dr
= ShowQuestion(string.Format("新版已于{0}发布,是否自动升级?(文件约1.5MB)", NewDate
.ToString("yyyy-M-d")), "喜大普奔");
4307 if (dr
== DialogResult
.Yes
)
4309 FormUpdater formUpdater
= new FormUpdater(startpath
, date
);
4310 formUpdater
.ShowDialog(this);
4316 ShowInfoMessage("已经是最新版了喵!");
4321 ShowInfoMessage("啊咧~似乎未能获取版本信息,请点击软件主页按钮查看最新版本。");
4325 #endregion CheckUpdate
4327 private void x264ShutdownCheckBox_CheckedChanged(object sender
, EventArgs e
)
4329 shutdownState
= x264ShutdownCheckBox
.Checked
;
4332 private void TrayModeCheckBox_CheckedChanged(object sender
, EventArgs e
)
4334 trayMode
= TrayModeCheckBox
.Checked
;
4337 private void ReleaseDatelabel_DoubleClick(object sender
, EventArgs e
)
4339 SplashForm sf
= new SplashForm();
4344 private void AudioCopyCheckBox_CheckedChanged(object sender
, EventArgs e
)
4346 OnePicAudioBitrateNum
.Enabled
= !AudioCopyCheckBox
.Checked
;
4349 private void HelpTextBox_LinkClicked(object sender
, LinkClickedEventArgs e
)
4351 Process
.Start(e
.LinkText
);
4354 private void labelAudio_Click(object sender
, EventArgs e
)
4356 tabControl
.SelectedIndex
= 1;
4359 private void SetupAVSPlayerButton_Click(object sender
, EventArgs e
)
4361 openFileDialog1
.Filter
= "程序(*.exe)|*.exe|所有文件(*.*)|*.*";
4362 DialogResult result
= openFileDialog1
.ShowDialog();
4363 if (result
== DialogResult
.OK
)
4365 SetupPlayerTextBox
.Text
= openFileDialog1
.FileName
;
4369 private void AVSAddFilterButton_Click(object sender
, EventArgs e
)
4371 string vsfilterDLLPath
= Path
.Combine(workPath
, @"avs\plugins\" + AVSFilterComboBox
.Text
);
4372 string text
= "LoadPlugin(\"" + vsfilterDLLPath
+ "\")" + "\r\n";
4373 AVSScriptTextBox
.Text
= text
+ AVSScriptTextBox
.Text
;
4376 private void AudioJoinButton_Click(object sender
, EventArgs e
)
4378 if (AudioListBox
.Items
.Count
== 0)
4380 ShowErrorMessage("请输入文件!");
4383 else if (AudioOutputTextBox
.Text
== "")
4385 ShowErrorMessage("请选择输出文件");
4388 StringBuilder sb
= new StringBuilder();
4390 string ext
= Path
.GetExtension(AudioListBox
.Items
[0].ToString());
4391 string finish
= Util
.ChangeExt(AudioOutputTextBox
.Text
, ext
);
4392 for (int i
= 0; i
< this.AudioListBox
.Items
.Count
; i
++)
4394 if (Path
.GetExtension(AudioListBox
.Items
[i
].ToString()) != ext
)
4396 ShowErrorMessage("只允许合并相同格式文件。");
4399 sb
.AppendLine("file '" + AudioListBox
.Items
[i
].ToString() + "'");
4400 File
.WriteAllText("concat.txt", sb
.ToString());
4401 ffmpeg
= "\"" + workPath
+ "\\ffmpeg.exe\" -f concat -i concat.txt -y -c copy " + finish
;
4403 ffmpeg
+= "\r\ncmd";
4404 batpath
= workPath
+ "\\concat.bat";
4405 File
.WriteAllText(batpath
, ffmpeg
, Encoding
.Default
);
4407 Process
.Start(batpath
);
4412 private void tabControl_DragOver(object sender
, DragEventArgs e
)
4414 if (e
.Data
.GetDataPresent(DataFormats
.FileDrop
))
4416 e
.Effect
= DragDropEffects
.All
;
4417 Point pt
= new Point(e
.X
+ 2, e
.Y
+ 2);
4418 pt
= PointToClient(pt
);
4419 int pi
= GetTabPageByTab(pt
);
4422 tabControl
.SelectedIndex
= pi
;
4425 else e
.Effect
= DragDropEffects
.None
;
4429 /// Finds the TabPage whose tab is contains the given point.
4431 /// <param name="pt">The point (given in client coordinates) to look for a TabPage.</param>
4432 /// <returns>The TabPage whose tab is at the given point (null if there isn't one).</returns>
4433 private int GetTabPageByTab(Point pt
)
4437 for (int i
= 0; i
< tabControl
.TabPages
.Count
; i
++)
4439 Rectangle a
= tabControl
.GetTabRect(i
);
4441 if (tabControl
.GetTabRect(i
).Contains(pt
))
4443 tp
= tabControl
.TabPages
[i
];
4451 private void MainForm_KeyDown(object sender
, KeyEventArgs e
)
4453 if (e
.Modifiers
== Keys
.Control
&& e
.KeyCode
== Keys
.D1
)
4455 tabControl
.SelectedIndex
= 0;
4457 if (e
.Modifiers
== Keys
.Control
&& e
.KeyCode
== Keys
.D2
)
4459 tabControl
.SelectedIndex
= 1;
4461 if (e
.Modifiers
== Keys
.Control
&& e
.KeyCode
== Keys
.D3
)
4463 tabControl
.SelectedIndex
= 2;
4465 if (e
.Modifiers
== Keys
.Control
&& e
.KeyCode
== Keys
.D4
)
4467 tabControl
.SelectedIndex
= 3;
4469 if (e
.Modifiers
== Keys
.Control
&& e
.KeyCode
== Keys
.D5
)
4471 tabControl
.SelectedIndex
= 4;
4473 if (e
.Modifiers
== Keys
.Control
&& e
.KeyCode
== Keys
.D6
)
4475 tabControl
.SelectedIndex
= 5;
4477 if (e
.Modifiers
== Keys
.Control
&& e
.KeyCode
== Keys
.D7
)
4479 tabControl
.SelectedIndex
= 6;
4481 if (e
.Modifiers
== Keys
.Control
&& e
.KeyCode
== Keys
.D8
)
4483 tabControl
.SelectedIndex
= 7;
4485 if (e
.Modifiers
== Keys
.Control
&& e
.KeyCode
== Keys
.D9
)
4487 tabControl
.SelectedIndex
= 8;
4491 #endregion TabControl
4493 private void gmkvextractguibButton_Click(object sender
, EventArgs e
)
4495 string path
= workPath
+ "\\gMKVExtractGUI.exe";
4496 if (File
.Exists(path
))
4497 Process
.Start(path
);
4499 ShowErrorMessage("请检查\r\n\r\n" + path
+ "\r\n\r\n是否存在", "未找到程序!");
4502 private void FeedbackButton_Click(object sender
, EventArgs e
)
4504 FeedbackForm ff
= new FeedbackForm();
4508 private void x264SubTextBox_DoubleClick(object sender
, EventArgs e
)
4510 x264SubTextBox
.Clear();
4513 private void RotateButton_Click(object sender
, EventArgs e
)
4515 if (namevideo4
== "")
4517 ShowErrorMessage("请选择视频文件");
4519 else if (nameout5
== "")
4521 ShowErrorMessage("请选择输出文件");
4525 clip
= string.Format(@"""{0}\ffmpeg.exe"" -i ""{1}"" -vf ""transpose={2}"" -y ""{3}""",
4526 workPath
, namevideo4
, TransposeComboBox
.SelectedIndex
, nameout5
) + Environment
.NewLine
+ "cmd";
4527 batpath
= workPath
+ "\\clip.bat";
4528 File
.WriteAllText(batpath
, clip
, Encoding
.Default
);
4529 Process
.Start(batpath
);
4533 private void AudioPresetComboBox_SelectedIndexChanged(object sender
, EventArgs e
)
4535 XElement x
= xdoc
.Element("root").Element("Audio").Element("AudioEncoder").Element(AudioEncoderComboBox
.Text
).Elements()
4536 .Where(_
=> _
.Attribute("Name").Value
== AudioPresetComboBox
.Text
).First();
4537 AudioCustomParameterTextBox
.Text
= x
.Value
;
4540 private void lbAuto_DrawItem(object sender
, DrawItemEventArgs e
)
4542 if (e
.Index
< 0 || e
.Index
>= 65535)
4546 SolidBrush BlueBrush
= new SolidBrush(Color
.Blue
);
4547 SolidBrush BlackBrush
= new SolidBrush(Color
.Black
);
4548 Color vColor
= Color
.Black
;
4549 string input
= lbAuto
.Items
[e
.Index
].ToString();
4550 if (!string.IsNullOrEmpty(GetSubtitlePath(input
)))
4552 e
.Graphics
.DrawString(Convert
.ToString(lbAuto
.Items
[e
.Index
]), e
.Font
, BlueBrush
, e
.Bounds
);
4556 e
.Graphics
.DrawString(Convert
.ToString(lbAuto
.Items
[e
.Index
]), e
.Font
, BlackBrush
, e
.Bounds
);
4560 private string GetSubtitlePath(string videoPath
)
4564 string[] subExt
= { ".ass", ".ssa", ".srt" }
;
4565 if (x264BatchSubSpecialLanguage
.Text
!= "none")
4566 splang
= "." + x264BatchSubSpecialLanguage
.Text
;
4567 foreach (string ext
in subExt
)
4569 if (File
.Exists(videoPath
.Remove(videoPath
.LastIndexOf(".")) + splang
+ ext
))
4571 sub
= videoPath
.Remove(videoPath
.LastIndexOf(".")) + splang
+ ext
;
4578 private void x264ExeComboBox_SelectedIndexChanged(object sender
, EventArgs e
)
4580 if (x264ExeComboBox
.SelectedIndex
== -1)
4583 if (x264ExeComboBox
.SelectedItem
.ToString().ToLower().Contains("x265"))
4585 x264SubTextBox
.Text
= string.Empty
;
4586 x264SubTextBox
.Enabled
= false;
4587 x264SubBtn
.Enabled
= false;
4588 x264BatchSubCheckBox
.Enabled
= false;
4589 x264BatchSubSpecialLanguage
.Enabled
= false;
4590 x264DemuxerComboBox
.Enabled
= false;
4591 VideoBatchFormatComboBox
.Text
= "mp4";
4592 VideoBatchFormatComboBox
.Enabled
= false;
4596 x264SubTextBox
.Enabled
= true;
4597 x264SubBtn
.Enabled
= true;
4598 x264BatchSubCheckBox
.Enabled
= true;
4599 x264BatchSubSpecialLanguage
.Enabled
= true;
4600 x264DemuxerComboBox
.Enabled
= true;
4601 VideoBatchFormatComboBox
.Enabled
= true;
4607 public String
GetCurrentDirectory()
4609 return Path
.GetDirectoryName(Assembly
.GetExecutingAssembly().Location
);
4612 public static void ShowErrorMessage(String argMessage
)
4614 MessageBox
.Show(argMessage
, "错误!", MessageBoxButtons
.OK
, MessageBoxIcon
.Warning
);
4617 public static void ShowErrorMessage(String argMessage
, String argTitle
)
4619 MessageBox
.Show(argMessage
, argTitle
, MessageBoxButtons
.OK
, MessageBoxIcon
.Warning
);
4622 public static void ShowWarningMessage(String argMessage
)
4624 MessageBox
.Show(argMessage
, "警告!", MessageBoxButtons
.OK
, MessageBoxIcon
.Warning
);
4627 public static void ShowWarningMessage(String argMessage
, String argTitle
)
4629 MessageBox
.Show(argMessage
, argTitle
, MessageBoxButtons
.OK
, MessageBoxIcon
.Warning
);
4632 public static void ShowInfoMessage(String argMessage
)
4634 MessageBox
.Show(argMessage
, "提示!", MessageBoxButtons
.OK
, MessageBoxIcon
.Information
);
4637 public static void ShowInfoMessage(String argMessage
, String argTitle
)
4639 MessageBox
.Show(argMessage
, argTitle
, MessageBoxButtons
.OK
, MessageBoxIcon
.Information
);
4642 public static DialogResult
ShowQuestion(String argQuestion
, String argTitle
)
4644 return MessageBox
.Show(argQuestion
, argTitle
, MessageBoxButtons
.YesNo
, MessageBoxIcon
.Question
);
4649 private void audioDeleteBt_Click(object sender
, EventArgs e
)
4651 if (ShowQuestion("确定要删除这条预设参数?", "提示") == DialogResult
.Yes
)
4655 var xls
= xdoc
.Element("root").Element("Audio").Element("AudioEncoder").Element(AudioEncoderComboBox
.Text
).Elements();
4656 foreach (var item
in xls
)
4658 if (item
.Attribute("Name").Value
== AudioPresetComboBox
.Text
)
4661 xdoc
.Save("preset.xml");
4664 catch (Exception ex
)
4666 ShowErrorMessage("删除失败! Reason: " + ex
.Message
);
4671 private void audioAddBt_Click(object sender
, EventArgs e
)
4675 string aPresetName
= InputBox
.Show("请输入这个预设名称", "请为预置配置命名", "新预置名称");
4676 if (!string.IsNullOrEmpty(aPresetName
))
4678 var xl
= xdoc
.Element("root").Element("Audio").Element("AudioEncoder").Element(AudioEncoderComboBox
.Text
);
4679 XElement xelnew
= new XElement("Parameter", AudioCustomParameterTextBox
.Text
,
4680 new XAttribute("Name", aPresetName
));
4681 foreach (var item
in xl
.Elements())
4683 if (item
.Attribute("Name").Value
== aPresetName
)
4685 ShowErrorMessage("预设名称已经存在", "预设名称重复");
4690 xdoc
.Save("preset.xml");
4692 AudioPresetComboBox
.SelectedIndex
= AudioPresetComboBox
.FindString(aPresetName
);
4695 catch (Exception ex
)
4697 ShowErrorMessage("添加失败! Reason: " + ex
.Message
);
4701 private void x265CheckBox_Click(object sender
, EventArgs e
)
4703 if (ShowQuestion("你必须重新启动小丸工具箱才能使设置的生效 是否现在重新启动?", "需要重新启动") == DialogResult
.Yes
)
4704 Application
.Restart();