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
43 /// This function takes in a Query which has been parsed by QueryParser and
\r
44 /// set's all the GUI widgets correctly.
\r
46 /// <param name="mainWindow"></param>
\r
47 /// <param name="presetQuery">The Parsed CLI Query</param>
\r
48 /// <param name="name">Name of the preset</param>
\r
49 public void presetLoader(frmMain mainWindow, Functions.QueryParser presetQuery, string name)
\r
51 // ---------------------------
\r
53 // ---------------------------
\r
57 // Reset some vaules to stock first to prevent errors.
\r
58 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
60 // Now load all the new settings onto the main window
\r
61 mainWindow.drp_dvdtitle.Text = "Automatic";
\r
62 mainWindow.drop_chapterStart.Text = "Auto";
\r
63 mainWindow.drop_chapterFinish.Text = "Auto";
\r
65 if (presetQuery.Format != null)
\r
67 string destination = mainWindow.text_destination.Text;
\r
68 destination = destination.Replace(".mp4", "." + presetQuery.Format);
\r
69 destination = destination.Replace(".m4v", "." + presetQuery.Format);
\r
70 destination = destination.Replace(".avi", "." + presetQuery.Format);
\r
71 destination = destination.Replace(".mkv", "." + presetQuery.Format);
\r
72 destination = destination.Replace(".ogm", "." + presetQuery.Format);
\r
73 mainWindow.text_destination.Text = destination;
\r
81 mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;
\r
83 if (presetQuery.Format != null)
\r
85 if (presetQuery.Format == "mp4")
\r
86 mainWindow.drop_format.SelectedIndex = 0;
\r
87 else if (presetQuery.Format == "m4v")
\r
88 mainWindow.drop_format.SelectedIndex = 1;
\r
89 else if (presetQuery.Format == "mkv")
\r
90 mainWindow.drop_format.SelectedIndex = 2;
\r
91 else if (presetQuery.Format == "avi")
\r
92 mainWindow.drop_format.SelectedIndex = 3;
\r
93 else if (presetQuery.Format == "ogm")
\r
94 mainWindow.drop_format.SelectedIndex = 4;
\r
97 if (presetQuery.IpodAtom == true)
\r
98 mainWindow.check_iPodAtom.CheckState = CheckState.Checked;
\r
100 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
102 if (presetQuery.OptimizeMP4 == true)
\r
103 mainWindow.check_optimiseMP4.CheckState = CheckState.Checked;
\r
105 mainWindow.check_optimiseMP4.CheckState = CheckState.Unchecked;
\r
109 // Picture Settings Tab
\r
112 if (presetQuery.CropTop == "0" && presetQuery.CropBottom == "0" && presetQuery.CropLeft == "0" && presetQuery.CropRight == "0")
\r
114 mainWindow.check_customCrop.Checked = true;
\r
115 mainWindow.text_top.Text = "0";
\r
116 mainWindow.text_bottom.Text = "0";
\r
117 mainWindow.text_left.Text = "0";
\r
118 mainWindow.text_right.Text = "0";
\r
120 else if (presetQuery.CropTop != null && presetQuery.CropBottom != null && presetQuery.CropLeft != null && presetQuery.CropRight != null)
\r
122 mainWindow.check_customCrop.Checked = true;
\r
123 mainWindow.text_top.Text = presetQuery.CropTop;
\r
124 mainWindow.text_bottom.Text = presetQuery.CropBottom;
\r
125 mainWindow.text_left.Text = presetQuery.CropLeft;
\r
126 mainWindow.text_right.Text = presetQuery.CropRight;
\r
129 mainWindow.check_autoCrop.Checked = true;
\r
131 mainWindow.drp_deInterlace_option.Text = presetQuery.DeInterlace;
\r
132 mainWindow.drp_deNoise.Text = presetQuery.DeNoise;
\r
134 if (presetQuery.Decomb == true)
\r
135 mainWindow.check_decomb.CheckState = CheckState.Checked;
\r
137 mainWindow.check_decomb.CheckState = CheckState.Unchecked;
\r
139 if (presetQuery.DeTelecine == true)
\r
140 mainWindow.check_detelecine.CheckState = CheckState.Checked;
\r
142 mainWindow.check_detelecine.CheckState = CheckState.Unchecked;
\r
144 if (presetQuery.DeBlock != 0)
\r
146 mainWindow.slider_deblock.Value = presetQuery.DeBlock;
\r
147 mainWindow.lbl_deblockVal.Text = presetQuery.DeBlock.ToString();
\r
151 mainWindow.slider_deblock.Value = 0;
\r
152 mainWindow.lbl_deblockVal.Text = "0";
\r
157 if (presetQuery.Anamorphic == true)
\r
158 mainWindow.drp_anamorphic.SelectedIndex = 1;
\r
160 mainWindow.drp_anamorphic.SelectedIndex = 0;
\r
162 if (presetQuery.LooseAnamorphic == true)
\r
163 mainWindow.drp_anamorphic.SelectedIndex = 2;
\r
166 if (presetQuery.Anamorphic != true)
\r
167 mainWindow.drp_anamorphic.SelectedIndex = 0;
\r
170 if (presetQuery.Width != 0)
\r
171 mainWindow.text_width.Text = presetQuery.Width.ToString();
\r
174 mainWindow.text_width.Text = "";
\r
177 if (presetQuery.Height != 0)
\r
178 mainWindow.text_height.Text = presetQuery.Height.ToString();
\r
181 mainWindow.text_height.Text = "";
\r
184 if (presetQuery.VFR == true)
\r
185 mainWindow.check_vfr.CheckState = CheckState.Checked;
\r
187 mainWindow.check_vfr.CheckState = CheckState.Unchecked;
\r
190 // Video Settings Tab
\r
192 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;
\r
193 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;
\r
194 mainWindow.slider_videoQuality.Value = presetQuery.VideoQuality;
\r
195 if (mainWindow.slider_videoQuality.Value != 0)
\r
197 int ql = presetQuery.VideoQuality;
\r
198 mainWindow.SliderValue.Text = ql.ToString() + "%";
\r
201 if (presetQuery.TwoPass == true)
\r
202 mainWindow.check_2PassEncode.CheckState = CheckState.Checked;
\r
204 mainWindow.check_2PassEncode.CheckState = CheckState.Unchecked;
\r
206 if (presetQuery.Grayscale == true)
\r
207 mainWindow.check_grayscale.CheckState = CheckState.Checked;
\r
209 mainWindow.check_grayscale.CheckState = CheckState.Unchecked;
\r
211 mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;
\r
213 if (presetQuery.TurboFirstPass == true)
\r
214 mainWindow.check_turbo.CheckState = CheckState.Checked;
\r
216 mainWindow.check_turbo.CheckState = CheckState.Unchecked;
\r
218 if (presetQuery.LargeMP4 == true)
\r
219 mainWindow.check_largeFile.CheckState = CheckState.Checked;
\r
222 mainWindow.check_largeFile.CheckState = CheckState.Unchecked;
\r
223 mainWindow.check_largeFile.BackColor = Color.Transparent;
\r
230 // Chapter Markers Tab
\r
231 #region Chapter Markers
\r
233 if (presetQuery.ChapterMarkers == true)
\r
235 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
236 mainWindow.text_destination.Text = mainWindow.text_destination.Text.Replace(".mp4", ".m4v");
\r
239 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;
\r
243 // Audio Settings Tab
\r
247 mainWindow.drp_track1Audio.Text = "Automatic";
\r
250 if (presetQuery.AudioEncoder2 != null) // Fix for loading in built in presets. Where 2 encoders but no tracks in the preset.
\r
252 mainWindow.drp_track2Audio.Enabled = true;
\r
253 mainWindow.drp_audsr_2.Enabled = true;
\r
254 mainWindow.drp_audmix_2.Enabled = true;
\r
255 mainWindow.drp_audenc_2.Enabled = true;
\r
256 mainWindow.drp_audbit_2.Enabled = true;
\r
257 mainWindow.drp_audsr_2.Text = "48";
\r
258 mainWindow.drp_track2Audio.Text = "Automatic";
\r
260 else if (presetQuery.AudioTrack2 == "None")
\r
262 mainWindow.drp_track2Audio.Text = "None";
\r
263 mainWindow.drp_track2Audio.SelectedIndex = 0;
\r
264 mainWindow.drp_audsr_2.Enabled = false;
\r
265 mainWindow.drp_audmix_2.Enabled = false;
\r
266 mainWindow.drp_audenc_2.Enabled = false;
\r
267 mainWindow.drp_audbit_2.Enabled = false;
\r
271 mainWindow.drp_track2Audio.Text = presetQuery.AudioTrack2;
\r
272 mainWindow.drp_audsr_2.Enabled = true;
\r
273 mainWindow.drp_audmix_2.Enabled = true;
\r
274 mainWindow.drp_audenc_2.Enabled = true;
\r
275 mainWindow.drp_audbit_2.Enabled = true;
\r
279 if (presetQuery.AudioTrack3 == "None")
\r
281 mainWindow.drp_track3Audio.SelectedIndex = 0;
\r
282 mainWindow.drp_audsr_3.Enabled = false;
\r
283 mainWindow.drp_audmix_3.Enabled = false;
\r
284 mainWindow.drp_audenc_3.Enabled = false;
\r
285 mainWindow.drp_audbit_3.Enabled = false;
\r
286 mainWindow.trackBar3.Enabled = false;
\r
288 mainWindow.drp_track3Audio.Text = "None";
\r
289 mainWindow.drp_audsr_3.Text = "";
\r
290 mainWindow.drp_audmix_3.Text = "Automatic";
\r
291 mainWindow.drp_audenc_3.Text = "";
\r
292 mainWindow.drp_audbit_3.Text = "";
\r
293 mainWindow.trackBar3.Value = 0;
\r
298 mainWindow.drp_track3Audio.Text = presetQuery.AudioTrack3;
\r
299 mainWindow.drp_audsr_3.Enabled = true;
\r
300 mainWindow.drp_audmix_3.Enabled = true;
\r
301 mainWindow.drp_audenc_3.Enabled = true;
\r
302 mainWindow.drp_audbit_3.Enabled = true;
\r
303 mainWindow.trackBar3.Enabled = true;
\r
307 if (presetQuery.AudioTrack4 == "None")
\r
309 mainWindow.drp_track4Audio.SelectedIndex = 0;
\r
310 mainWindow.drp_audsr_4.Enabled = false;
\r
311 mainWindow.drp_audmix_4.Enabled = false;
\r
312 mainWindow.drp_audenc_4.Enabled = false;
\r
313 mainWindow.drp_audbit_4.Enabled = false;
\r
314 mainWindow.trackBar4.Enabled = false;
\r
316 mainWindow.drp_track4Audio.Text = "None";
\r
317 mainWindow.drp_audsr_4.Text = "";
\r
318 mainWindow.drp_audmix_4.Text = "Automatic";
\r
319 mainWindow.drp_audenc_4.Text = "";
\r
320 mainWindow.drp_audbit_4.Text = "";
\r
321 mainWindow.trackBar4.Value = 0;
\r
325 mainWindow.drp_track4Audio.Text = presetQuery.AudioTrack4;
\r
326 mainWindow.drp_audsr_4.Enabled = true;
\r
327 mainWindow.drp_audmix_4.Enabled = true;
\r
328 mainWindow.drp_audenc_4.Enabled = true;
\r
329 mainWindow.drp_audbit_4.Enabled = true;
\r
330 mainWindow.trackBar4.Enabled = true;
\r
333 // Now lets start setting stuff
\r
334 if (presetQuery.AudioEncoder1 != null)
\r
335 mainWindow.drp_audenc_1.Text = presetQuery.AudioEncoder1;
\r
336 mainWindow.drp_audenc_2.Text = presetQuery.AudioEncoder2;
\r
337 mainWindow.drp_audenc_3.Text = presetQuery.AudioEncoder3;
\r
338 mainWindow.drp_audenc_4.Text = presetQuery.AudioEncoder4;
\r
340 if (presetQuery.AudioBitrate1 != null)
\r
341 mainWindow.drp_audbit_1.Text = presetQuery.AudioBitrate1;
\r
342 mainWindow.drp_audbit_2.Text = presetQuery.AudioBitrate2;
\r
343 mainWindow.drp_audbit_3.Text = presetQuery.AudioBitrate4;
\r
344 mainWindow.drp_audbit_3.Text = presetQuery.AudioBitrate4;
\r
346 if (presetQuery.AudioSamplerate1 != null)
\r
347 mainWindow.drp_audsr_1.Text = presetQuery.AudioSamplerate1;
\r
348 mainWindow.drp_audsr_2.Text = presetQuery.AudioSamplerate2;
\r
349 mainWindow.drp_audsr_3.Text = presetQuery.AudioSamplerate3;
\r
350 mainWindow.drp_audsr_4.Text = presetQuery.AudioSamplerate4;
\r
352 mainWindow.drp_audmix_1.Text = presetQuery.AudioTrackMix1;
\r
353 mainWindow.drp_audmix_2.Text = presetQuery.AudioTrackMix2;
\r
354 mainWindow.drp_audmix_3.Text = presetQuery.AudioTrackMix3;
\r
355 mainWindow.drp_audmix_4.Text = presetQuery.AudioTrackMix4;
\r
358 // Dynamic Range Compression (Should be a float but we use double for ease)
\r
360 double actualValue = 0;
\r
362 value = presetQuery.DRC1;
\r
364 value = value - 10;
\r
365 mainWindow.trackBar1.Value = int.Parse(value.ToString());
\r
366 actualValue = presetQuery.DRC1 / 10;
\r
367 mainWindow.lbl_drc1.Text = actualValue.ToString();
\r
369 value = presetQuery.DRC2;
\r
371 value = value - 10;
\r
372 mainWindow.trackBar2.Value = int.Parse(value.ToString());
\r
373 actualValue = presetQuery.DRC2 / 10;
\r
374 mainWindow.lbl_drc2.Text = actualValue.ToString();
\r
376 value = presetQuery.DRC3;
\r
378 value = value - 10;
\r
379 mainWindow.trackBar3.Value = int.Parse(value.ToString());
\r
380 actualValue = presetQuery.DRC3 / 10;
\r
381 mainWindow.lbl_drc3.Text = actualValue.ToString();
\r
383 value = presetQuery.DRC4;
\r
385 value = value - 10;
\r
386 mainWindow.trackBar4.Value = int.Parse(value.ToString());
\r
387 actualValue = presetQuery.DRC4 / 10;
\r
388 mainWindow.lbl_drc4.Text = actualValue.ToString();
\r
392 mainWindow.drp_subtitle.Text = presetQuery.Subtitles;
\r
394 if (presetQuery.ForcedSubtitles == true)
\r
396 mainWindow.check_forced.CheckState = CheckState.Checked;
\r
397 mainWindow.check_forced.Enabled = true;
\r
400 mainWindow.check_forced.CheckState = CheckState.Unchecked;
\r
405 // H264 Tab & Preset Name
\r
407 mainWindow.rtf_x264Query.Text = presetQuery.H264Query;
\r
409 // Set the preset name
\r
410 mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";
\r
416 #region Query Generator Functions
\r
419 /// Generates a CLI query based on the GUI widgets.
\r
421 /// <param name="mainWindow"></param>
\r
422 /// <returns>The CLI String</returns>
\r
423 public string GenerateTheQuery(frmMain mainWindow)
\r
429 if ((mainWindow.text_source.Text != "") && (mainWindow.text_source.Text.Trim() != "Click 'Source' to continue"))
\r
430 query = " -i " + '"' + mainWindow.text_source.Text + '"';
\r
432 if (mainWindow.drp_dvdtitle.Text != "Automatic")
\r
434 string[] titleInfo = mainWindow.drp_dvdtitle.Text.Split(' ');
\r
435 query += " -t " + titleInfo[0];
\r
438 if (mainWindow.drop_chapterFinish.Text == mainWindow.drop_chapterStart.Text && mainWindow.drop_chapterStart.Text != "Auto")
\r
439 query += " -c " + mainWindow.drop_chapterStart.Text;
\r
440 else if (mainWindow.drop_chapterStart.Text == "Auto" && mainWindow.drop_chapterFinish.Text != "Auto")
\r
441 query += " -c " + "0-" + mainWindow.drop_chapterFinish.Text;
\r
442 else if (mainWindow.drop_chapterStart.Text != "Auto" && mainWindow.drop_chapterFinish.Text != "Auto")
\r
443 query += " -c " + mainWindow.drop_chapterStart.Text + "-" + mainWindow.drop_chapterFinish.Text;
\r
448 #region Destination
\r
449 if (mainWindow.text_destination.Text != "")
\r
450 query += " -o " + '"' + mainWindow.text_destination.Text + '"';
\r
453 query += generateTabbedComponentsQuery(mainWindow, mainWindow.text_source.Text);
\r
458 /// Generates a CLI query for the preview function.
\r
459 /// This basically forces a shortened version of the encdode.
\r
461 /// <param name="mainWindow"></param>
\r
462 /// <returns>Returns a CLI query String.</returns>
\r
463 public string GeneratePreviewQuery(frmMain mainWindow)
\r
469 if ((mainWindow.text_source.Text != "") && (mainWindow.text_source.Text.Trim() != "Click 'Source' to continue"))
\r
470 query = " -i " + '"' + mainWindow.text_source.Text + '"';
\r
472 if (mainWindow.drp_dvdtitle.Text != "Automatic")
\r
474 string[] titleInfo = mainWindow.drp_dvdtitle.Text.Split(' ');
\r
475 query += " -t " + titleInfo[0];
\r
482 #region Destination
\r
483 if (mainWindow.text_destination.Text != "")
\r
484 query += " -o " + '"' + mainWindow.text_destination.Text.Replace(".m", "_sample.m").Replace(".avi", "_sample.avi").Replace(".ogm", "_sample.ogm") + '"';
\r
488 query += generateTabbedComponentsQuery(mainWindow, mainWindow.text_source.Text);
\r
493 /// Generates part of the CLI query, for the tabbed components only.
\r
495 /// <param name="mainWindow"></param>
\r
496 /// <param name="source"></param>
\r
497 /// <returns></returns>
\r
498 private string generateTabbedComponentsQuery(frmMain mainWindow, string source)
\r
502 // Picture Settings Tab
\r
503 #region Picture Settings Tab
\r
505 switch (mainWindow.drp_videoEncoder.Text)
\r
507 case "MPEG-4 (FFmpeg)":
\r
508 query += " -e ffmpeg";
\r
510 case "MPEG-4 (XviD)":
\r
511 query += " -e xvid";
\r
513 case "H.264 (x264)":
\r
514 query += " -e x264";
\r
516 case "VP3 (Theora)":
\r
517 query += " -e theora";
\r
520 query += " -e x264";
\r
524 if (mainWindow.text_width.Text != "")
\r
525 query += " -w " + mainWindow.text_width.Text;
\r
527 if (mainWindow.text_height.Text != "")
\r
528 query += " -l " + mainWindow.text_height.Text;
\r
530 string cropTop = mainWindow.text_top.Text;
\r
531 string cropBottom = mainWindow.text_bottom.Text;
\r
532 string cropLeft = mainWindow.text_left.Text;
\r
533 string cropRight = mainWindow.text_right.Text;
\r
535 if (mainWindow.check_customCrop.Checked)
\r
537 if (mainWindow.text_top.Text == string.Empty)
\r
539 if (mainWindow.text_bottom.Text == string.Empty)
\r
541 if (mainWindow.text_left.Text == string.Empty)
\r
543 if (mainWindow.text_right.Text == string.Empty)
\r
546 query += " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;
\r
549 switch (mainWindow.drp_deInterlace_option.Text)
\r
555 query += " --deinterlace=\"fast\"";
\r
558 query += " --deinterlace=\"slow\"";
\r
561 query += " --deinterlace=\"slower\"";
\r
564 query += " --deinterlace=\"slowest\"";
\r
571 if (mainWindow.check_decomb.Checked)
\r
573 string decombValue = Properties.Settings.Default.decomb;
\r
574 if (decombValue != "" && decombValue != Properties.Settings.Default.default_decomb)
\r
575 query += " --decomb=\"" + decombValue + "\"";
\r
577 query += " --decomb ";
\r
580 if (mainWindow.check_grayscale.Checked)
\r
583 if (mainWindow.drp_anamorphic.SelectedIndex == 1)
\r
585 else if (mainWindow.drp_anamorphic.SelectedIndex == 2)
\r
588 if (mainWindow.slider_deblock.Value != 0)
\r
589 query += " --deblock=" + mainWindow.slider_deblock.Value;
\r
591 if (mainWindow.check_detelecine.Checked)
\r
592 query += " --detelecine";
\r
594 if (mainWindow.check_vfr.Checked)
\r
598 // Video Settings Tab
\r
599 #region Video Settings Tab
\r
600 // These are output settings features
\r
601 if (mainWindow.check_largeFile.Checked)
\r
604 if (mainWindow.check_iPodAtom.Checked)
\r
607 if (mainWindow.check_optimiseMP4.Checked)
\r
611 if (mainWindow.text_bitrate.Text != "")
\r
612 query += " -b " + mainWindow.text_bitrate.Text;
\r
614 if (mainWindow.text_filesize.Text != "")
\r
615 query += " -S " + mainWindow.text_filesize.Text;
\r
617 // Video Quality Setting
\r
618 double videoQuality = mainWindow.slider_videoQuality.Value;
\r
619 if (videoQuality != 0)
\r
621 videoQuality = videoQuality / 100;
\r
622 query += " -q " + videoQuality.ToString(new CultureInfo("en-US"));
\r
625 if (mainWindow.check_2PassEncode.Checked)
\r
628 if (mainWindow.drp_videoFramerate.Text != "Same as source")
\r
630 if (!mainWindow.check_vfr.Checked)
\r
631 query += " -r " + mainWindow.drp_videoFramerate.Text;
\r
634 if (mainWindow.check_turbo.Checked)
\r
639 switch (mainWindow.drp_deNoise.Text)
\r
645 query += " --denoise=\"weak\"";
\r
648 query += " --denoise=\"medium\"";
\r
651 query += " --denoise=\"strong\"";
\r
659 // Audio Settings Tab
\r
660 #region Audio Settings Tab
\r
662 string track1 = mainWindow.drp_track1Audio.Text;
\r
663 string aencoder1 = mainWindow.drp_audenc_1.Text;
\r
664 string audioBitrate1 = mainWindow.drp_audbit_1.Text;
\r
665 string audioSampleRate1 = mainWindow.drp_audsr_1.Text;
\r
666 string Mixdown1 = mainWindow.drp_audmix_1.Text;
\r
667 string drc1 = mainWindow.trackBar1.Value.ToString();
\r
670 string track2 = mainWindow.drp_track2Audio.Text;
\r
671 string aencoder2 = mainWindow.drp_audenc_2.Text;
\r
672 string audioBitrate2 = mainWindow.drp_audbit_2.Text;
\r
673 string audioSampleRate2 = mainWindow.drp_audsr_2.Text;
\r
674 string Mixdown2 = mainWindow.drp_audmix_2.Text;
\r
675 string drc2 = mainWindow.trackBar2.Value.ToString();
\r
678 string track3 = mainWindow.drp_track3Audio.Text;
\r
679 string aencoder3 = mainWindow.drp_audenc_3.Text;
\r
680 string audioBitrate3 = mainWindow.drp_audbit_3.Text;
\r
681 string audioSampleRate3 = mainWindow.drp_audsr_3.Text;
\r
682 string Mixdown3 = mainWindow.drp_audmix_3.Text;
\r
683 string drc3 = mainWindow.trackBar3.Value.ToString();
\r
686 string track4 = mainWindow.drp_track4Audio.Text;
\r
687 string aencoder4 = mainWindow.drp_audenc_4.Text;
\r
688 string audioBitrate4 = mainWindow.drp_audbit_4.Text;
\r
689 string audioSampleRate4 = mainWindow.drp_audsr_4.Text;
\r
690 string Mixdown4 = mainWindow.drp_audmix_4.Text;
\r
691 string drc4 = mainWindow.trackBar4.Value.ToString();
\r
695 // Audio Track Selections
\r
697 if (track1 == "Automatic")
\r
699 else if (track1 != "None")
\r
701 string[] tempSub = track1.Split(' ');
\r
702 query += " -a " + tempSub[0];
\r
705 if (track2 == "Automatic")
\r
707 else if (track2 != "None")
\r
710 tempSub = track2.Split(' ');
\r
712 if (track1 == "None")
\r
713 query += " -a none," + tempSub[0];
\r
715 query += "," + tempSub[0];
\r
718 if (track3 != "None")
\r
721 tempSub = track3.Split(' ');
\r
722 query += "," + tempSub[0];
\r
725 if (track4 != "None")
\r
728 tempSub = track4.Split(' ');
\r
729 query += "," + tempSub[0];
\r
735 if (aencoder1 != "")
\r
736 query += " -E " + getAudioEncoder(aencoder1);
\r
738 if (aencoder2 != "")
\r
740 if (aencoder1 == string.Empty)
\r
741 query += " -E faac," + getAudioEncoder(aencoder2);
\r
743 query += "," + getAudioEncoder(aencoder2);
\r
746 if (aencoder3 != "")
\r
747 query += "," + getAudioEncoder(aencoder3);
\r
749 if (aencoder4 != "")
\r
750 query += "," + getAudioEncoder(aencoder4);
\r
753 // Audio Bitrate Selections
\r
755 if (audioBitrate1 != "")
\r
756 query += " -B " + audioBitrate1;
\r
758 if (audioBitrate2 != "")
\r
760 if (audioBitrate1 == string.Empty)
\r
761 query += " -B 160," + audioBitrate2;
\r
763 query += "," + audioBitrate2;
\r
766 if (audioBitrate3 != "")
\r
767 query += "," + audioBitrate3;
\r
769 if (audioBitrate4 != "")
\r
770 query += "," + audioBitrate4;
\r
773 //Audio Sample Rate - audioSampleRate
\r
774 if (audioSampleRate1 != "")
\r
775 query += " -R " + audioSampleRate1.Replace("Auto", "0");
\r
777 if (audioSampleRate2 != "")
\r
779 if (audioSampleRate1 == string.Empty)
\r
780 query += " -R 0," + audioSampleRate2.Replace("Auto", "0");
\r
782 query += "," + audioSampleRate2.Replace("Auto", "0");
\r
786 // All this is a hack, because when AppleTV is selected, there is no sample rate selected. so just add a 48
\r
787 // It should probably be setup later so the GUI widget has the value 48 in it.
\r
789 if ((track2 != "") && (track2 != "None"))
\r
791 if (audioSampleRate1 == string.Empty)
\r
792 query += " -R 0,0";
\r
798 if (audioSampleRate3 != "")
\r
799 query += "," + audioSampleRate3.Replace("Auto", "0");
\r
801 if (audioSampleRate4 != "")
\r
802 query += "," + audioSampleRate4.Replace("Auto", "0");
\r
805 // Audio Mixdown Selections
\r
808 if (Mixdown1 != "")
\r
809 query += " -6 " + getMixDown(Mixdown1);
\r
811 query += " -6 dpl2";
\r
813 if (Mixdown2 != "" && track2 != "None")
\r
814 query += "," + getMixDown(Mixdown2);
\r
816 if (Mixdown3 != "" && track3 != "None" && track2 != "None")
\r
817 query += "," + getMixDown(Mixdown3);
\r
819 if (Mixdown4 != "" && track4 != "None" && track3 != "None")
\r
820 query += "," + getMixDown(Mixdown4);
\r
828 value = mainWindow.trackBar1.Value / 10.0;
\r
832 query += " -D " + value;
\r
836 value = mainWindow.trackBar2.Value / 10.0;
\r
838 if (track2 != "None" && drc2 != "0")
\r
839 query += "," + value;
\r
840 else if (track2 != "None" && drc2 == "0")
\r
843 value = mainWindow.trackBar3.Value / 10.0;
\r
845 if (track3 != "None" && drc3 != "0")
\r
846 query += "," + value;
\r
847 else if (track3 != "None" && drc3 == "0")
\r
850 value = mainWindow.trackBar4.Value / 10.0;
\r
852 if (track4 != "None" && drc4 != "0")
\r
853 query += "," + value;
\r
854 else if (track4 != "None" && drc4 == "0")
\r
858 string subtitles = mainWindow.drp_subtitle.Text;
\r
859 if (subtitles == "Autoselect")
\r
861 else if (subtitles != "" && subtitles != "None")
\r
864 tempSub = subtitles.Split(' ');
\r
865 query += " -s " + tempSub[0];
\r
868 if (mainWindow.check_forced.Checked)
\r
873 // Chapter Markers Tab
\r
874 #region Chapter Markers
\r
876 // Attach Source name and dvd title to the start of the chapters.csv filename.
\r
877 // This is for the queue. It allows different chapter name files for each title.
\r
878 string source_name = mainWindow.text_source.Text;
\r
879 string[] sourceName = source.Split('\\');
\r
880 source_name = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");
\r
881 source_name = source_name.Replace("\"", "");
\r
883 string source_title = mainWindow.drp_dvdtitle.Text;
\r
884 string[] titlesplit = source_title.Split(' ');
\r
885 source_title = titlesplit[0];
\r
887 if (mainWindow.Check_ChapterMarkers.Checked)
\r
889 if ((source_name.Trim().Replace("-i ", "") != "Click 'Browse' to continue") && (source_name.Trim().Replace("-i ", "") != ""))
\r
891 if (source_title != "Automatic")
\r
893 string filename = source_name + "-" + source_title + "-chapters.csv";
\r
894 string path = Path.Combine(Path.GetTempPath(), filename);
\r
896 Boolean saveCSV = chapterCSVSave(mainWindow, path);
\r
897 if (saveCSV == false)
\r
900 query += " --markers=" + "\"" + path + "\"";
\r
904 string filename = source_name + "-chapters.csv";
\r
905 string path = Path.Combine(Path.GetTempPath(), filename);
\r
907 Boolean saveCSV = chapterCSVSave(mainWindow, path);
\r
908 if (saveCSV == false)
\r
911 query += " --markers=" + "\"" + path + "\"";
\r
916 string path = Path.Combine(Path.GetTempPath(), "chapters.csv");
\r
917 query += " --markers=" + "\"" + path + "\"";
\r
924 if (mainWindow.rtf_x264Query.Text != "")
\r
925 query += " -x " + mainWindow.rtf_x264Query.Text;
\r
929 #region Processors / Other
\r
930 string processors = Properties.Settings.Default.Processors;
\r
931 if (processors != "Automatic")
\r
932 query += " -C " + processors + " ";
\r
941 /// Get the CLI equive of the audio mixdown from the widget name.
\r
943 /// <param name="selectedAudio"></param>
\r
944 /// <returns></returns>
\r
946 private string getMixDown(string selectedAudio)
\r
948 switch (selectedAudio)
\r
956 case "Dolby Surround":
\r
958 case "Dolby Pro Logic II":
\r
960 case "6 Channel Discrete":
\r
968 /// Get the CLI equiv of the audio encoder from the widget name.
\r
970 /// <param name="selectedEncoder"></param>
\r
971 /// <returns></returns>
\r
973 private string getAudioEncoder(string selectedEncoder)
\r
975 switch (selectedEncoder)
\r
991 /// This function saves the data in the chapters tab, dataGridView into a CSV file called chapters.csv
\r
992 /// in a directory specified by file_path_name
\r
994 /// <param name="mainWindow"></param>
\r
995 /// <param name="file_path_name"></param>
\r
996 /// <returns></returns>
\r
997 private Boolean chapterCSVSave(frmMain mainWindow, string file_path_name)
\r
1001 StringBuilder csv = new StringBuilder();
\r
1003 foreach (DataGridViewRow row in mainWindow.data_chpt.Rows)
\r
1005 csv.Append(row.Cells[0].Value.ToString());
\r
1007 csv.Append(row.Cells[1].Value.ToString());
\r
1008 csv.Append(Environment.NewLine);
\r
1010 StreamWriter file = new StreamWriter(file_path_name);
\r
1011 file.Write(csv.ToString());
\r
1017 catch (Exception exc)
\r
1019 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
1026 #region Actions, Versioning etc
\r
1029 /// Select the longest title in the DVD title dropdown menu on frmMain
\r
1031 public void selectLongestTitle(frmMain mainWindow)
\r
1033 int current_largest = 0;
\r
1034 Handbrake.Parsing.Title title2Select;
\r
1036 // Check if there are titles in the DVD title dropdown menu and make sure, it's not just "Automatic"
\r
1037 if (mainWindow.drp_dvdtitle.Items[0].ToString() != "Automatic")
\r
1038 title2Select = (Handbrake.Parsing.Title)mainWindow.drp_dvdtitle.Items[0];
\r
1040 title2Select = null;
\r
1042 // So, If there are titles in the DVD Title dropdown menu, lets select the longest.
\r
1043 if (title2Select != null)
\r
1045 foreach (Handbrake.Parsing.Title x in mainWindow.drp_dvdtitle.Items)
\r
1047 string title = x.ToString();
\r
1048 if (title != "Automatic")
\r
1050 string[] y = title.Split(' ');
\r
1051 string time = y[1].Replace("(", "").Replace(")", "");
\r
1052 string[] z = time.Split(':');
\r
1054 int hours = int.Parse(z[0]) * 60 * 60;
\r
1055 int minutes = int.Parse(z[1]) * 60;
\r
1056 int seconds = int.Parse(z[2]);
\r
1057 int total_sec = hours + minutes + seconds;
\r
1059 if (current_largest == 0)
\r
1061 current_largest = hours + minutes + seconds;
\r
1066 if (total_sec > current_largest)
\r
1068 current_largest = total_sec;
\r
1075 // Now set the longest title in the gui.
\r
1076 mainWindow.drp_dvdtitle.SelectedItem = title2Select;
\r
1081 /// Set's up the DataGridView on the Chapters tab (frmMain)
\r
1083 /// <param name="mainWindow"></param>
\r
1084 public void chapterNaming(frmMain mainWindow)
\r
1088 mainWindow.data_chpt.Rows.Clear();
\r
1093 if (mainWindow.drop_chapterFinish.Text != "Auto")
\r
1094 finish = int.Parse(mainWindow.drop_chapterFinish.Text);
\r
1096 if (mainWindow.drop_chapterStart.Text != "Auto")
\r
1097 start = int.Parse(mainWindow.drop_chapterStart.Text);
\r
1099 rowCount = finish - (start - 1);
\r
1101 while (i < rowCount)
\r
1103 DataGridViewRow row = new DataGridViewRow();
\r
1105 mainWindow.data_chpt.Rows.Insert(i, row);
\r
1106 mainWindow.data_chpt.Rows[i].Cells[0].Value = (i + 1);
\r
1107 mainWindow.data_chpt.Rows[i].Cells[1].Value = "Chapter " + (i + 1);
\r
1111 catch (Exception exc)
\r
1113 MessageBox.Show("chapterNaming() Error has occured: \n" + exc.ToString());
\r
1118 /// Function which generates the filename and path automatically based on
\r
1119 /// the Source Name, DVD title and DVD Chapters
\r
1121 /// <param name="mainWindow"></param>
\r
1122 public void autoName(frmMain mainWindow)
\r
1124 if (Properties.Settings.Default.autoNaming == "Checked")
\r
1126 if (mainWindow.drp_dvdtitle.Text != "Automatic")
\r
1128 // Todo: This code is a tad messy. Clean it up at some point.
\r
1129 // Get the Source Name
\r
1130 string source = mainWindow.text_source.Text;
\r
1131 string[] sourceName = source.Split('\\');
\r
1132 source = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");
\r
1134 // Get the Selected Title Number
\r
1135 string title = mainWindow.drp_dvdtitle.Text;
\r
1136 string[] titlesplit = title.Split(' ');
\r
1137 title = titlesplit[0];
\r
1139 // Get the Chapter Start and Chapter End Numbers
\r
1140 string cs = mainWindow.drop_chapterStart.Text;
\r
1141 string cf = mainWindow.drop_chapterFinish.Text;
\r
1143 // Just incase the above are set to their default Automatic values, set the varible to ""
\r
1144 if (title == "Automatic")
\r
1151 // If both CS and CF are populated, set the dash varible
\r
1156 // Get the destination filename.
\r
1157 string destination_filename = "";
\r
1158 if (Properties.Settings.Default.autoNameFormat != "")
\r
1160 destination_filename = Properties.Settings.Default.autoNameFormat;
\r
1161 destination_filename = destination_filename.Replace("{source}", source).Replace("{title}", title).Replace("{chapters}", cs + dash + cf);
\r
1164 destination_filename = source + "_T" + title + "_C" + cs + dash + cf;
\r
1166 // If the text box is blank
\r
1167 if (!mainWindow.text_destination.Text.Contains("\\"))
\r
1169 string filePath = "";
\r
1170 if (Properties.Settings.Default.autoNamePath.Trim() != "")
\r
1172 if (Properties.Settings.Default.autoNamePath.Trim() != "Click 'Browse' to set the default location")
\r
1173 filePath = Properties.Settings.Default.autoNamePath + "\\";
\r
1175 mainWindow.text_destination.Text = filePath + destination_filename + ".mp4";
\r
1177 else // If the text box already has a path and file
\r
1179 string dest = mainWindow.text_destination.Text;
\r
1180 string[] destName = dest.Split('\\');
\r
1181 string[] extension = dest.Split('.');
\r
1182 string ext = extension[extension.Length - 1];
\r
1184 destName[destName.Length - 1] = destination_filename + "." + ext;
\r
1186 string fullDest = "";
\r
1187 foreach (string part in destName)
\r
1189 if (fullDest != "")
\r
1190 fullDest = fullDest + "\\" + part;
\r
1192 fullDest = fullDest + part;
\r
1195 mainWindow.text_destination.Text = fullDest;
\r
1202 /// Checks for updates and returns true if an update is available.
\r
1204 /// <param name="debug">Turns on debug mode. Don't use on program startup</param>
\r
1205 /// <returns>Boolean True = Update available</returns>
\r
1206 public Boolean updateCheck(Boolean debug)
\r
1210 Functions.AppcastReader rssRead = new Functions.AppcastReader();
\r
1211 string build = rssRead.build();
\r
1213 int latest = int.Parse(build);
\r
1214 int current = Properties.Settings.Default.hb_build;
\r
1215 int skip = Properties.Settings.Default.skipversion;
\r
1217 if (latest == skip)
\r
1221 Boolean update = (latest > current);
\r
1225 catch (Exception exc)
\r
1227 if (debug == true)
\r
1228 MessageBox.Show("Unable to check for updates, Please try again later. \n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
1234 /// Get's HandBrakes version data from the CLI.
\r
1236 /// <returns>Arraylist of Version Data. 0 = hb_version 1 = hb_build</returns>
\r
1237 public ArrayList getCliVersionData()
\r
1239 ArrayList cliVersionData = new ArrayList();
\r
1240 // 0 = SVN Build / Version
\r
1243 Process cliProcess = new Process();
\r
1244 ProcessStartInfo handBrakeCLI = new ProcessStartInfo("HandBrakeCLI.exe", " -u");
\r
1245 handBrakeCLI.UseShellExecute = false;
\r
1246 handBrakeCLI.RedirectStandardError = true;
\r
1247 handBrakeCLI.RedirectStandardOutput = true;
\r
1248 handBrakeCLI.CreateNoWindow = true;
\r
1249 cliProcess.StartInfo = handBrakeCLI;
\r
1250 cliProcess.Start();
\r
1252 // Retrieve standard output and report back to parent thread until the process is complete
\r
1254 TextReader stdOutput = cliProcess.StandardError;
\r
1256 while (!cliProcess.HasExited)
\r
1258 line = stdOutput.ReadLine();
\r
1259 Match m = Regex.Match(line, @"HandBrake [0-9\.]*svn[0-9]*[M]* \([0-9]*\)");
\r
1260 if (m.Success != false)
\r
1262 string data = line.Replace("(", "").Replace(")", "").Replace("HandBrake ", "");
\r
1263 string[] arr = data.Split(' ');
\r
1264 cliVersionData.Add(arr[0]);
\r
1265 cliVersionData.Add(arr[1]);
\r
1266 return cliVersionData;
\r
1273 /// Check if the queue recovery file contains records.
\r
1274 /// If it does, it means the last queue did not complete before HandBrake closed.
\r
1275 /// So, return a boolean if true.
\r
1277 public Boolean check_queue_recovery()
\r
1281 string tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");
\r
1282 using (StreamReader reader = new StreamReader(tempPath))
\r
1284 string queue_item = reader.ReadLine();
\r
1285 if (queue_item == null)
\r
1291 else // There exists an item in the recovery queue file, so try and recovr it.
\r
1301 // Keep quiet about the error.
\r