3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Collections;
\r
10 using System.Windows.Forms;
\r
11 using System.Globalization;
\r
13 using System.Drawing;
\r
14 using System.Diagnostics;
\r
15 using System.Text.RegularExpressions;
\r
17 namespace Handbrake.Functions
\r
24 /// Update the presets.dat file with the latest version of HandBrak's presets from the CLI
\r
26 public void grabCLIPresets()
\r
28 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
\r
29 string presetsPath = Path.Combine(Application.StartupPath, "presets.dat");
\r
31 string strCmdLine = String.Format(@"cmd /c """"{0}"" --preset-list >""{1}"" 2>&1""", handbrakeCLIPath, presetsPath);
\r
33 ProcessStartInfo hbGetPresets = new ProcessStartInfo("CMD.exe", strCmdLine);
\r
34 hbGetPresets.WindowStyle = ProcessWindowStyle.Hidden;
\r
36 Process hbproc = Process.Start(hbGetPresets);
\r
37 hbproc.WaitForExit();
\r
42 /// This function takes in a Query which has been parsed by QueryParser and
\r
43 /// set's all the GUI widgets correctly.
\r
45 /// <param name="mainWindow"></param>
\r
46 /// <param name="presetQuery">The Parsed CLI Query</param>
\r
47 /// <param name="name">Name of the preset</param>
\r
48 public void presetLoader(frmMain mainWindow, Functions.QueryParser presetQuery, string name)
\r
50 // ---------------------------
\r
52 // ---------------------------
\r
56 // Reset some vaules to stock first to prevent errors.
\r
57 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
59 // Now load all the new settings onto the main window
\r
60 mainWindow.drp_dvdtitle.Text = "Automatic";
\r
61 mainWindow.drop_chapterStart.Text = "Auto";
\r
62 mainWindow.drop_chapterFinish.Text = "Auto";
\r
64 if (presetQuery.Format != null)
\r
66 string destination = mainWindow.text_destination.Text;
\r
67 destination = destination.Replace(".mp4", "." + presetQuery.Format);
\r
68 destination = destination.Replace(".m4v", "." + presetQuery.Format);
\r
69 destination = destination.Replace(".avi", "." + presetQuery.Format);
\r
70 destination = destination.Replace(".mkv", "." + presetQuery.Format);
\r
71 destination = destination.Replace(".ogm", "." + presetQuery.Format);
\r
72 mainWindow.text_destination.Text = destination;
\r
80 mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;
\r
82 if (presetQuery.Format != null)
\r
84 if (presetQuery.Format == "mp4")
\r
85 mainWindow.drop_format.SelectedIndex = 0;
\r
86 else if (presetQuery.Format == "m4v")
\r
87 mainWindow.drop_format.SelectedIndex = 1;
\r
88 else if (presetQuery.Format == "mkv")
\r
89 mainWindow.drop_format.SelectedIndex = 2;
\r
90 else if (presetQuery.Format == "avi")
\r
91 mainWindow.drop_format.SelectedIndex = 3;
\r
92 else if (presetQuery.Format == "ogm")
\r
93 mainWindow.drop_format.SelectedIndex = 4;
\r
96 if (presetQuery.IpodAtom == true)
\r
97 mainWindow.check_iPodAtom.CheckState = CheckState.Checked;
\r
99 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
101 if (presetQuery.OptimizeMP4 == true)
\r
102 mainWindow.check_optimiseMP4.CheckState = CheckState.Checked;
\r
104 mainWindow.check_optimiseMP4.CheckState = CheckState.Unchecked;
\r
108 // Picture Settings Tab
\r
111 if (presetQuery.CropTop == "0" && presetQuery.CropBottom == "0" && presetQuery.CropLeft == "0" && presetQuery.CropRight == "0")
\r
113 mainWindow.drp_crop.SelectedIndex = 2;
\r
115 else if (presetQuery.CropTop != null && presetQuery.CropBottom != null && presetQuery.CropLeft != null && presetQuery.CropRight != null)
\r
117 mainWindow.drp_crop.SelectedIndex = 1;
\r
118 mainWindow.text_top.Text = presetQuery.CropTop;
\r
119 mainWindow.text_bottom.Text = presetQuery.CropBottom;
\r
120 mainWindow.text_left.Text = presetQuery.CropLeft;
\r
121 mainWindow.text_right.Text = presetQuery.CropRight;
\r
125 mainWindow.drp_crop.SelectedIndex = 0;
\r
128 mainWindow.drp_deInterlace_option.Text = presetQuery.DeInterlace;
\r
129 mainWindow.drp_deNoise.Text = presetQuery.DeNoise;
\r
131 if (presetQuery.Decomb == true)
\r
132 mainWindow.check_decomb.CheckState = CheckState.Checked;
\r
134 mainWindow.check_decomb.CheckState = CheckState.Unchecked;
\r
136 if (presetQuery.DeTelecine == true)
\r
137 mainWindow.check_detelecine.CheckState = CheckState.Checked;
\r
139 mainWindow.check_detelecine.CheckState = CheckState.Unchecked;
\r
142 if (presetQuery.DeBlock == true)
\r
143 mainWindow.check_deblock.CheckState = CheckState.Checked;
\r
145 mainWindow.check_deblock.CheckState = CheckState.Unchecked;
\r
148 if (presetQuery.Anamorphic == true)
\r
149 mainWindow.drp_anamorphic.SelectedIndex = 1;
\r
151 mainWindow.drp_anamorphic.SelectedIndex = 0;
\r
153 if (presetQuery.LooseAnamorphic == true)
\r
154 mainWindow.drp_anamorphic.SelectedIndex = 2;
\r
157 if (presetQuery.Anamorphic != true)
\r
158 mainWindow.drp_anamorphic.SelectedIndex = 0;
\r
161 if (presetQuery.Width != 0)
\r
162 mainWindow.text_width.Text = presetQuery.Width.ToString();
\r
165 mainWindow.text_width.Text = "";
\r
168 if (presetQuery.Height != 0)
\r
169 mainWindow.text_height.Text = presetQuery.Height.ToString();
\r
172 mainWindow.text_height.Text = "";
\r
175 if (presetQuery.VFR == true)
\r
176 mainWindow.check_vfr.CheckState = CheckState.Checked;
\r
178 mainWindow.check_vfr.CheckState = CheckState.Unchecked;
\r
181 // Video Settings Tab
\r
183 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;
\r
184 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;
\r
185 mainWindow.slider_videoQuality.Value = presetQuery.VideoQuality;
\r
186 if (mainWindow.slider_videoQuality.Value != 0)
\r
188 int ql = presetQuery.VideoQuality;
\r
189 mainWindow.SliderValue.Text = ql.ToString() + "%";
\r
192 if (presetQuery.TwoPass == true)
\r
193 mainWindow.check_2PassEncode.CheckState = CheckState.Checked;
\r
195 mainWindow.check_2PassEncode.CheckState = CheckState.Unchecked;
\r
197 if (presetQuery.Grayscale == true)
\r
198 mainWindow.check_grayscale.CheckState = CheckState.Checked;
\r
200 mainWindow.check_grayscale.CheckState = CheckState.Unchecked;
\r
202 mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;
\r
204 if (presetQuery.TurboFirstPass == true)
\r
205 mainWindow.check_turbo.CheckState = CheckState.Checked;
\r
207 mainWindow.check_turbo.CheckState = CheckState.Unchecked;
\r
209 if (presetQuery.LargeMP4 == true)
\r
210 mainWindow.check_largeFile.CheckState = CheckState.Checked;
\r
213 mainWindow.check_largeFile.CheckState = CheckState.Unchecked;
\r
214 mainWindow.check_largeFile.BackColor = Color.Transparent;
\r
221 // Chapter Markers Tab
\r
222 #region Chapter Markers
\r
224 if (presetQuery.ChapterMarkers == true)
\r
226 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
227 mainWindow.text_destination.Text = mainWindow.text_destination.Text.Replace(".mp4", ".m4v");
\r
230 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;
\r
234 // Audio Settings Tab
\r
238 if (presetQuery.AudioTrack1 == string.Empty)
\r
239 mainWindow.drp_track1Audio.Text = "Automatic";
\r
241 mainWindow.drp_track1Audio.Text = presetQuery.AudioTrack1;
\r
244 if (presetQuery.AudioEncoder2 != null) // Fix for loading in built in presets. Where 2 encoders but no tracks in the preset.
\r
246 mainWindow.drp_track2Audio.Enabled = true;
\r
247 mainWindow.drp_audsr_2.Enabled = true;
\r
248 mainWindow.drp_audmix_2.Enabled = true;
\r
249 mainWindow.drp_audenc_2.Enabled = true;
\r
250 mainWindow.drp_audbit_2.Enabled = true;
\r
251 mainWindow.drp_audsr_2.Text = "48";
\r
252 if ((presetQuery.AudioTrack2 != null) && (presetQuery.AudioTrack2 != "None"))
\r
253 mainWindow.drp_track2Audio.Text = presetQuery.AudioTrack2;
\r
255 mainWindow.drp_track2Audio.Text = "Automatic";
\r
257 else if (presetQuery.AudioTrack2 == "None")
\r
259 mainWindow.drp_track2Audio.Text = "None";
\r
260 mainWindow.drp_track2Audio.SelectedIndex = 0;
\r
261 mainWindow.drp_audsr_2.Enabled = false;
\r
262 mainWindow.drp_audmix_2.Enabled = false;
\r
263 mainWindow.drp_audenc_2.Enabled = false;
\r
264 mainWindow.drp_audbit_2.Enabled = false;
\r
268 mainWindow.drp_track2Audio.Text = presetQuery.AudioTrack2;
\r
269 mainWindow.drp_audsr_2.Enabled = true;
\r
270 mainWindow.drp_audmix_2.Enabled = true;
\r
271 mainWindow.drp_audenc_2.Enabled = true;
\r
272 mainWindow.drp_audbit_2.Enabled = true;
\r
276 if (presetQuery.AudioTrack3 == "None")
\r
278 mainWindow.drp_track3Audio.SelectedIndex = 0;
\r
279 mainWindow.drp_audsr_3.Enabled = false;
\r
280 mainWindow.drp_audmix_3.Enabled = false;
\r
281 mainWindow.drp_audenc_3.Enabled = false;
\r
282 mainWindow.drp_audbit_3.Enabled = false;
\r
283 mainWindow.trackBar3.Enabled = false;
\r
285 mainWindow.drp_track3Audio.Text = "None";
\r
286 mainWindow.drp_audsr_3.Text = "";
\r
287 mainWindow.drp_audmix_3.Text = "Automatic";
\r
288 mainWindow.drp_audenc_3.Text = "";
\r
289 mainWindow.drp_audbit_3.Text = "";
\r
290 mainWindow.trackBar3.Value = 0;
\r
295 mainWindow.drp_track3Audio.Text = presetQuery.AudioTrack3;
\r
296 mainWindow.drp_audsr_3.Enabled = true;
\r
297 mainWindow.drp_audmix_3.Enabled = true;
\r
298 mainWindow.drp_audenc_3.Enabled = true;
\r
299 mainWindow.drp_audbit_3.Enabled = true;
\r
300 mainWindow.trackBar3.Enabled = true;
\r
304 if (presetQuery.AudioTrack4 == "None")
\r
306 mainWindow.drp_track4Audio.SelectedIndex = 0;
\r
307 mainWindow.drp_audsr_4.Enabled = false;
\r
308 mainWindow.drp_audmix_4.Enabled = false;
\r
309 mainWindow.drp_audenc_4.Enabled = false;
\r
310 mainWindow.drp_audbit_4.Enabled = false;
\r
311 mainWindow.trackBar4.Enabled = false;
\r
313 mainWindow.drp_track4Audio.Text = "None";
\r
314 mainWindow.drp_audsr_4.Text = "";
\r
315 mainWindow.drp_audmix_4.Text = "Automatic";
\r
316 mainWindow.drp_audenc_4.Text = "";
\r
317 mainWindow.drp_audbit_4.Text = "";
\r
318 mainWindow.trackBar4.Value = 0;
\r
322 mainWindow.drp_track4Audio.Text = presetQuery.AudioTrack4;
\r
323 mainWindow.drp_audsr_4.Enabled = true;
\r
324 mainWindow.drp_audmix_4.Enabled = true;
\r
325 mainWindow.drp_audenc_4.Enabled = true;
\r
326 mainWindow.drp_audbit_4.Enabled = true;
\r
327 mainWindow.trackBar4.Enabled = true;
\r
330 // Now lets start setting stuff
\r
331 if (presetQuery.AudioEncoder1 != null)
\r
332 mainWindow.drp_audenc_1.Text = presetQuery.AudioEncoder1;
\r
333 mainWindow.drp_audenc_2.Text = presetQuery.AudioEncoder2;
\r
334 mainWindow.drp_audenc_3.Text = presetQuery.AudioEncoder3;
\r
335 mainWindow.drp_audenc_4.Text = presetQuery.AudioEncoder4;
\r
337 if (presetQuery.AudioBitrate1 != null)
\r
338 mainWindow.drp_audbit_1.Text = presetQuery.AudioBitrate1;
\r
339 mainWindow.drp_audbit_2.Text = presetQuery.AudioBitrate2;
\r
340 mainWindow.drp_audbit_3.Text = presetQuery.AudioBitrate4;
\r
341 mainWindow.drp_audbit_3.Text = presetQuery.AudioBitrate4;
\r
343 if (presetQuery.AudioSamplerate1 != null)
\r
344 mainWindow.drp_audsr_1.Text = presetQuery.AudioSamplerate1;
\r
345 mainWindow.drp_audsr_2.Text = presetQuery.AudioSamplerate2;
\r
346 mainWindow.drp_audsr_3.Text = presetQuery.AudioSamplerate3;
\r
347 mainWindow.drp_audsr_4.Text = presetQuery.AudioSamplerate4;
\r
349 mainWindow.drp_audmix_1.Text = presetQuery.AudioTrackMix1;
\r
350 mainWindow.drp_audmix_2.Text = presetQuery.AudioTrackMix2;
\r
351 mainWindow.drp_audmix_3.Text = presetQuery.AudioTrackMix3;
\r
352 mainWindow.drp_audmix_4.Text = presetQuery.AudioTrackMix4;
\r
355 // Dynamic Range Compression (Should be a float but we use double for ease)
\r
357 double actualValue = 0;
\r
359 value = presetQuery.DRC1;
\r
361 value = value - 10;
\r
362 mainWindow.trackBar1.Value = int.Parse(value.ToString());
\r
363 actualValue = presetQuery.DRC1 / 10;
\r
364 mainWindow.lbl_drc1.Text = actualValue.ToString();
\r
366 value = presetQuery.DRC2;
\r
368 value = value - 10;
\r
369 mainWindow.trackBar2.Value = int.Parse(value.ToString());
\r
370 actualValue = presetQuery.DRC2 / 10;
\r
371 mainWindow.lbl_drc2.Text = actualValue.ToString();
\r
373 value = presetQuery.DRC3;
\r
375 value = value - 10;
\r
376 mainWindow.trackBar3.Value = int.Parse(value.ToString());
\r
377 actualValue = presetQuery.DRC3 / 10;
\r
378 mainWindow.lbl_drc3.Text = actualValue.ToString();
\r
380 value = presetQuery.DRC4;
\r
382 value = value - 10;
\r
383 mainWindow.trackBar4.Value = int.Parse(value.ToString());
\r
384 actualValue = presetQuery.DRC4 / 10;
\r
385 mainWindow.lbl_drc4.Text = actualValue.ToString();
\r
389 mainWindow.drp_subtitle.Text = presetQuery.Subtitles;
\r
391 if (presetQuery.ForcedSubtitles == true)
\r
393 mainWindow.check_forced.CheckState = CheckState.Checked;
\r
394 mainWindow.check_forced.Enabled = true;
\r
397 mainWindow.check_forced.CheckState = CheckState.Unchecked;
\r
402 // H264 Tab & Preset Name
\r
404 mainWindow.rtf_x264Query.Text = presetQuery.H264Query;
\r
406 // Set the preset name
\r
407 mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";
\r
413 #region Query Generator & Chapter CSV Creation
\r
416 /// Generates a CLI query based on the GUI widgets.
\r
418 /// <param name="mainWindow"></param>
\r
419 /// <returns>The CLI String</returns>
\r
420 public string GenerateTheQuery(frmMain mainWindow)
\r
426 if ((mainWindow.text_source.Text != "") && (mainWindow.text_source.Text.Trim() != "Click 'Source' to continue"))
\r
427 query = " -i " + '"' + mainWindow.text_source.Text + '"';
\r
429 if (mainWindow.drp_dvdtitle.Text != "Automatic")
\r
431 string[] titleInfo = mainWindow.drp_dvdtitle.Text.Split(' ');
\r
432 query += " -t " + titleInfo[0];
\r
435 if (mainWindow.drop_chapterFinish.Text == mainWindow.drop_chapterStart.Text && mainWindow.drop_chapterStart.Text != "Auto")
\r
436 query += " -c " + mainWindow.drop_chapterStart.Text;
\r
437 else if (mainWindow.drop_chapterStart.Text == "Auto" && mainWindow.drop_chapterFinish.Text != "Auto")
\r
438 query += " -c " + "0-" + mainWindow.drop_chapterFinish.Text;
\r
439 else if (mainWindow.drop_chapterStart.Text != "Auto" && mainWindow.drop_chapterFinish.Text != "Auto")
\r
440 query += " -c " + mainWindow.drop_chapterStart.Text + "-" + mainWindow.drop_chapterFinish.Text;
\r
445 #region Destination
\r
446 if (mainWindow.text_destination.Text != "")
\r
447 query += " -o " + '"' + mainWindow.text_destination.Text + '"';
\r
450 query += generateTabbedComponentsQuery(mainWindow, mainWindow.text_source.Text);
\r
454 /// Generates a CLI query for the preview function.
\r
455 /// This basically forces a shortened version of the encdode.
\r
457 /// <param name="mainWindow"></param>
\r
458 /// <returns>Returns a CLI query String.</returns>
\r
459 public string GeneratePreviewQuery(frmMain mainWindow)
\r
465 if ((mainWindow.text_source.Text != "") && (mainWindow.text_source.Text.Trim() != "Click 'Source' to continue"))
\r
466 query = " -i " + '"' + mainWindow.text_source.Text + '"';
\r
468 if (mainWindow.drp_dvdtitle.Text != "Automatic")
\r
470 string[] titleInfo = mainWindow.drp_dvdtitle.Text.Split(' ');
\r
471 query += " -t " + titleInfo[0];
\r
478 #region Destination
\r
479 if (mainWindow.text_destination.Text != "")
\r
480 query += " -o " + '"' + mainWindow.text_destination.Text.Replace(".m", "_sample.m").Replace(".avi", "_sample.avi").Replace(".ogm", "_sample.ogm") + '"';
\r
484 query += generateTabbedComponentsQuery(mainWindow, mainWindow.text_source.Text);
\r
488 // Generates part of the CLI query, for the tabbed components only.
\r
489 private string generateTabbedComponentsQuery(frmMain mainWindow, string source)
\r
493 // Picture Settings Tab
\r
494 #region Picture Settings Tab
\r
496 switch (mainWindow.drp_videoEncoder.Text)
\r
498 case "MPEG-4 (FFmpeg)":
\r
499 query += " -e ffmpeg";
\r
501 case "MPEG-4 (XviD)":
\r
502 query += " -e xvid";
\r
504 case "H.264 (x264)":
\r
505 query += " -e x264";
\r
507 case "VP3 (Theora)":
\r
508 query += " -e theora";
\r
511 query += " -e x264";
\r
515 if (mainWindow.text_width.Text != "")
\r
516 query += " -w " + mainWindow.text_width.Text;
\r
518 if (mainWindow.text_height.Text != "")
\r
519 query += " -l " + mainWindow.text_height.Text;
\r
521 string cropTop = mainWindow.text_top.Text;
\r
522 string cropBottom = mainWindow.text_bottom.Text;
\r
523 string cropLeft = mainWindow.text_left.Text;
\r
524 string cropRight = mainWindow.text_right.Text;
\r
526 if (mainWindow.drp_crop.Text == "No Crop")
\r
527 query += " --crop 0:0:0:0 ";
\r
528 else if (mainWindow.drp_crop.Text == "Custom")
\r
530 if (mainWindow.text_top.Text == string.Empty)
\r
532 if (mainWindow.text_bottom.Text == string.Empty)
\r
534 if (mainWindow.text_left.Text == string.Empty)
\r
536 if (mainWindow.text_right.Text == string.Empty)
\r
539 query += " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;
\r
542 switch (mainWindow.drp_deInterlace_option.Text)
\r
548 query += " --deinterlace=\"fast\"";
\r
551 query += " --deinterlace=\"slow\"";
\r
554 query += " --deinterlace=\"slower\"";
\r
557 query += " --deinterlace=\"slowest\"";
\r
564 if (mainWindow.check_decomb.Checked)
\r
566 string decombValue = Properties.Settings.Default.decomb;
\r
567 if (decombValue != "" && decombValue != Properties.Settings.Default.default_decomb)
\r
568 query += " --decomb=\"" + decombValue + "\"";
\r
570 query += " --decomb ";
\r
573 if (mainWindow.check_grayscale.Checked)
\r
576 if (mainWindow.drp_anamorphic.SelectedIndex == 1)
\r
578 else if (mainWindow.drp_anamorphic.SelectedIndex == 2)
\r
581 if (mainWindow.check_deblock.Checked)
\r
582 query += " --deblock";
\r
584 if (mainWindow.check_detelecine.Checked)
\r
585 query += " --detelecine";
\r
587 if (mainWindow.check_vfr.Checked)
\r
591 // Video Settings Tab
\r
592 #region Video Settings Tab
\r
593 // These are output settings features
\r
594 if (mainWindow.check_largeFile.Checked)
\r
597 if (mainWindow.check_iPodAtom.Checked)
\r
600 if (mainWindow.check_optimiseMP4.Checked)
\r
604 if (mainWindow.text_bitrate.Text != "")
\r
605 query += " -b " + mainWindow.text_bitrate.Text;
\r
607 if (mainWindow.text_filesize.Text != "")
\r
608 query += " -S " + mainWindow.text_filesize.Text;
\r
610 // Video Quality Setting
\r
611 double videoQuality = mainWindow.slider_videoQuality.Value;
\r
612 if (videoQuality != 0)
\r
614 videoQuality = videoQuality / 100;
\r
615 query += " -q " + videoQuality.ToString(new CultureInfo("en-US"));
\r
618 if (mainWindow.check_2PassEncode.Checked)
\r
621 if (mainWindow.drp_videoFramerate.Text != "Same as source")
\r
623 if (!mainWindow.check_vfr.Checked)
\r
624 query += " -r " + mainWindow.drp_videoFramerate.Text;
\r
627 if (mainWindow.check_turbo.Checked)
\r
632 switch (mainWindow.drp_deNoise.Text)
\r
638 query += " --denoise=\"weak\"";
\r
641 query += " --denoise=\"medium\"";
\r
644 query += " --denoise=\"strong\"";
\r
652 // Audio Settings Tab
\r
653 #region Audio Settings Tab
\r
655 string track1 = mainWindow.drp_track1Audio.Text;
\r
656 string aencoder1 = mainWindow.drp_audenc_1.Text;
\r
657 string audioBitrate1 = mainWindow.drp_audbit_1.Text;
\r
658 string audioSampleRate1 = mainWindow.drp_audsr_1.Text;
\r
659 string Mixdown1 = mainWindow.drp_audmix_1.Text;
\r
660 string drc1 = mainWindow.trackBar1.Value.ToString();
\r
663 string track2 = mainWindow.drp_track2Audio.Text;
\r
664 string aencoder2 = mainWindow.drp_audenc_2.Text;
\r
665 string audioBitrate2 = mainWindow.drp_audbit_2.Text;
\r
666 string audioSampleRate2 = mainWindow.drp_audsr_2.Text;
\r
667 string Mixdown2 = mainWindow.drp_audmix_2.Text;
\r
668 string drc2 = mainWindow.trackBar2.Value.ToString();
\r
671 string track3 = mainWindow.drp_track3Audio.Text;
\r
672 string aencoder3 = mainWindow.drp_audenc_3.Text;
\r
673 string audioBitrate3 = mainWindow.drp_audbit_3.Text;
\r
674 string audioSampleRate3 = mainWindow.drp_audsr_3.Text;
\r
675 string Mixdown3 = mainWindow.drp_audmix_3.Text;
\r
676 string drc3 = mainWindow.trackBar3.Value.ToString();
\r
679 string track4 = mainWindow.drp_track4Audio.Text;
\r
680 string aencoder4 = mainWindow.drp_audenc_4.Text;
\r
681 string audioBitrate4 = mainWindow.drp_audbit_4.Text;
\r
682 string audioSampleRate4 = mainWindow.drp_audsr_4.Text;
\r
683 string Mixdown4 = mainWindow.drp_audmix_4.Text;
\r
684 string drc4 = mainWindow.trackBar4.Value.ToString();
\r
688 // Audio Track Selections
\r
690 if (track1 == "Automatic")
\r
692 else if (track1 != "None")
\r
694 string[] tempSub = track1.Split(' ');
\r
695 query += " -a " + tempSub[0];
\r
698 if (track2 != "None")
\r
701 tempSub = track2.Split(' ');
\r
703 if (track1 == "None")
\r
704 query += " -a none," + tempSub[0];
\r
706 query += "," + tempSub[0];
\r
709 if (track3 != "None")
\r
712 tempSub = track3.Split(' ');
\r
713 query += "," + tempSub[0];
\r
716 if (track4 != "None")
\r
719 tempSub = track4.Split(' ');
\r
720 query += "," + tempSub[0];
\r
726 if (aencoder1 != "")
\r
727 query += " -E " + getAudioEncoder(aencoder1);
\r
729 if (aencoder2 != "")
\r
731 if (aencoder1 == string.Empty)
\r
732 query += " -E faac," + getAudioEncoder(aencoder2);
\r
734 query += "," + getAudioEncoder(aencoder2);
\r
737 if (aencoder3 != "")
\r
738 query += "," + getAudioEncoder(aencoder3);
\r
740 if (aencoder4 != "")
\r
741 query += "," + getAudioEncoder(aencoder4);
\r
744 // Audio Bitrate Selections
\r
746 if (audioBitrate1 != "")
\r
747 query += " -B " + audioBitrate1;
\r
749 if (audioBitrate2 != "")
\r
751 if (audioBitrate1 == string.Empty)
\r
752 query += " -B 160," + audioBitrate2;
\r
754 query += "," + audioBitrate2;
\r
757 if (audioBitrate3 != "")
\r
758 query += "," + audioBitrate3;
\r
760 if (audioBitrate4 != "")
\r
761 query += "," + audioBitrate4;
\r
764 //Audio Sample Rate - audioSampleRate
\r
765 if (audioSampleRate1 != "")
\r
766 query += " -R " + audioSampleRate1.Replace("Auto", "0");
\r
768 if (audioSampleRate2 != "")
\r
770 if (audioSampleRate1 == string.Empty)
\r
771 query += " -R 0," + audioSampleRate2.Replace("Auto", "0");
\r
773 query += "," + audioSampleRate2.Replace("Auto", "0");
\r
777 // All this is a hack, because when AppleTV is selected, there is no sample rate selected. so just add a 48
\r
778 // It should probably be setup later so the GUI widget has the value 48 in it.
\r
780 if ((track2 != "") && (track2 != "None"))
\r
782 if (audioSampleRate1 == string.Empty)
\r
783 query += " -R 0,0";
\r
789 if (audioSampleRate3 != "")
\r
790 query += "," + audioSampleRate3.Replace("Auto", "0");
\r
792 if (audioSampleRate4 != "")
\r
793 query += "," + audioSampleRate4.Replace("Auto", "0");
\r
796 // Audio Mixdown Selections
\r
799 if (Mixdown1 != "")
\r
800 query += " -6 " + getMixDown(Mixdown1);
\r
802 query += " -6 dpl2";
\r
804 if (Mixdown2 != "" && track2 != "None")
\r
805 query += "," + getMixDown(Mixdown2);
\r
807 if (Mixdown3 != "" && track3 != "None" && track2 != "None")
\r
808 query += "," + getMixDown(Mixdown3);
\r
810 if (Mixdown4 != "" && track4 != "None" && track3 != "None")
\r
811 query += "," + getMixDown(Mixdown4);
\r
819 value = mainWindow.trackBar1.Value / 10.0;
\r
823 query += " -D " + value;
\r
827 value = mainWindow.trackBar2.Value / 10.0;
\r
829 if (track2 != "None" && drc2 != "0")
\r
830 query += "," + value;
\r
831 else if (track2 != "None" && drc2 == "0")
\r
834 value = mainWindow.trackBar3.Value / 10.0;
\r
836 if (track3 != "None" && drc3 != "0")
\r
837 query += "," + value;
\r
838 else if (track3 != "None" && drc3 == "0")
\r
841 value = mainWindow.trackBar4.Value / 10.0;
\r
843 if (track4 != "None" && drc4 != "0")
\r
844 query += "," + value;
\r
845 else if (track4 != "None" && drc4 == "0")
\r
849 string subtitles = mainWindow.drp_subtitle.Text;
\r
850 if (subtitles == "Autoselect")
\r
852 else if (subtitles != "" && subtitles != "None")
\r
855 tempSub = subtitles.Split(' ');
\r
856 query += " -s " + tempSub[0];
\r
859 if (mainWindow.check_forced.Checked)
\r
864 // Chapter Markers Tab
\r
865 #region Chapter Markers
\r
867 // Attach Source name and dvd title to the start of the chapters.csv filename.
\r
868 // This is for the queue. It allows different chapter name files for each title.
\r
869 string source_name = mainWindow.text_source.Text;
\r
870 string[] sourceName = source.Split('\\');
\r
871 source_name = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");
\r
872 source_name = source_name.Replace("\"", "");
\r
874 string source_title = mainWindow.drp_dvdtitle.Text;
\r
875 string[] titlesplit = source_title.Split(' ');
\r
876 source_title = titlesplit[0];
\r
878 if (mainWindow.Check_ChapterMarkers.Checked)
\r
880 if ((source_name.Trim().Replace("-i ", "") != "Click 'Browse' to continue") && (source_name.Trim().Replace("-i ", "") != ""))
\r
882 if (source_title != "Automatic")
\r
884 string filename = source_name + "-" + source_title + "-chapters.csv";
\r
885 string path = Path.Combine(Path.GetTempPath(), filename);
\r
887 Boolean saveCSV = chapterCSVSave(mainWindow, path);
\r
888 if (saveCSV == false)
\r
891 query += " --markers=" + "\"" + path + "\"";
\r
895 string filename = source_name + "-chapters.csv";
\r
896 string path = Path.Combine(Path.GetTempPath(), filename);
\r
898 Boolean saveCSV = chapterCSVSave(mainWindow, path);
\r
899 if (saveCSV == false)
\r
902 query += " --markers=" + "\"" + path + "\"";
\r
907 string path = Path.Combine(Path.GetTempPath(), "chapters.csv");
\r
908 query += " --markers=" + "\"" + path + "\"";
\r
915 if (mainWindow.rtf_x264Query.Text != "")
\r
916 query += " -x " + mainWindow.rtf_x264Query.Text;
\r
920 #region Processors / Other
\r
921 string processors = Properties.Settings.Default.Processors;
\r
922 if (processors != "Automatic")
\r
923 query += " -C " + processors + " ";
\r
930 // Get the CLI equive of the audio mixdown from the widget name.
\r
931 private string getMixDown(string selectedAudio)
\r
933 switch (selectedAudio)
\r
941 case "Dolby Surround":
\r
943 case "Dolby Pro Logic II":
\r
945 case "6 Channel Discrete":
\r
951 // Get the CLI equiv of the audio encoder from the widget name.
\r
952 private string getAudioEncoder(string selectedEncoder)
\r
954 switch (selectedEncoder)
\r
968 // This function saves the data in the chapters tab, dataGridView into a CSV file called chapters.csv
\r
969 // in a directory specified by file_path_name
\r
970 private Boolean chapterCSVSave(frmMain mainWindow, string file_path_name)
\r
974 StringBuilder csv = new StringBuilder();
\r
976 foreach (DataGridViewRow row in mainWindow.data_chpt.Rows)
\r
978 csv.Append(row.Cells[0].Value.ToString());
\r
980 csv.Append(row.Cells[1].Value.ToString());
\r
981 csv.Append(Environment.NewLine);
\r
983 StreamWriter file = new StreamWriter(file_path_name);
\r
984 file.Write(csv.ToString());
\r
990 catch (Exception exc)
\r
992 MessageBox.Show("Unable to save Chapter Makrers file! \nChapter marker names will NOT be saved in your encode \n\n" + exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
999 #region frmMain Actions
\r
1002 /// Select the longest title in the DVD title dropdown menu on frmMain
\r
1004 public void selectLongestTitle(frmMain mainWindow)
\r
1006 int current_largest = 0;
\r
1007 Handbrake.Parsing.Title title2Select;
\r
1009 // Check if there are titles in the DVD title dropdown menu and make sure, it's not just "Automatic"
\r
1010 if (mainWindow.drp_dvdtitle.Items[0].ToString() != "Automatic")
\r
1011 title2Select = (Handbrake.Parsing.Title)mainWindow.drp_dvdtitle.Items[0];
\r
1013 title2Select = null;
\r
1015 // So, If there are titles in the DVD Title dropdown menu, lets select the longest.
\r
1016 if (title2Select != null)
\r
1018 foreach (Handbrake.Parsing.Title x in mainWindow.drp_dvdtitle.Items)
\r
1020 string title = x.ToString();
\r
1021 if (title != "Automatic")
\r
1023 string[] y = title.Split(' ');
\r
1024 string time = y[1].Replace("(", "").Replace(")", "");
\r
1025 string[] z = time.Split(':');
\r
1027 int hours = int.Parse(z[0]) * 60 * 60;
\r
1028 int minutes = int.Parse(z[1]) * 60;
\r
1029 int seconds = int.Parse(z[2]);
\r
1030 int total_sec = hours + minutes + seconds;
\r
1032 if (current_largest == 0)
\r
1034 current_largest = hours + minutes + seconds;
\r
1039 if (total_sec > current_largest)
\r
1041 current_largest = total_sec;
\r
1048 // Now set the longest title in the gui.
\r
1049 mainWindow.drp_dvdtitle.SelectedItem = title2Select;
\r
1054 /// Set's up the DataGridView on the Chapters tab (frmMain)
\r
1056 /// <param name="mainWindow"></param>
\r
1057 public void chapterNaming(frmMain mainWindow)
\r
1061 mainWindow.data_chpt.Rows.Clear();
\r
1066 if (mainWindow.drop_chapterFinish.Text != "Auto")
\r
1067 finish = int.Parse(mainWindow.drop_chapterFinish.Text);
\r
1069 if (mainWindow.drop_chapterStart.Text != "Auto")
\r
1070 start = int.Parse(mainWindow.drop_chapterStart.Text);
\r
1072 rowCount = finish - (start - 1);
\r
1074 while (i < rowCount)
\r
1076 DataGridViewRow row = new DataGridViewRow();
\r
1078 mainWindow.data_chpt.Rows.Insert(i, row);
\r
1079 mainWindow.data_chpt.Rows[i].Cells[0].Value = (i + 1);
\r
1080 mainWindow.data_chpt.Rows[i].Cells[1].Value = "Chapter " + (i + 1);
\r
1084 catch (Exception exc)
\r
1086 MessageBox.Show("chapterNaming() Error has occured: \n" + exc.ToString());
\r
1091 /// Function which generates the filename and path automatically based on
\r
1092 /// the Source Name, DVD title and DVD Chapters
\r
1094 /// <param name="mainWindow"></param>
\r
1095 public void autoName(frmMain mainWindow)
\r
1097 if (Properties.Settings.Default.autoNaming == "Checked")
\r
1099 if (mainWindow.drp_dvdtitle.Text != "Automatic")
\r
1101 string source = mainWindow.text_source.Text;
\r
1102 string[] sourceName = source.Split('\\');
\r
1103 source = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");
\r
1105 string title = mainWindow.drp_dvdtitle.Text;
\r
1106 string[] titlesplit = title.Split(' ');
\r
1107 title = titlesplit[0];
\r
1109 string cs = mainWindow.drop_chapterStart.Text;
\r
1110 string cf = mainWindow.drop_chapterFinish.Text;
\r
1112 if (title == "Automatic")
\r
1123 if (!mainWindow.text_destination.Text.Contains("\\"))
\r
1125 string filePath = "";
\r
1126 if (Properties.Settings.Default.autoNamePath.Trim() != "")
\r
1128 if (Properties.Settings.Default.autoNamePath.Trim() != "Click 'Browse' to set the default location")
\r
1129 filePath = Properties.Settings.Default.autoNamePath + "\\";
\r
1131 mainWindow.text_destination.Text = filePath + source + "_T" + title + "_C" + cs + dash + cf + ".mp4";
\r
1135 string dest = mainWindow.text_destination.Text;
\r
1137 string[] destName = dest.Split('\\');
\r
1140 string[] extension = dest.Split('.');
\r
1141 string ext = extension[extension.Length - 1];
\r
1143 destName[destName.Length - 1] = source + "_T" + title + "_C" + cs + dash + cf + "." + ext;
\r
1145 string fullDest = "";
\r
1146 foreach (string part in destName)
\r
1148 if (fullDest != "")
\r
1149 fullDest = fullDest + "\\" + part;
\r
1151 fullDest = fullDest + part;
\r
1154 mainWindow.text_destination.Text = fullDest;
\r
1162 #region Version and Update Checking
\r
1165 /// Checks for updates and returns true if an update is available.
\r
1167 /// <param name="debug">Turns on debug mode. Don't use on program startup</param>
\r
1168 /// <returns>Boolean True = Update available</returns>
\r
1169 public Boolean updateCheck(Boolean debug)
\r
1173 Functions.AppcastReader rssRead = new Functions.AppcastReader();
\r
1174 string build = rssRead.build();
\r
1176 int latest = int.Parse(build);
\r
1177 int current = Properties.Settings.Default.hb_build;
\r
1178 int skip = Properties.Settings.Default.skipversion;
\r
1180 if (latest == skip)
\r
1184 Boolean update = (latest > current);
\r
1188 catch (Exception exc)
\r
1190 if (debug == true)
\r
1191 MessageBox.Show("Unable to check for updates, Please try again later. \n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
1196 /// Get's HandBrakes version data from the CLI.
\r
1198 /// <returns>Arraylist of Version Data. 0 = hb_version 1 = hb_build</returns>
\r
1199 public ArrayList getCliVersionData()
\r
1201 ArrayList cliVersionData = new ArrayList();
\r
1202 // 0 = SVN Build / Version
\r
1205 Process cliProcess = new Process();
\r
1206 ProcessStartInfo handBrakeCLI = new ProcessStartInfo("HandBrakeCLI.exe", " -u");
\r
1207 handBrakeCLI.UseShellExecute = false;
\r
1208 handBrakeCLI.RedirectStandardError = true;
\r
1209 handBrakeCLI.RedirectStandardOutput = true;
\r
1210 handBrakeCLI.CreateNoWindow = true;
\r
1211 cliProcess.StartInfo = handBrakeCLI;
\r
1212 cliProcess.Start();
\r
1214 // Retrieve standard output and report back to parent thread until the process is complete
\r
1216 TextReader stdOutput = cliProcess.StandardError;
\r
1218 while (!cliProcess.HasExited)
\r
1220 line = stdOutput.ReadLine();
\r
1221 Match m = Regex.Match(line, @"HandBrake [0-9\.]*svn[0-9]*[M]* \([0-9]*\)");
\r
1222 if (m.Success != false)
\r
1224 string data = line.Replace("(", "").Replace(")", "").Replace("HandBrake ", "");
\r
1225 string[] arr = data.Split(' ');
\r
1226 cliVersionData.Add(arr[0]);
\r
1227 cliVersionData.Add(arr[1]);
\r
1228 return cliVersionData;
\r
1238 /// Check if the queue recovery file contains records.
\r
1239 /// If it does, it means the last queue did not complete before HandBrake closed.
\r
1240 /// So, return a boolean if true.
\r
1242 public Boolean check_queue_recovery()
\r
1246 string tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");
\r
1247 using (StreamReader reader = new StreamReader(tempPath))
\r
1249 string queue_item = reader.ReadLine();
\r
1250 if (queue_item == null)
\r
1256 else // There exists an item in the recovery queue file, so try and recovr it.
\r
1266 // Keep quiet about the error.
\r