2 using System.Collections.Generic;
\r
3 using System.ComponentModel;
\r
5 using System.Drawing;
\r
7 using System.Windows.Forms;
\r
10 using System.Diagnostics;
\r
11 using System.Threading;
\r
15 public partial class frmMain : Form
\r
17 private Process hbProc;
\r
18 private Parsing.DVD thisDVD;
\r
20 // --------------------------------------------------------------
\r
21 // Some windows that require only 1 instance.
\r
22 // --------------------------------------------------------------
\r
23 private frmQueue queueWindow = new frmQueue();
\r
25 // --------------------------------------------------------------
\r
26 // Stuff that needs doing on startup.
\r
27 // - Load users default settings. (if required)
\r
28 // - Do an update check (if required)
\r
29 // --------------------------------------------------------------
\r
33 InitializeComponent();
\r
35 // Set the Version number lable to the corect version.
\r
36 Version.Text = "Version " + Properties.Settings.Default.GuiVersion;
\r
38 // Run the update checker.
\r
41 // Now load the users default if required.
\r
45 public void loadUserDefaults()
\r
49 if (Properties.Settings.Default.defaultSettings == "Checked")
\r
52 text_source.Text = Properties.Settings.Default.DVDSource;
\r
53 drp_dvdtitle.Text = Properties.Settings.Default.DVDTitle;
\r
54 drop_chapterStart.Text = Properties.Settings.Default.ChapterStart;
\r
55 drop_chapterFinish.Text = Properties.Settings.Default.ChapterFinish;
\r
58 text_destination.Text = Properties.Settings.Default.VideoDest;
\r
59 drp_videoEncoder.Text = Properties.Settings.Default.VideoEncoder;
\r
60 drp_audioCodec.Text = Properties.Settings.Default.AudioEncoder;
\r
61 text_width.Text = Properties.Settings.Default.Width;
\r
62 text_height.Text = Properties.Settings.Default.Height;
\r
64 // Picture Settings Tab
\r
65 drp_crop.Text = Properties.Settings.Default.CroppingOption;
\r
66 text_top.Text = Properties.Settings.Default.CropTop;
\r
67 text_bottom.Text = Properties.Settings.Default.CropBottom;
\r
68 text_left.Text = Properties.Settings.Default.CropLeft;
\r
69 text_right.Text = Properties.Settings.Default.CropRight;
\r
70 drp_subtitle.Text = Properties.Settings.Default.Subtitles;
\r
72 // Video Settings Tab
\r
73 text_bitrate.Text = Properties.Settings.Default.VideoBitrate;
\r
74 text_filesize.Text = Properties.Settings.Default.VideoFilesize;
\r
75 slider_videoQuality.Value = Properties.Settings.Default.VideoQuality;
\r
77 if (Properties.Settings.Default.TwoPass == "Checked")
\r
79 check_2PassEncode.CheckState = CheckState.Checked;
\r
81 if (Properties.Settings.Default.DeInterlace == "Checked")
\r
83 check_DeInterlace.CheckState = CheckState.Checked;
\r
85 if (Properties.Settings.Default.Grayscale == "Checked")
\r
87 check_grayscale.CheckState = CheckState.Checked;
\r
90 drp_videoFramerate.Text = Properties.Settings.Default.Framerate;
\r
92 if (Properties.Settings.Default.PixelRatio == "Checked")
\r
94 CheckPixelRatio.CheckState = CheckState.Checked;
\r
96 if (Properties.Settings.Default.turboFirstPass == "Checked")
\r
98 check_turbo.CheckState = CheckState.Checked;
\r
100 if (Properties.Settings.Default.largeFile == "Checked")
\r
102 check_largeFile.CheckState = CheckState.Checked;
\r
104 // Audio Settings Tab
\r
105 drp_audioBitrate.Text = Properties.Settings.Default.AudioBitrate;
\r
106 drp_audioSampleRate.Text = Properties.Settings.Default.AudioSampleRate;
\r
107 drp_audioChannels.Text = Properties.Settings.Default.AudioChannels;
\r
110 if (Properties.Settings.Default.CRF == "Checked")
\r
112 CheckCRF.CheckState = CheckState.Checked;
\r
114 rtf_h264advanced.Text = Properties.Settings.Default.H264;
\r
119 // No real need to alert the user. Try/Catch only in just incase there is a problem reading the settings xml file.
\r
123 public void updateCheck()
\r
125 if (Properties.Settings.Default.updateStatus == "Checked")
\r
129 String updateFile = Properties.Settings.Default.updateFile;
\r
130 WebClient client = new WebClient();
\r
131 String data = client.DownloadString(updateFile);
\r
132 String[] versionData = data.Split('\n');
\r
134 if ((versionData[0] != Properties.Settings.Default.GuiVersion) || (versionData[1] != Properties.Settings.Default.CliVersion))
\r
136 lbl_update.Visible = true;
\r
141 // Silently ignore the error
\r
146 // --------------------------------------------------------------
\r
147 // The main Menu bar.
\r
148 // --------------------------------------------------------------
\r
152 private void mnu_open_Click(object sender, EventArgs e)
\r
155 File_Open.ShowDialog();
\r
156 filename = File_Open.FileName;
\r
157 if (filename != "")
\r
161 // Create StreamReader & open file
\r
162 StreamReader line = new StreamReader(filename);
\r
163 string temporyLine; // Used for reading the line into a varible before processing on the checkState items below.
\r
165 // Read in the data and set the correct GUI component with the setting.
\r
166 text_source.Text = line.ReadLine();
\r
167 drp_dvdtitle.Text = line.ReadLine();
\r
168 drop_chapterStart.Text = line.ReadLine();
\r
169 drop_chapterFinish.Text = line.ReadLine();
\r
170 text_destination.Text = line.ReadLine();
\r
171 drp_videoEncoder.Text = line.ReadLine();
\r
172 drp_audioCodec.Text = line.ReadLine();
\r
173 text_width.Text = line.ReadLine();
\r
174 text_height.Text = line.ReadLine();
\r
175 text_top.Text = line.ReadLine();
\r
176 text_bottom.Text = line.ReadLine();
\r
177 text_left.Text = line.ReadLine();
\r
178 text_right.Text = line.ReadLine();
\r
179 drp_subtitle.Text = line.ReadLine();
\r
180 text_bitrate.Text = line.ReadLine();
\r
181 text_filesize.Text = line.ReadLine();
\r
182 slider_videoQuality.Value = int.Parse(line.ReadLine());
\r
184 temporyLine = line.ReadLine();
\r
185 if (temporyLine == "Checked")
\r
187 check_2PassEncode.CheckState = CheckState.Checked;
\r
190 temporyLine = line.ReadLine();
\r
191 if (temporyLine == "Checked")
\r
193 check_DeInterlace.CheckState = CheckState.Checked;
\r
196 temporyLine = line.ReadLine();
\r
197 if (temporyLine == "Checked")
\r
199 check_grayscale.CheckState = CheckState.Checked;
\r
202 drp_videoFramerate.Text = line.ReadLine();
\r
204 temporyLine = line.ReadLine();
\r
205 if (temporyLine == "Checked")
\r
207 Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
210 temporyLine = line.ReadLine();
\r
211 if (temporyLine == "Checked")
\r
213 CheckPixelRatio.CheckState = CheckState.Checked;
\r
216 temporyLine = line.ReadLine();
\r
217 if (temporyLine == "Checked")
\r
219 check_turbo.CheckState = CheckState.Checked;
\r
222 temporyLine = line.ReadLine();
\r
223 if (temporyLine == "Checked")
\r
225 check_largeFile.CheckState = CheckState.Checked;
\r
228 drp_audioBitrate.Text = line.ReadLine();
\r
229 drp_audioSampleRate.Text = line.ReadLine();
\r
230 drp_audioChannels.Text = line.ReadLine();
\r
231 drp_audioMixDown.Text = line.ReadLine();
\r
233 // Advanced H264 Options
\r
234 temporyLine = line.ReadLine();
\r
235 if (temporyLine == "Checked")
\r
237 CheckCRF.CheckState = CheckState.Checked;
\r
239 rtf_h264advanced.Text = line.ReadLine();
\r
241 // Close the stream
\r
245 // Fix for SliderValue not appearing when Opening saved file
\r
246 SliderValue.Text = slider_videoQuality.Value + "%";
\r
248 } catch (Exception){
\r
249 MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
254 private void mnu_save_Click(object sender, EventArgs e)
\r
258 File_Save.ShowDialog();
\r
259 filename = File_Save.FileName;
\r
260 if (filename != "")
\r
264 // Create a StreamWriter and open the file
\r
265 StreamWriter line = new StreamWriter(filename);
\r
268 line.WriteLine(text_source.Text);
\r
269 line.WriteLine(drp_dvdtitle.Text);
\r
270 line.WriteLine(drop_chapterStart.Text);
\r
271 line.WriteLine(drop_chapterFinish.Text);
\r
273 line.WriteLine(text_destination.Text);
\r
274 line.WriteLine(drp_videoEncoder.Text);
\r
275 line.WriteLine(drp_audioCodec.Text);
\r
276 line.WriteLine(text_width.Text);
\r
277 line.WriteLine(text_height.Text);
\r
278 //Picture Settings Tab
\r
279 line.WriteLine(text_top.Text);
\r
280 line.WriteLine(text_bottom.Text);
\r
281 line.WriteLine(text_left.Text);
\r
282 line.WriteLine(text_right.Text);
\r
283 line.WriteLine(drp_subtitle.Text);
\r
284 //Video Settings Tab
\r
285 line.WriteLine(text_bitrate.Text);
\r
286 line.WriteLine(text_filesize.Text);
\r
287 line.WriteLine(slider_videoQuality.Value.ToString());
\r
288 line.WriteLine(check_2PassEncode.CheckState.ToString());
\r
289 line.WriteLine(check_DeInterlace.CheckState.ToString());
\r
290 line.WriteLine(check_grayscale.CheckState.ToString());
\r
291 line.WriteLine(drp_videoFramerate.Text);
\r
292 line.WriteLine(Check_ChapterMarkers.CheckState.ToString());
\r
293 line.WriteLine(CheckPixelRatio.CheckState.ToString());
\r
294 line.WriteLine(check_turbo.CheckState.ToString());
\r
295 line.WriteLine(check_largeFile.CheckState.ToString());
\r
296 //Audio Settings Tab
\r
297 line.WriteLine(drp_audioBitrate.Text);
\r
298 line.WriteLine(drp_audioSampleRate.Text);
\r
299 line.WriteLine(drp_audioChannels.Text);
\r
300 line.WriteLine(drp_audioMixDown.Text);
\r
302 line.WriteLine(CheckCRF.CheckState.ToString());
\r
303 line.WriteLine(rtf_h264advanced.Text);
\r
304 // close the stream
\r
306 MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
310 MessageBox.Show("Unable to write to the file. Please make sure the location has the correct permissions for file writing.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
316 private void mnu_update_Click(object sender, EventArgs e)
\r
318 Form Update = new frmUpdate();
\r
319 Update.ShowDialog();
\r
322 private void mnu_exit_Click(object sender, EventArgs e)
\r
331 private void mnu_encode_Click(object sender, EventArgs e)
\r
336 private frmDvdInfo dvdInfoWindow = new frmDvdInfo();
\r
337 private void mnu_viewDVDdata_Click(object sender, EventArgs e)
\r
339 dvdInfoWindow.Show();
\r
341 // BUG *******************************************************
\r
342 // Cross-thread operation not valid: Control 'rtf_dvdInfo' accessed from a thread other than the thread it was created on.
\r
343 // This happens when the DVD is scanned and this item is then selected.
\r
344 // If this item is selected so a blank copy of the window appears, then a DVD is scanned, there is no cross-thread issue.
\r
345 // ***********************************************************
\r
349 private void mnu_options_Click(object sender, EventArgs e)
\r
351 Form Options = new frmOptions();
\r
352 Options.ShowDialog();
\r
357 #region Presets Menu
\r
359 private void mnu_preset_ipod133_Click(object sender, EventArgs e)
\r
361 CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
362 text_width.Text = "640";
\r
363 text_height.Text = "480";
\r
364 drp_videoEncoder.Text = "H.264 (iPod)";
\r
365 text_bitrate.Text = "1000";
\r
366 text_filesize.Text = "";
\r
367 slider_videoQuality.Value = 0;
\r
368 SliderValue.Text = "0%";
\r
369 drp_audioBitrate.Text = "160";
\r
370 rtf_h264advanced.Text = "";
\r
371 drp_crop.Text = "No Crop";
\r
374 private void mnu_preset_ipod178_Click(object sender, EventArgs e)
\r
376 CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
377 text_width.Text = "640";
\r
378 text_height.Text = "352";
\r
379 drp_videoEncoder.Text = "H.264 (iPod)";
\r
380 text_bitrate.Text = "1000";
\r
381 text_filesize.Text = "";
\r
382 slider_videoQuality.Value = 0;
\r
383 SliderValue.Text = "0%";
\r
384 drp_audioBitrate.Text = "160";
\r
385 rtf_h264advanced.Text = "";
\r
386 drp_crop.Text = "No Crop";
\r
389 private void mnu_preset_ipod235_Click(object sender, EventArgs e)
\r
391 CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
392 text_width.Text = "640";
\r
393 text_height.Text = "272";
\r
394 drp_videoEncoder.Text = "H.264 (iPod)";
\r
395 text_bitrate.Text = "1000";
\r
396 text_filesize.Text = "";
\r
397 slider_videoQuality.Value = 0;
\r
398 SliderValue.Text = "0%";
\r
399 drp_audioBitrate.Text = "160";
\r
400 rtf_h264advanced.Text = "";
\r
401 drp_crop.Text = "No Crop";
\r
404 private void mnu_appleTv_Click(object sender, EventArgs e)
\r
406 text_width.Text = "";
\r
407 text_height.Text = "";
\r
408 drp_videoEncoder.Text = "H.264";
\r
409 text_bitrate.Text = "3000";
\r
410 text_filesize.Text = "";
\r
411 slider_videoQuality.Value = 0;
\r
412 SliderValue.Text = "0%";
\r
413 drp_audioBitrate.Text = "160";
\r
414 CheckPixelRatio.CheckState = CheckState.Checked;
\r
415 drp_audioSampleRate.Text = "48";
\r
416 rtf_h264advanced.Text = "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";
\r
417 drp_crop.Text = "No Crop";
\r
421 private void mnu_presetPS3_Click(object sender, EventArgs e)
\r
423 CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
424 text_width.Text = "";
\r
425 text_height.Text = "";
\r
426 drp_videoEncoder.Text = "H.264";
\r
427 text_bitrate.Text = "3000";
\r
428 text_filesize.Text = "";
\r
429 slider_videoQuality.Value = 0;
\r
430 SliderValue.Text = "0%";
\r
431 drp_audioBitrate.Text = "160";
\r
432 CheckPixelRatio.CheckState = CheckState.Checked;
\r
433 drp_audioSampleRate.Text = "48";
\r
434 rtf_h264advanced.Text = "level=41";
\r
435 drp_crop.Text = "No Crop";
\r
438 private void mnu_ProgramDefaultOptions_Click(object sender, EventArgs e)
\r
441 Properties.Settings.Default.DVDSource = text_source.Text;
\r
442 Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;
\r
443 Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;
\r
444 Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;
\r
446 Properties.Settings.Default.VideoDest = text_destination.Text;
\r
447 Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;
\r
448 Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;
\r
449 Properties.Settings.Default.Width = text_width.Text;
\r
450 Properties.Settings.Default.Height = text_height.Text;
\r
451 //Picture Settings Tab
\r
452 Properties.Settings.Default.CroppingOption = drp_crop.Text;
\r
453 Properties.Settings.Default.CropTop = text_top.Text;
\r
454 Properties.Settings.Default.CropBottom = text_bottom.Text;
\r
455 Properties.Settings.Default.CropLeft = text_left.Text;
\r
456 Properties.Settings.Default.CropRight = text_right.Text;
\r
457 Properties.Settings.Default.Subtitles = drp_subtitle.Text;
\r
458 //Video Settings Tab
\r
459 Properties.Settings.Default.VideoBitrate = text_bitrate.Text;
\r
460 Properties.Settings.Default.VideoFilesize = text_filesize.Text;
\r
461 Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;
\r
462 Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();
\r
463 Properties.Settings.Default.DeInterlace = check_DeInterlace.CheckState.ToString();
\r
464 Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();
\r
465 Properties.Settings.Default.Framerate = drp_videoFramerate.Text;
\r
466 Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();
\r
467 Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();
\r
468 Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString();
\r
469 //Audio Settings Tab
\r
470 Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;
\r
471 Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;
\r
472 Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;
\r
474 Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();
\r
475 Properties.Settings.Default.H264 = rtf_h264advanced.Text;
\r
476 Properties.Settings.Default.Save();
\r
483 private void mnu_wiki_Click(object sender, EventArgs e)
\r
485 Process.Start("http://handbrake.m0k.org/trac");
\r
488 private void mnu_onlineDocs_Click(object sender, EventArgs e)
\r
490 Process.Start("http://handbrake.m0k.org/?page_id=11");
\r
493 private void mnu_faq_Click(object sender, EventArgs e)
\r
495 Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");
\r
498 private void mnu_homepage_Click(object sender, EventArgs e)
\r
500 Process.Start("http://handbrake.m0k.org");
\r
503 private void mnu_forum_Click(object sender, EventArgs e)
\r
505 Process.Start("http://handbrake.m0k.org/forum");
\r
508 private void mnu_about_Click(object sender, EventArgs e)
\r
510 Form About = new frmAbout();
\r
511 About.ShowDialog();
\r
516 // --------------------------------------------------------------
\r
517 // Buttons on the main Window
\r
518 // --------------------------------------------------------------
\r
519 private void btn_Browse_Click(object sender, EventArgs e)
\r
522 String filename ="";
\r
523 text_source.Text = "";
\r
525 if (RadioDVD.Checked)
\r
527 DVD_Open.ShowDialog();
\r
528 filename = DVD_Open.SelectedPath;
\r
529 if (filename != "")
\r
531 text_source.Text = filename;
\r
532 Form frmReadDVD = new frmReadDVD(filename, this, dvdInfoWindow);
\r
533 frmReadDVD.ShowDialog();
\r
538 ISO_Open.ShowDialog();
\r
539 filename = ISO_Open.FileName;
\r
540 if (filename != "")
\r
542 text_source.Text = filename;
\r
543 Form frmReadDVD = new frmReadDVD(filename, this, dvdInfoWindow);
\r
544 frmReadDVD.ShowDialog();
\r
548 // Quick check to make sure some titles were found.
\r
549 if (filename != "")
\r
551 if (drp_dvdtitle.Items.Count == 0)
\r
553 MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
558 text_source.Text = "Click 'Browse' to continue";
\r
563 private void btn_destBrowse_Click(object sender, EventArgs e)
\r
565 // TODO: Need to write some code to check if there is a reasonable amount of disk space left.
\r
567 DVD_Save.ShowDialog();
\r
568 text_destination.Text = DVD_Save.FileName;
\r
570 if (Check_ChapterMarkers.Checked)
\r
572 string destination = text_destination.Text;
\r
573 destination = destination.Replace(".mp4", ".m4v");
\r
574 text_destination.Text = destination;
\r
578 private void btn_h264Clear_Click(object sender, EventArgs e)
\r
580 rtf_h264advanced.Text = "";
\r
583 private void GenerateQuery_Click(object sender, EventArgs e)
\r
585 String query = GenerateTheQuery();
\r
586 QueryEditorText.Text = query;
\r
589 private void btn_ClearQuery_Click(object sender, EventArgs e)
\r
591 QueryEditorText.Text = "";
\r
594 private void btn_queue_Click(object sender, EventArgs e)
\r
596 String query = GenerateTheQuery();
\r
597 queueWindow.list_queue.Items.Add(query);
\r
598 queueWindow.Show();
\r
601 private void showQueue()
\r
603 queueWindow.Show();
\r
606 private void btn_encode_Click(object sender, EventArgs e)
\r
609 lbl_encode.Visible = true;
\r
611 if (QueryEditorText.Text == "")
\r
613 query = GenerateTheQuery();
\r
617 query = QueryEditorText.Text;
\r
620 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
623 private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)
\r
625 if (this.InvokeRequired)
\r
627 this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),
\r
628 new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });
\r
631 lbl_encode.Text = string.Format("Encode Progress: {0}%, FPS: {1}, Avg FPS: {2}, Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);
\r
634 private void procMonitor(object state)
\r
636 Functions.CLI process = new Functions.CLI();
\r
637 hbProc = process.runCli(this, (string)state, true, true, false, true);
\r
639 MessageBox.Show("The encode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
641 Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);
\r
642 //TODO: prevent this event from being subscribed more than once
\r
643 encode.OnEncodeProgress += encode_OnEncodeProgress;
\r
644 while (!encode.EndOfStream)
\r
650 hbProc.WaitForExit();
\r
654 MessageBox.Show("The encode process has now ended.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
657 //---------------------------------------------------
\r
658 // Items that require actions on frmMain
\r
659 //---------------------------------------------------
\r
661 private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)
\r
663 lbl_chptWarn.Visible = false;
\r
664 QueryEditorText.Text = "";
\r
665 if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))
\r
669 int chapterFinish = int.Parse(drop_chapterFinish.Text);
\r
670 int chapterStart = int.Parse(drop_chapterStart.Text);
\r
672 if (chapterFinish < chapterStart)
\r
674 lbl_chptWarn.Visible = true;
\r
675 lbl_chptWarn.Text = "Invalid Chapter Range!";
\r
680 lbl_chptWarn.Visible = true;
\r
681 lbl_chptWarn.Text = "Invalid Chapter Range!";
\r
688 private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)
\r
690 lbl_chptWarn.Visible = false;
\r
691 QueryEditorText.Text = "";
\r
692 if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))
\r
696 int chapterFinish = int.Parse(drop_chapterFinish.Text);
\r
697 int chapterStart = int.Parse(drop_chapterStart.Text);
\r
699 if (chapterFinish < chapterStart)
\r
701 lbl_chptWarn.Visible = true;
\r
702 lbl_chptWarn.Text = "Invalid Chapter Range!";
\r
707 lbl_chptWarn.Visible = true;
\r
708 lbl_chptWarn.Text = "Invalid Chapter Range!";
\r
713 private void text_bitrate_TextChanged(object sender, EventArgs e)
\r
715 text_filesize.Text = "";
\r
716 slider_videoQuality.Value = 0;
\r
717 SliderValue.Text = "0%";
\r
718 CheckCRF.CheckState = CheckState.Unchecked;
\r
721 private void text_filesize_TextChanged(object sender, EventArgs e)
\r
723 text_bitrate.Text = "";
\r
724 slider_videoQuality.Value = 0;
\r
725 SliderValue.Text = "0%";
\r
726 CheckCRF.CheckState = CheckState.Unchecked;
\r
729 private void slider_videoQuality_Scroll(object sender, EventArgs e)
\r
731 SliderValue.Text = slider_videoQuality.Value.ToString() + "%";
\r
732 text_bitrate.Text = "";
\r
733 text_filesize.Text = "";
\r
736 private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
738 Process.Start("http://handbrake.m0k.org/trac/wiki/x264Options");
\r
741 private void text_width_TextChanged(object sender, EventArgs e)
\r
746 if (CheckPixelRatio.Checked)
\r
748 text_width.Text = "";
\r
749 text_width.BackColor = Color.White;
\r
753 if ((int.Parse(text_width.Text) % 16) != 0)
\r
755 text_width.BackColor = Color.LightCoral;
\r
759 text_width.BackColor = Color.LightGreen;
\r
763 if (lbl_Aspect.Text != "Select a Title")
\r
765 double height = int.Parse(text_width.Text) / double.Parse(lbl_Aspect.Text);
\r
766 double mod16 = height % 16;
\r
767 height = height - mod16;
\r
769 if (text_width.Text == "")
\r
771 text_height.Text = "";
\r
772 text_width.BackColor = Color.White;
\r
776 text_height.Text = height.ToString();
\r
782 // No need to throw an error here.
\r
788 private void text_height_TextChanged(object sender, EventArgs e)
\r
792 if (CheckPixelRatio.Checked)
\r
794 text_height.Text = "";
\r
795 text_width.BackColor = Color.White;
\r
799 if ((int.Parse(text_height.Text) % 16) != 0)
\r
801 text_height.BackColor = Color.LightCoral;
\r
805 text_height.BackColor = Color.LightGreen;
\r
808 } catch(Exception){
\r
809 // No need to alert the user.
\r
813 private void drp_crop_SelectedIndexChanged(object sender, EventArgs e)
\r
815 if ((string)drp_crop.SelectedItem == "Manual")
\r
817 text_left.Enabled = true;
\r
818 text_right.Enabled = true;
\r
819 text_top.Enabled = true;
\r
820 text_bottom.Enabled = true;
\r
823 if ((string)drp_crop.SelectedItem == "Auto Crop")
\r
825 text_left.Enabled = false;
\r
826 text_right.Enabled = false;
\r
827 text_top.Enabled = false;
\r
828 text_bottom.Enabled = false;
\r
829 text_left.Text = "";
\r
830 text_right.Text = "";
\r
831 text_top.Text = "";
\r
832 text_bottom.Text = "";
\r
834 if (lbl_RecomendedCrop.Text != "Select a Title")
\r
836 string[] temp = new string[4];
\r
837 temp = lbl_RecomendedCrop.Text.Split('/');
\r
838 text_left.Text = temp[2];
\r
839 text_right.Text = temp[3];
\r
840 text_top.Text = temp[0];
\r
841 text_bottom.Text = temp[1];
\r
845 if ((string)drp_crop.SelectedItem == "No Crop")
\r
847 text_left.Enabled = false;
\r
848 text_right.Enabled = false;
\r
849 text_top.Enabled = false;
\r
850 text_bottom.Enabled = false;
\r
851 text_left.Text = "0";
\r
852 text_right.Text = "0";
\r
853 text_top.Text = "0";
\r
854 text_bottom.Text = "0";
\r
859 private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)
\r
861 text_width.Text = "";
\r
862 text_height.Text = "";
\r
863 text_width.BackColor = Color.White;
\r
864 text_height.BackColor = Color.White;
\r
867 private void drp_dvdtitle_Click(object sender, EventArgs e)
\r
869 if (drp_dvdtitle.Items.Count == 1)
\r
871 MessageBox.Show("There are no titles to select. Please scan the DVD by clicking the 'browse' button above before trying to select a title.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
875 private void drp_audioCodec_SelectedIndexChanged(object sender, EventArgs e)
\r
878 //CLI Audio mixdown Names: mono stereo dpl1 dpl2 6ch
\r
880 drp_audioMixDown.Items.Clear();
\r
882 if (drp_audioCodec.Text == "AAC")
\r
884 drp_audioMixDown.Items.Clear();
\r
885 drp_audioMixDown.Items.Add("Mono");
\r
886 drp_audioMixDown.Items.Add("Stereo");
\r
887 drp_audioMixDown.Items.Add("Dolby Surround");
\r
888 drp_audioMixDown.Items.Add("Dolby Pro Logic II");
\r
889 drp_audioMixDown.Items.Add("6 Channel Discrete");
\r
891 drp_audioBitrate.Items.Clear();
\r
892 drp_audioBitrate.Items.Add("32");
\r
893 drp_audioBitrate.Items.Add("40");
\r
894 drp_audioBitrate.Items.Add("48");
\r
895 drp_audioBitrate.Items.Add("56");
\r
896 drp_audioBitrate.Items.Add("64");
\r
897 drp_audioBitrate.Items.Add("80");
\r
898 drp_audioBitrate.Items.Add("86");
\r
899 drp_audioBitrate.Items.Add("112");
\r
900 drp_audioBitrate.Items.Add("128");
\r
901 drp_audioBitrate.Items.Add("160");
\r
906 drp_audioMixDown.Items.Clear();
\r
907 drp_audioMixDown.Items.Add("Stereo");
\r
908 drp_audioMixDown.Items.Add("Dolby Surround");
\r
909 drp_audioMixDown.Items.Add("Dolby Pro Logic II");
\r
911 drp_audioBitrate.Items.Clear();
\r
912 drp_audioBitrate.Items.Add("32");
\r
913 drp_audioBitrate.Items.Add("40");
\r
914 drp_audioBitrate.Items.Add("48");
\r
915 drp_audioBitrate.Items.Add("56");
\r
916 drp_audioBitrate.Items.Add("64");
\r
917 drp_audioBitrate.Items.Add("80");
\r
918 drp_audioBitrate.Items.Add("86");
\r
919 drp_audioBitrate.Items.Add("112");
\r
920 drp_audioBitrate.Items.Add("128");
\r
921 drp_audioBitrate.Items.Add("160");
\r
922 drp_audioBitrate.Items.Add("192");
\r
923 drp_audioBitrate.Items.Add("224");
\r
924 drp_audioBitrate.Items.Add("256");
\r
925 drp_audioBitrate.Items.Add("320");
\r
926 drp_audioBitrate.Items.Add("384");
\r
930 private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e)
\r
932 if (drp_audioCodec.Text == "AAC")
\r
934 if (drp_audioMixDown.Text == "6 Channel Discrete")
\r
937 drp_audioBitrate.Items.Clear();
\r
938 drp_audioBitrate.Items.Add("32");
\r
939 drp_audioBitrate.Items.Add("40");
\r
940 drp_audioBitrate.Items.Add("48");
\r
941 drp_audioBitrate.Items.Add("56");
\r
942 drp_audioBitrate.Items.Add("64");
\r
943 drp_audioBitrate.Items.Add("80");
\r
944 drp_audioBitrate.Items.Add("86");
\r
945 drp_audioBitrate.Items.Add("112");
\r
946 drp_audioBitrate.Items.Add("128");
\r
947 drp_audioBitrate.Items.Add("160");
\r
948 drp_audioBitrate.Items.Add("192");
\r
949 drp_audioBitrate.Items.Add("224");
\r
950 drp_audioBitrate.Items.Add("256");
\r
951 drp_audioBitrate.Items.Add("320");
\r
952 drp_audioBitrate.Items.Add("384");
\r
957 private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)
\r
959 if (Check_ChapterMarkers.Checked)
\r
961 string destination = text_destination.Text;
\r
962 destination = destination.Replace(".mp4", ".m4v");
\r
963 text_destination.Text = destination;
\r
967 private void check_largeFile_CheckedChanged(object sender, EventArgs e)
\r
969 if (!text_destination.Text.Contains(".mp4"))
\r
971 MessageBox.Show("This option is only compatible with the mp4 file container.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
972 check_largeFile.CheckState = CheckState.Unchecked;
\r
976 private void check_turbo_CheckedChanged(object sender, EventArgs e)
\r
978 if (!drp_videoEncoder.Text.Contains("H.264"))
\r
980 MessageBox.Show("This option is only compatible with the H.264 encoder's", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
981 check_turbo.CheckState = CheckState.Unchecked;
\r
985 private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)
\r
987 //Turn off some options which are H.264 only when the user selects a non h.264 encoder
\r
988 if (!drp_videoEncoder.Text.Contains("H.264"))
\r
990 check_turbo.CheckState = CheckState.Unchecked;
\r
991 CheckCRF.CheckState = CheckState.Unchecked;
\r
995 private void CheckCRF_CheckedChanged(object sender, EventArgs e)
\r
997 if (slider_videoQuality.Value == 0)
\r
999 MessageBox.Show("This option is can only be used with the 'Video Quality' slider.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1000 CheckCRF.CheckState = CheckState.Unchecked;
\r
1004 public void setStreamReader(Parsing.DVD dvd)
\r
1006 this.thisDVD = dvd;
\r
1009 private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
1011 // Reset some values on the form
\r
1012 lbl_Aspect.Text = "Select a Title";
\r
1013 lbl_RecomendedCrop.Text = "Select a Title";
\r
1014 drop_chapterStart.Items.Clear();
\r
1015 drop_chapterFinish.Items.Clear();
\r
1016 QueryEditorText.Text = "";
\r
1018 // If the dropdown is set to automatic nothing else needs to be done.
\r
1019 // Otheriwse if its not, title data has to be loased from parsing.
\r
1020 if (drp_dvdtitle.Text != "Automatic")
\r
1022 Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;
\r
1024 // Set the Aspect Ratio
\r
1025 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();
\r
1027 // Set the Recommended Cropping values
\r
1028 lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);
\r
1030 // Populate the Start chapter Dropdown
\r
1031 drop_chapterStart.Items.Clear();
\r
1032 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1033 if (drop_chapterStart.Items.Count > 0)
\r
1035 drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();
\r
1038 // Populate the Final Chapter Dropdown
\r
1039 drop_chapterFinish.Items.Clear();
\r
1040 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1041 if (drop_chapterFinish.Items.Count > 0)
\r
1043 drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();
\r
1046 // Populate the Audio Channels Dropdown
\r
1047 drp_audioChannels.Items.Clear();
\r
1048 drp_audioChannels.Items.Add("Automatic");
\r
1049 drp_audioChannels.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
1050 if (drp_audioChannels.Items.Count > 0)
\r
1052 drp_audioChannels.Text = drp_audioChannels.Items[0].ToString();
\r
1055 // Populate the Subtitles dropdown
\r
1056 drp_subtitle.Items.Clear();
\r
1057 drp_subtitle.Items.Add("None");
\r
1058 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());
\r
1059 if (drp_subtitle.Items.Count > 0)
\r
1061 drp_subtitle.Text = drp_subtitle.Items[0].ToString();
\r
1066 //---------------------------------------------------
\r
1067 // The query Generation function.
\r
1068 //---------------------------------------------------
\r
1069 public string GenerateTheQuery()
\r
1071 string source = text_source.Text;
\r
1072 string dvdTitle = drp_dvdtitle.Text;
\r
1073 string chapterStart = drop_chapterStart.Text;
\r
1074 string chapterFinish = drop_chapterFinish.Text;
\r
1075 int totalChapters = drop_chapterFinish.Items.Count - 1;
\r
1076 string dvdChapter = "";
\r
1079 MessageBox.Show("No Source has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1082 source = " -i " + '"' + source+ '"'; //'"'+
\r
1085 if (dvdTitle == "Automatic")
\r
1089 string[] titleInfo = dvdTitle.Split(' ');
\r
1090 dvdTitle = " -t "+ titleInfo[0];
\r
1093 if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))
\r
1095 else if (chapterFinish == chapterStart)
\r
1096 dvdChapter = " -c " + chapterStart;
\r
1098 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;
\r
1100 string querySource = source+ dvdTitle+ dvdChapter;
\r
1101 // ----------------------------------------------------------------------
\r
1105 string destination = text_destination.Text;
\r
1106 string videoEncoder = drp_videoEncoder.Text;
\r
1107 string audioEncoder = drp_audioCodec.Text;
\r
1108 string width = text_width.Text;
\r
1109 string height = text_height.Text;
\r
1111 if (destination == "")
\r
1112 MessageBox.Show("No destination has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1114 destination = " -o " + '"' + destination + '"'; //'"'+
\r
1117 switch (videoEncoder)
\r
1120 videoEncoder = " -e ffmpeg";
\r
1123 videoEncoder = " -e xvid";
\r
1126 videoEncoder = " -e x264";
\r
1128 case "H.264 Baseline 1.3":
\r
1129 videoEncoder = " -e x264b13";
\r
1131 case "H.264 (iPod)":
\r
1132 videoEncoder = " -e x264b30";
\r
1135 videoEncoder = " -e x264";
\r
1139 switch (audioEncoder)
\r
1142 audioEncoder = " -E faac";
\r
1145 audioEncoder = " -E lame";
\r
1148 audioEncoder = " -E vorbis";
\r
1151 audioEncoder = " -E ac3";
\r
1154 audioEncoder = " -E faac";
\r
1159 width = " -w "+ width;
\r
1163 height = " -l "+ height;
\r
1166 string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height;
\r
1167 // ----------------------------------------------------------------------
\r
1169 // Picture Settings Tab
\r
1171 string cropSetting = drp_crop.Text;
\r
1172 string cropTop = text_top.Text;
\r
1173 string cropBottom = text_bottom.Text;
\r
1174 string cropLeft = text_left.Text;
\r
1175 string cropRight = text_right.Text;
\r
1176 string subtitles = drp_subtitle.Text;
\r
1177 string cropOut = "";
\r
1178 // Returns Crop Query
\r
1180 if (cropSetting == "Auto Crop")
\r
1182 else if (cropSetting == "No Crop")
\r
1183 cropOut = " --crop 0:0:0:0 ";
\r
1185 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;
\r
1187 if (subtitles == "None")
\r
1189 else if (subtitles == "")
\r
1194 tempSub = subtitles.Split(' ');
\r
1195 subtitles = " -s "+ tempSub[0];
\r
1198 string queryPictureSettings = cropOut+ subtitles;
\r
1199 // ----------------------------------------------------------------------
\r
1201 // Video Settings Tab
\r
1203 string videoBitrate = text_bitrate.Text;
\r
1204 string videoFilesize = text_filesize.Text;
\r
1205 int videoQuality = slider_videoQuality.Value;
\r
1206 string vidQSetting = "";
\r
1207 string twoPassEncoding = "";
\r
1208 string deinterlace = "";
\r
1209 string grayscale = "";
\r
1210 string videoFramerate = drp_videoFramerate.Text;
\r
1211 string pixelRatio = "";
\r
1212 string ChapterMarkers = "";
\r
1213 string turboH264 = "";
\r
1214 string largeFile = "";
\r
1216 if (videoBitrate != "")
\r
1217 videoBitrate = " -b "+ videoBitrate;
\r
1219 if (videoFilesize != "")
\r
1220 videoFilesize = " -S "+ videoFilesize;
\r
1222 // Video Quality Setting
\r
1224 if ((videoQuality == 0))
\r
1228 videoQuality = videoQuality/ 100;
\r
1229 if (videoQuality == 1)
\r
1231 vidQSetting = "1.0";
\r
1234 vidQSetting = " -q " + videoQuality.ToString();
\r
1237 if (check_2PassEncode.Checked)
\r
1238 twoPassEncoding = " -2 ";
\r
1240 if (check_DeInterlace.Checked)
\r
1241 deinterlace = " -d ";
\r
1243 if (check_grayscale.Checked)
\r
1244 grayscale = " -g ";
\r
1246 if (videoFramerate == "Automatic")
\r
1247 videoFramerate = "";
\r
1249 videoFramerate = " -r "+ videoFramerate;
\r
1251 if (CheckPixelRatio.Checked)
\r
1252 pixelRatio = " -p ";
\r
1254 if (Check_ChapterMarkers.Checked)
\r
1255 ChapterMarkers = " -m ";
\r
1257 if (check_turbo.Checked)
\r
1258 turboH264 = " -T ";
\r
1260 if (check_largeFile.Checked)
\r
1261 largeFile = " -4 ";
\r
1263 string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + deinterlace + grayscale + videoFramerate + pixelRatio + ChapterMarkers + turboH264 + largeFile;
\r
1264 // ----------------------------------------------------------------------
\r
1266 // Audio Settings Tab
\r
1268 string audioBitrate = drp_audioBitrate.Text;
\r
1269 string audioSampleRate = drp_audioSampleRate.Text;
\r
1270 string audioChannels = drp_audioChannels.Text;
\r
1271 string Mixdown = drp_audioMixDown.Text;
\r
1272 string SixChannelAudio = "";
\r
1274 if (audioBitrate != "")
\r
1275 audioBitrate = " -B "+ audioBitrate;
\r
1277 if (audioSampleRate != "")
\r
1278 audioSampleRate = " -R "+ audioSampleRate;
\r
1280 if (audioChannels == "Automatic")
\r
1281 audioChannels = "";
\r
1282 else if (audioChannels == "")
\r
1283 audioChannels = "";
\r
1287 tempSub = audioChannels.Split(' ');
\r
1288 audioChannels = " -a "+ tempSub[0];
\r
1300 Mixdown = "stereo";
\r
1302 case "Dolby Surround":
\r
1305 case "Dolby Pro Logic II":
\r
1308 case "6 Channel Discrete":
\r
1312 Mixdown = "stero";
\r
1316 if (Mixdown != "")
\r
1317 SixChannelAudio = " -6 "+ Mixdown;
\r
1319 SixChannelAudio = "";
\r
1321 string queryAudioSettings = audioBitrate+ audioSampleRate+ audioChannels+ SixChannelAudio;
\r
1322 // ----------------------------------------------------------------------
\r
1326 string CRF = CheckCRF.CheckState.ToString();
\r
1327 string h264Advanced = rtf_h264advanced.Text;
\r
1333 if ((h264Advanced == ""))
\r
1334 h264Advanced = "";
\r
1336 h264Advanced = " -x "+ h264Advanced;
\r
1339 string h264Settings = CRF+ h264Advanced;
\r
1340 // ----------------------------------------------------------------------
\r
1342 // Processors (Program Settings)
\r
1344 string processors = Properties.Settings.Default.Processors;
\r
1345 // Number of Processors Handler
\r
1347 if (processors == "Automatic")
\r
1350 processors = " -C "+ processors+ " ";
\r
1353 string queryAdvancedSettings = processors;
\r
1354 // ----------------------------------------------------------------------
\r
1356 // Verbose option (Program Settings)
\r
1358 string verbose = "";
\r
1359 if (Properties.Settings.Default.verbose == "Checked")
\r
1362 // ----------------------------------------------------------------------
\r
1364 return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;
\r
1367 private void frmMain_Load(object sender, EventArgs e)
\r
1372 // This is the END of the road ------------------------------------------------------------------------------
\r