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
30 private frmDvdInfo dvdInfoWindow = new frmDvdInfo();
\r
35 ThreadPool.QueueUserWorkItem(showSplash);
\r
38 InitializeComponent();
\r
40 // This is a quick Hack fix for the cross-thread problem with frmDvdIndo ************************
\r
41 dvdInfoWindow.Show();
\r
42 dvdInfoWindow.Hide();
\r
43 // **********************************************************************************************
\r
45 // Set the Version number lable to the corect version.
\r
46 Version.Text = "Version " + Properties.Settings.Default.GuiVersion;
\r
48 // Run the update checker.
\r
51 // Now load the users default if required.
\r
55 public void showSplash(object sender)
\r
57 Form splash = new frmSplashScreen();
\r
62 public void loadUserDefaults()
\r
66 if (Properties.Settings.Default.defaultSettings == "Checked")
\r
69 text_source.Text = Properties.Settings.Default.DVDSource;
\r
70 drp_dvdtitle.Text = Properties.Settings.Default.DVDTitle;
\r
71 drop_chapterStart.Text = Properties.Settings.Default.ChapterStart;
\r
72 drop_chapterFinish.Text = Properties.Settings.Default.ChapterFinish;
\r
75 text_destination.Text = Properties.Settings.Default.VideoDest;
\r
76 drp_videoEncoder.Text = Properties.Settings.Default.VideoEncoder;
\r
77 drp_audioCodec.Text = Properties.Settings.Default.AudioEncoder;
\r
78 text_width.Text = Properties.Settings.Default.Width;
\r
79 text_height.Text = Properties.Settings.Default.Height;
\r
81 // Picture Settings Tab
\r
82 drp_crop.Text = Properties.Settings.Default.CroppingOption;
\r
83 text_top.Text = Properties.Settings.Default.CropTop;
\r
84 text_bottom.Text = Properties.Settings.Default.CropBottom;
\r
85 text_left.Text = Properties.Settings.Default.CropLeft;
\r
86 text_right.Text = Properties.Settings.Default.CropRight;
\r
87 drp_subtitle.Text = Properties.Settings.Default.Subtitles;
\r
89 // Video Settings Tab
\r
90 text_bitrate.Text = Properties.Settings.Default.VideoBitrate;
\r
91 text_filesize.Text = Properties.Settings.Default.VideoFilesize;
\r
92 slider_videoQuality.Value = Properties.Settings.Default.VideoQuality;
\r
94 if (Properties.Settings.Default.TwoPass == "Checked")
\r
96 check_2PassEncode.CheckState = CheckState.Checked;
\r
98 if (Properties.Settings.Default.DeInterlace == "Checked")
\r
100 check_DeInterlace.CheckState = CheckState.Checked;
\r
102 if (Properties.Settings.Default.Grayscale == "Checked")
\r
104 check_grayscale.CheckState = CheckState.Checked;
\r
107 drp_videoFramerate.Text = Properties.Settings.Default.Framerate;
\r
109 if (Properties.Settings.Default.PixelRatio == "Checked")
\r
111 CheckPixelRatio.CheckState = CheckState.Checked;
\r
113 if (Properties.Settings.Default.turboFirstPass == "Checked")
\r
115 check_turbo.CheckState = CheckState.Checked;
\r
117 if (Properties.Settings.Default.largeFile == "Checked")
\r
119 check_largeFile.CheckState = CheckState.Checked;
\r
121 // Audio Settings Tab
\r
122 drp_audioBitrate.Text = Properties.Settings.Default.AudioBitrate;
\r
123 drp_audioSampleRate.Text = Properties.Settings.Default.AudioSampleRate;
\r
124 drp_audioChannels.Text = Properties.Settings.Default.AudioChannels;
\r
127 if (Properties.Settings.Default.CRF == "Checked")
\r
129 CheckCRF.CheckState = CheckState.Checked;
\r
131 rtf_h264advanced.Text = Properties.Settings.Default.H264;
\r
136 // No real need to alert the user. Try/Catch only in just incase there is a problem reading the settings xml file.
\r
140 public void updateCheck()
\r
142 if (Properties.Settings.Default.updateStatus == "Checked")
\r
146 String updateFile = Properties.Settings.Default.updateFile;
\r
147 WebClient client = new WebClient();
\r
148 String data = client.DownloadString(updateFile);
\r
149 String[] versionData = data.Split('\n');
\r
151 if ((versionData[0] != Properties.Settings.Default.GuiVersion) || (versionData[1] != Properties.Settings.Default.CliVersion))
\r
153 lbl_update.Visible = true;
\r
158 // Silently ignore the error
\r
163 // --------------------------------------------------------------
\r
164 // The main Menu bar.
\r
165 // --------------------------------------------------------------
\r
169 private void mnu_open_Click(object sender, EventArgs e)
\r
172 File_Open.ShowDialog();
\r
173 filename = File_Open.FileName;
\r
174 if (filename != "")
\r
178 // Create StreamReader & open file
\r
179 StreamReader line = new StreamReader(filename);
\r
180 string temporyLine; // Used for reading the line into a varible before processing on the checkState items below.
\r
182 // Read in the data and set the correct GUI component with the setting.
\r
183 text_source.Text = line.ReadLine();
\r
184 drp_dvdtitle.Text = line.ReadLine();
\r
185 drop_chapterStart.Text = line.ReadLine();
\r
186 drop_chapterFinish.Text = line.ReadLine();
\r
187 text_destination.Text = line.ReadLine();
\r
188 drp_videoEncoder.Text = line.ReadLine();
\r
189 drp_audioCodec.Text = line.ReadLine();
\r
190 text_width.Text = line.ReadLine();
\r
191 text_height.Text = line.ReadLine();
\r
192 text_top.Text = line.ReadLine();
\r
193 text_bottom.Text = line.ReadLine();
\r
194 text_left.Text = line.ReadLine();
\r
195 text_right.Text = line.ReadLine();
\r
196 drp_subtitle.Text = line.ReadLine();
\r
197 text_bitrate.Text = line.ReadLine();
\r
198 text_filesize.Text = line.ReadLine();
\r
199 slider_videoQuality.Value = int.Parse(line.ReadLine());
\r
201 temporyLine = line.ReadLine();
\r
202 if (temporyLine == "Checked")
\r
204 check_2PassEncode.CheckState = CheckState.Checked;
\r
207 temporyLine = line.ReadLine();
\r
208 if (temporyLine == "Checked")
\r
210 check_DeInterlace.CheckState = CheckState.Checked;
\r
213 temporyLine = line.ReadLine();
\r
214 if (temporyLine == "Checked")
\r
216 check_grayscale.CheckState = CheckState.Checked;
\r
219 drp_videoFramerate.Text = line.ReadLine();
\r
221 temporyLine = line.ReadLine();
\r
222 if (temporyLine == "Checked")
\r
224 Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
227 temporyLine = line.ReadLine();
\r
228 if (temporyLine == "Checked")
\r
230 CheckPixelRatio.CheckState = CheckState.Checked;
\r
233 temporyLine = line.ReadLine();
\r
234 if (temporyLine == "Checked")
\r
236 check_turbo.CheckState = CheckState.Checked;
\r
239 temporyLine = line.ReadLine();
\r
240 if (temporyLine == "Checked")
\r
242 check_largeFile.CheckState = CheckState.Checked;
\r
245 drp_audioBitrate.Text = line.ReadLine();
\r
246 drp_audioSampleRate.Text = line.ReadLine();
\r
247 drp_audioChannels.Text = line.ReadLine();
\r
248 drp_audioMixDown.Text = line.ReadLine();
\r
250 // Advanced H264 Options
\r
251 temporyLine = line.ReadLine();
\r
252 if (temporyLine == "Checked")
\r
254 CheckCRF.CheckState = CheckState.Checked;
\r
256 rtf_h264advanced.Text = line.ReadLine();
\r
258 // Close the stream
\r
262 // Fix for SliderValue not appearing when Opening saved file
\r
263 SliderValue.Text = slider_videoQuality.Value + "%";
\r
265 } catch (Exception){
\r
266 MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
271 private void mnu_save_Click(object sender, EventArgs e)
\r
275 File_Save.ShowDialog();
\r
276 filename = File_Save.FileName;
\r
277 if (filename != "")
\r
281 // Create a StreamWriter and open the file
\r
282 StreamWriter line = new StreamWriter(filename);
\r
285 line.WriteLine(text_source.Text);
\r
286 line.WriteLine(drp_dvdtitle.Text);
\r
287 line.WriteLine(drop_chapterStart.Text);
\r
288 line.WriteLine(drop_chapterFinish.Text);
\r
290 line.WriteLine(text_destination.Text);
\r
291 line.WriteLine(drp_videoEncoder.Text);
\r
292 line.WriteLine(drp_audioCodec.Text);
\r
293 line.WriteLine(text_width.Text);
\r
294 line.WriteLine(text_height.Text);
\r
295 //Picture Settings Tab
\r
296 line.WriteLine(text_top.Text);
\r
297 line.WriteLine(text_bottom.Text);
\r
298 line.WriteLine(text_left.Text);
\r
299 line.WriteLine(text_right.Text);
\r
300 line.WriteLine(drp_subtitle.Text);
\r
301 //Video Settings Tab
\r
302 line.WriteLine(text_bitrate.Text);
\r
303 line.WriteLine(text_filesize.Text);
\r
304 line.WriteLine(slider_videoQuality.Value.ToString());
\r
305 line.WriteLine(check_2PassEncode.CheckState.ToString());
\r
306 line.WriteLine(check_DeInterlace.CheckState.ToString());
\r
307 line.WriteLine(check_grayscale.CheckState.ToString());
\r
308 line.WriteLine(drp_videoFramerate.Text);
\r
309 line.WriteLine(Check_ChapterMarkers.CheckState.ToString());
\r
310 line.WriteLine(CheckPixelRatio.CheckState.ToString());
\r
311 line.WriteLine(check_turbo.CheckState.ToString());
\r
312 line.WriteLine(check_largeFile.CheckState.ToString());
\r
313 //Audio Settings Tab
\r
314 line.WriteLine(drp_audioBitrate.Text);
\r
315 line.WriteLine(drp_audioSampleRate.Text);
\r
316 line.WriteLine(drp_audioChannels.Text);
\r
317 line.WriteLine(drp_audioMixDown.Text);
\r
319 line.WriteLine(CheckCRF.CheckState.ToString());
\r
320 line.WriteLine(rtf_h264advanced.Text);
\r
321 // close the stream
\r
323 MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
327 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
333 private void mnu_update_Click(object sender, EventArgs e)
\r
335 Form Update = new frmUpdate();
\r
336 Update.ShowDialog();
\r
339 private void mnu_exit_Click(object sender, EventArgs e)
\r
348 private void mnu_encode_Click(object sender, EventArgs e)
\r
354 private void mnu_viewDVDdata_Click(object sender, EventArgs e)
\r
358 dvdInfoWindow.Show();
\r
365 // BUG *******************************************************
\r
366 // Cross-thread operation not valid: Control 'rtf_dvdInfo' accessed from a thread other than the thread it was created on.
\r
367 // This happens when the DVD is scanned and this item is then selected.
\r
368 // 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
369 // NOTE: Try/catch added to prevent final build crashing.
\r
370 // NOTE2: Included a quick fix in frmMain(). Simply show and hide the window when starting the app.
\r
371 // Note3: Suspect the problem lies with line 30.
\r
372 // ***********************************************************
\r
376 private void mnu_options_Click(object sender, EventArgs e)
\r
378 Form Options = new frmOptions();
\r
379 Options.ShowDialog();
\r
384 #region Presets Menu
\r
386 private void mnu_preset_ipod133_Click(object sender, EventArgs e)
\r
388 CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
389 text_width.Text = "640";
\r
390 text_height.Text = "480";
\r
391 drp_videoEncoder.Text = "H.264 (iPod)";
\r
392 text_bitrate.Text = "1000";
\r
393 text_filesize.Text = "";
\r
394 slider_videoQuality.Value = 0;
\r
395 SliderValue.Text = "0%";
\r
396 drp_audioBitrate.Text = "160";
\r
397 rtf_h264advanced.Text = "";
\r
398 drp_crop.Text = "No Crop";
\r
401 private void mnu_preset_ipod178_Click(object sender, EventArgs e)
\r
403 CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
404 text_width.Text = "640";
\r
405 text_height.Text = "352";
\r
406 drp_videoEncoder.Text = "H.264 (iPod)";
\r
407 text_bitrate.Text = "1000";
\r
408 text_filesize.Text = "";
\r
409 slider_videoQuality.Value = 0;
\r
410 SliderValue.Text = "0%";
\r
411 drp_audioBitrate.Text = "160";
\r
412 rtf_h264advanced.Text = "";
\r
413 drp_crop.Text = "No Crop";
\r
416 private void mnu_preset_ipod235_Click(object sender, EventArgs e)
\r
418 CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
419 text_width.Text = "640";
\r
420 text_height.Text = "272";
\r
421 drp_videoEncoder.Text = "H.264 (iPod)";
\r
422 text_bitrate.Text = "1000";
\r
423 text_filesize.Text = "";
\r
424 slider_videoQuality.Value = 0;
\r
425 SliderValue.Text = "0%";
\r
426 drp_audioBitrate.Text = "160";
\r
427 rtf_h264advanced.Text = "";
\r
428 drp_crop.Text = "No Crop";
\r
431 private void mnu_appleTv_Click(object sender, EventArgs e)
\r
433 text_width.Text = "";
\r
434 text_height.Text = "";
\r
435 drp_videoEncoder.Text = "H.264";
\r
436 text_bitrate.Text = "3000";
\r
437 text_filesize.Text = "";
\r
438 slider_videoQuality.Value = 0;
\r
439 SliderValue.Text = "0%";
\r
440 drp_audioBitrate.Text = "160";
\r
441 CheckPixelRatio.CheckState = CheckState.Checked;
\r
442 drp_audioSampleRate.Text = "48";
\r
443 rtf_h264advanced.Text = "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";
\r
444 drp_crop.Text = "No Crop";
\r
448 private void mnu_presetPS3_Click(object sender, EventArgs e)
\r
450 CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
451 text_width.Text = "";
\r
452 text_height.Text = "";
\r
453 drp_videoEncoder.Text = "H.264";
\r
454 text_bitrate.Text = "3000";
\r
455 text_filesize.Text = "";
\r
456 slider_videoQuality.Value = 0;
\r
457 SliderValue.Text = "0%";
\r
458 drp_audioBitrate.Text = "160";
\r
459 CheckPixelRatio.CheckState = CheckState.Checked;
\r
460 drp_audioSampleRate.Text = "48";
\r
461 rtf_h264advanced.Text = "level=41";
\r
462 drp_crop.Text = "No Crop";
\r
465 private void mnu_ProgramDefaultOptions_Click(object sender, EventArgs e)
\r
468 Properties.Settings.Default.DVDSource = text_source.Text;
\r
469 Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;
\r
470 Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;
\r
471 Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;
\r
473 Properties.Settings.Default.VideoDest = text_destination.Text;
\r
474 Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;
\r
475 Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;
\r
476 Properties.Settings.Default.Width = text_width.Text;
\r
477 Properties.Settings.Default.Height = text_height.Text;
\r
478 //Picture Settings Tab
\r
479 Properties.Settings.Default.CroppingOption = drp_crop.Text;
\r
480 Properties.Settings.Default.CropTop = text_top.Text;
\r
481 Properties.Settings.Default.CropBottom = text_bottom.Text;
\r
482 Properties.Settings.Default.CropLeft = text_left.Text;
\r
483 Properties.Settings.Default.CropRight = text_right.Text;
\r
484 Properties.Settings.Default.Subtitles = drp_subtitle.Text;
\r
485 //Video Settings Tab
\r
486 Properties.Settings.Default.VideoBitrate = text_bitrate.Text;
\r
487 Properties.Settings.Default.VideoFilesize = text_filesize.Text;
\r
488 Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;
\r
489 Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();
\r
490 Properties.Settings.Default.DeInterlace = check_DeInterlace.CheckState.ToString();
\r
491 Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();
\r
492 Properties.Settings.Default.Framerate = drp_videoFramerate.Text;
\r
493 Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();
\r
494 Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();
\r
495 Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString();
\r
496 //Audio Settings Tab
\r
497 Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;
\r
498 Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;
\r
499 Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;
\r
501 Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();
\r
502 Properties.Settings.Default.H264 = rtf_h264advanced.Text;
\r
503 Properties.Settings.Default.Save();
\r
510 private void mnu_wiki_Click(object sender, EventArgs e)
\r
512 Process.Start("http://handbrake.m0k.org/trac");
\r
515 private void mnu_onlineDocs_Click(object sender, EventArgs e)
\r
517 Process.Start("http://handbrake.m0k.org/?page_id=11");
\r
520 private void mnu_faq_Click(object sender, EventArgs e)
\r
522 Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");
\r
525 private void mnu_homepage_Click(object sender, EventArgs e)
\r
527 Process.Start("http://handbrake.m0k.org");
\r
530 private void mnu_forum_Click(object sender, EventArgs e)
\r
532 Process.Start("http://handbrake.m0k.org/forum");
\r
535 private void mnu_about_Click(object sender, EventArgs e)
\r
537 Form About = new frmAbout();
\r
538 About.ShowDialog();
\r
543 // --------------------------------------------------------------
\r
544 // Buttons on the main Window
\r
545 // --------------------------------------------------------------
\r
546 private void btn_Browse_Click(object sender, EventArgs e)
\r
549 String filename ="";
\r
550 text_source.Text = "";
\r
552 //int scanTwice = 0;
\r
554 if (RadioDVD.Checked)
\r
556 DVD_Open.ShowDialog();
\r
557 filename = DVD_Open.SelectedPath;
\r
558 if (filename != "")
\r
560 Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);
\r
561 text_source.Text = filename;
\r
562 frmRD.ShowDialog();
\r
567 ISO_Open.ShowDialog();
\r
568 filename = ISO_Open.FileName;
\r
569 if (filename != "")
\r
571 Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);
\r
572 text_source.Text = filename;
\r
573 frmRD.ShowDialog();
\r
577 // Check if there was titles in the dvd title dropdown
\r
578 // If there isn't any, rescan the DVD. hbcli occasionally fails (see bug in encode) with standard error.
\r
579 if (filename != "")
\r
581 // Disbaled the 2nd pass for the time being.
\r
582 /* if (drp_dvdtitle.Items.Count == 0)
\r
584 if (scanTwice == 0)
\r
586 MessageBox.Show("Scan Failed. Waiting 5 Seconds before attempting to re-scan the source a 2nd time.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
587 Thread.Sleep(3000);
\r
588 Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);
\r
589 frmRD.ShowDialog();
\r
596 text_source.Text = "Click 'Browse' to continue";
\r
599 if (drp_dvdtitle.Items.Count == 0)
\r
601 MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source. Please refer to the FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
606 private void btn_destBrowse_Click(object sender, EventArgs e)
\r
608 // TODO: Need to write some code to check if there is a reasonable amount of disk space left.
\r
610 DVD_Save.ShowDialog();
\r
611 text_destination.Text = DVD_Save.FileName;
\r
613 if (Check_ChapterMarkers.Checked)
\r
615 string destination = text_destination.Text;
\r
616 destination = destination.Replace(".mp4", ".m4v");
\r
617 text_destination.Text = destination;
\r
621 private void btn_h264Clear_Click(object sender, EventArgs e)
\r
623 rtf_h264advanced.Text = "";
\r
626 private void GenerateQuery_Click(object sender, EventArgs e)
\r
628 String query = GenerateTheQuery();
\r
629 QueryEditorText.Text = query;
\r
632 private void btn_ClearQuery_Click(object sender, EventArgs e)
\r
634 QueryEditorText.Text = "";
\r
637 private void btn_queue_Click(object sender, EventArgs e)
\r
639 if (text_destination.Text != "" && text_source.Text != "")
\r
642 String query = GenerateTheQuery();
\r
643 queueWindow.list_queue.Items.Add(query);
\r
644 queueWindow.Show();
\r
648 MessageBox.Show("No Source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
652 private void showQueue()
\r
654 queueWindow.Show();
\r
661 //---------------------------------------------------
\r
662 // Encode / Cancel Buttons
\r
663 // Encode Progress Text Handler
\r
664 //---------------------------------------------------
\r
666 Functions.CLI process = new Functions.CLI();
\r
668 private void btn_encode_Click(object sender, EventArgs e)
\r
670 btn_eCancel.Enabled = true;
\r
672 lbl_encode.Visible = true;
\r
674 if (QueryEditorText.Text == "")
\r
676 query = GenerateTheQuery();
\r
680 query = QueryEditorText.Text;
\r
683 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
684 lbl_encode.Text = "Encoding Started";
\r
687 private void btn_eCancel_Click(object sender, EventArgs e)
\r
691 lbl_encode.Text = "Encoding Canceled";
\r
694 private void procMonitor(object state)
\r
696 // Make sure we are not already encoding and if we are then display an error.
\r
697 if (hbProc != null)
\r
699 MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
703 hbProc = process.runCli(this, (string)state, true, true, false, false);
\r
705 MessageBox.Show("The encode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
710 //*****************************************************************************************
\r
712 // When the below code is used and standard error is set to true, hbcli is outputing a
\r
713 // video stream which has mild corruption issues every few seconds.
\r
714 // Maybe an issue with the Parser cauing the CLI to hickup/pause?
\r
715 //*****************************************************************************************
\r
718 /*Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);
\r
719 encode.OnEncodeProgress += encode_OnEncodeProgress;
\r
720 while (!encode.EndOfStream)
\r
725 hbProc.WaitForExit();
\r
726 process.closeCLI();
\r
734 MessageBox.Show("The encode process has now ended.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
739 private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)
\r
741 if (this.InvokeRequired)
\r
743 this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),
\r
744 new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });
\r
747 lbl_encode.Text = string.Format("Encode Progress: {0}%, FPS: {1}, Avg FPS: {2}, Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);
\r
750 //---------------------------------------------------
\r
751 // Items that require actions on frmMain
\r
752 //---------------------------------------------------
\r
754 private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)
\r
756 lbl_chptWarn.Visible = false;
\r
757 QueryEditorText.Text = "";
\r
758 if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))
\r
762 int chapterFinish = int.Parse(drop_chapterFinish.Text);
\r
763 int chapterStart = int.Parse(drop_chapterStart.Text);
\r
765 if (chapterFinish < chapterStart)
\r
767 lbl_chptWarn.Visible = true;
\r
768 lbl_chptWarn.Text = "Invalid Chapter Range!";
\r
773 lbl_chptWarn.Visible = true;
\r
774 lbl_chptWarn.Text = "Invalid Chapter Range!";
\r
781 private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)
\r
783 lbl_chptWarn.Visible = false;
\r
784 QueryEditorText.Text = "";
\r
785 if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))
\r
789 int chapterFinish = int.Parse(drop_chapterFinish.Text);
\r
790 int chapterStart = int.Parse(drop_chapterStart.Text);
\r
792 if (chapterFinish < chapterStart)
\r
794 lbl_chptWarn.Visible = true;
\r
795 lbl_chptWarn.Text = "Invalid Chapter Range!";
\r
800 lbl_chptWarn.Visible = true;
\r
801 lbl_chptWarn.Text = "Invalid Chapter Range!";
\r
806 private void text_bitrate_TextChanged(object sender, EventArgs e)
\r
808 text_filesize.Text = "";
\r
809 slider_videoQuality.Value = 0;
\r
810 SliderValue.Text = "0%";
\r
811 CheckCRF.CheckState = CheckState.Unchecked;
\r
812 CheckCRF.Enabled = false;
\r
815 private void text_filesize_TextChanged(object sender, EventArgs e)
\r
817 text_bitrate.Text = "";
\r
818 slider_videoQuality.Value = 0;
\r
819 SliderValue.Text = "0%";
\r
820 CheckCRF.CheckState = CheckState.Unchecked;
\r
821 CheckCRF.Enabled = false;
\r
824 private void slider_videoQuality_Scroll(object sender, EventArgs e)
\r
826 SliderValue.Text = slider_videoQuality.Value.ToString() + "%";
\r
827 text_bitrate.Text = "";
\r
828 text_filesize.Text = "";
\r
829 CheckCRF.Enabled = true;
\r
832 private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
834 Process.Start("http://handbrake.m0k.org/trac/wiki/x264Options");
\r
837 private void text_width_TextChanged(object sender, EventArgs e)
\r
842 if (CheckPixelRatio.Checked)
\r
844 text_width.Text = "";
\r
845 text_width.BackColor = Color.White;
\r
849 if ((int.Parse(text_width.Text) % 16) != 0)
\r
851 text_width.BackColor = Color.LightCoral;
\r
855 text_width.BackColor = Color.LightGreen;
\r
859 if (lbl_Aspect.Text != "Select a Title")
\r
861 double height = int.Parse(text_width.Text) / double.Parse(lbl_Aspect.Text);
\r
862 double mod16 = height % 16;
\r
863 height = height - mod16;
\r
865 if (text_width.Text == "")
\r
867 text_height.Text = "";
\r
868 text_width.BackColor = Color.White;
\r
872 text_height.Text = height.ToString();
\r
878 // No need to throw an error here.
\r
884 private void text_height_TextChanged(object sender, EventArgs e)
\r
888 if (CheckPixelRatio.Checked)
\r
890 text_height.Text = "";
\r
891 text_width.BackColor = Color.White;
\r
895 if ((int.Parse(text_height.Text) % 16) != 0)
\r
897 text_height.BackColor = Color.LightCoral;
\r
901 text_height.BackColor = Color.LightGreen;
\r
904 } catch(Exception){
\r
905 // No need to alert the user.
\r
909 private void drp_crop_SelectedIndexChanged(object sender, EventArgs e)
\r
911 if ((string)drp_crop.SelectedItem == "Manual")
\r
913 text_left.Enabled = true;
\r
914 text_right.Enabled = true;
\r
915 text_top.Enabled = true;
\r
916 text_bottom.Enabled = true;
\r
919 if ((string)drp_crop.SelectedItem == "Auto Crop")
\r
921 text_left.Enabled = false;
\r
922 text_right.Enabled = false;
\r
923 text_top.Enabled = false;
\r
924 text_bottom.Enabled = false;
\r
925 text_left.Text = "";
\r
926 text_right.Text = "";
\r
927 text_top.Text = "";
\r
928 text_bottom.Text = "";
\r
930 if (lbl_RecomendedCrop.Text != "Select a Title")
\r
932 string[] temp = new string[4];
\r
933 temp = lbl_RecomendedCrop.Text.Split('/');
\r
934 text_left.Text = temp[2];
\r
935 text_right.Text = temp[3];
\r
936 text_top.Text = temp[0];
\r
937 text_bottom.Text = temp[1];
\r
941 if ((string)drp_crop.SelectedItem == "No Crop")
\r
943 text_left.Enabled = false;
\r
944 text_right.Enabled = false;
\r
945 text_top.Enabled = false;
\r
946 text_bottom.Enabled = false;
\r
947 text_left.Text = "0";
\r
948 text_right.Text = "0";
\r
949 text_top.Text = "0";
\r
950 text_bottom.Text = "0";
\r
955 private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)
\r
957 text_width.Text = "";
\r
958 text_height.Text = "";
\r
959 text_width.BackColor = Color.White;
\r
960 text_height.BackColor = Color.White;
\r
963 private void drp_dvdtitle_Click(object sender, EventArgs e)
\r
965 if (drp_dvdtitle.Items.Count == 1)
\r
967 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
971 private void drp_audioCodec_SelectedIndexChanged(object sender, EventArgs e)
\r
974 //CLI Audio mixdown Names: mono stereo dpl1 dpl2 6ch
\r
976 drp_audioMixDown.Items.Clear();
\r
978 if (drp_audioCodec.Text == "AAC")
\r
980 drp_audioMixDown.Items.Clear();
\r
981 drp_audioMixDown.Items.Add("Mono");
\r
982 drp_audioMixDown.Items.Add("Stereo");
\r
983 drp_audioMixDown.Items.Add("Dolby Surround");
\r
984 drp_audioMixDown.Items.Add("Dolby Pro Logic II");
\r
985 drp_audioMixDown.Items.Add("6 Channel Discrete");
\r
987 drp_audioBitrate.Items.Clear();
\r
988 drp_audioBitrate.Items.Add("32");
\r
989 drp_audioBitrate.Items.Add("40");
\r
990 drp_audioBitrate.Items.Add("48");
\r
991 drp_audioBitrate.Items.Add("56");
\r
992 drp_audioBitrate.Items.Add("64");
\r
993 drp_audioBitrate.Items.Add("80");
\r
994 drp_audioBitrate.Items.Add("86");
\r
995 drp_audioBitrate.Items.Add("112");
\r
996 drp_audioBitrate.Items.Add("128");
\r
997 drp_audioBitrate.Items.Add("160");
\r
1002 drp_audioMixDown.Items.Clear();
\r
1003 drp_audioMixDown.Items.Add("Stereo");
\r
1004 drp_audioMixDown.Items.Add("Dolby Surround");
\r
1005 drp_audioMixDown.Items.Add("Dolby Pro Logic II");
\r
1007 drp_audioBitrate.Items.Clear();
\r
1008 drp_audioBitrate.Items.Add("32");
\r
1009 drp_audioBitrate.Items.Add("40");
\r
1010 drp_audioBitrate.Items.Add("48");
\r
1011 drp_audioBitrate.Items.Add("56");
\r
1012 drp_audioBitrate.Items.Add("64");
\r
1013 drp_audioBitrate.Items.Add("80");
\r
1014 drp_audioBitrate.Items.Add("86");
\r
1015 drp_audioBitrate.Items.Add("112");
\r
1016 drp_audioBitrate.Items.Add("128");
\r
1017 drp_audioBitrate.Items.Add("160");
\r
1018 drp_audioBitrate.Items.Add("192");
\r
1019 drp_audioBitrate.Items.Add("224");
\r
1020 drp_audioBitrate.Items.Add("256");
\r
1021 drp_audioBitrate.Items.Add("320");
\r
1022 drp_audioBitrate.Items.Add("384");
\r
1026 private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e)
\r
1028 if (drp_audioCodec.Text == "AAC")
\r
1030 if (drp_audioMixDown.Text == "6 Channel Discrete")
\r
1033 drp_audioBitrate.Items.Clear();
\r
1034 drp_audioBitrate.Items.Add("32");
\r
1035 drp_audioBitrate.Items.Add("40");
\r
1036 drp_audioBitrate.Items.Add("48");
\r
1037 drp_audioBitrate.Items.Add("56");
\r
1038 drp_audioBitrate.Items.Add("64");
\r
1039 drp_audioBitrate.Items.Add("80");
\r
1040 drp_audioBitrate.Items.Add("86");
\r
1041 drp_audioBitrate.Items.Add("112");
\r
1042 drp_audioBitrate.Items.Add("128");
\r
1043 drp_audioBitrate.Items.Add("160");
\r
1044 drp_audioBitrate.Items.Add("192");
\r
1045 drp_audioBitrate.Items.Add("224");
\r
1046 drp_audioBitrate.Items.Add("256");
\r
1047 drp_audioBitrate.Items.Add("320");
\r
1048 drp_audioBitrate.Items.Add("384");
\r
1053 private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)
\r
1055 if (Check_ChapterMarkers.Checked)
\r
1057 string destination = text_destination.Text;
\r
1058 destination = destination.Replace(".mp4", ".m4v");
\r
1059 text_destination.Text = destination;
\r
1063 private void check_largeFile_CheckedChanged(object sender, EventArgs e)
\r
1065 if (!text_destination.Text.Contains(".mp4"))
\r
1067 MessageBox.Show("This option is only compatible with the mp4 file container.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1068 check_largeFile.CheckState = CheckState.Unchecked;
\r
1072 private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)
\r
1074 //Turn off some options which are H.264 only when the user selects a non h.264 encoder
\r
1075 if (!drp_videoEncoder.Text.Contains("H.264"))
\r
1077 check_turbo.CheckState = CheckState.Unchecked;
\r
1078 CheckCRF.CheckState = CheckState.Unchecked;
\r
1079 CheckCRF.Enabled = false;
\r
1080 check_turbo.Enabled = false;
\r
1081 h264Tab.Enabled = false;
\r
1085 CheckCRF.Enabled = true;
\r
1086 check_turbo.Enabled = true;
\r
1087 h264Tab.Enabled = true;
\r
1092 public void setStreamReader(Parsing.DVD dvd)
\r
1094 this.thisDVD = dvd;
\r
1097 private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
1099 // Reset some values on the form
\r
1100 lbl_Aspect.Text = "Select a Title";
\r
1101 lbl_RecomendedCrop.Text = "Select a Title";
\r
1102 drop_chapterStart.Items.Clear();
\r
1103 drop_chapterFinish.Items.Clear();
\r
1104 QueryEditorText.Text = "";
\r
1106 // If the dropdown is set to automatic nothing else needs to be done.
\r
1107 // Otheriwse if its not, title data has to be loased from parsing.
\r
1108 if (drp_dvdtitle.Text != "Automatic")
\r
1110 Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;
\r
1112 // Set the Aspect Ratio
\r
1113 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();
\r
1115 // Set the Recommended Cropping values
\r
1116 lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);
\r
1118 // Populate the Start chapter Dropdown
\r
1119 drop_chapterStart.Items.Clear();
\r
1120 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1121 if (drop_chapterStart.Items.Count > 0)
\r
1123 drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();
\r
1126 // Populate the Final Chapter Dropdown
\r
1127 drop_chapterFinish.Items.Clear();
\r
1128 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1129 if (drop_chapterFinish.Items.Count > 0)
\r
1131 drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();
\r
1134 // Populate the Audio Channels Dropdown
\r
1135 drp_audioChannels.Items.Clear();
\r
1136 drp_audioChannels.Items.Add("Automatic");
\r
1137 drp_audioChannels.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
1138 if (drp_audioChannels.Items.Count > 0)
\r
1140 drp_audioChannels.Text = drp_audioChannels.Items[0].ToString();
\r
1143 // Populate the Subtitles dropdown
\r
1144 drp_subtitle.Items.Clear();
\r
1145 drp_subtitle.Items.Add("None");
\r
1146 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());
\r
1147 if (drp_subtitle.Items.Count > 0)
\r
1149 drp_subtitle.Text = drp_subtitle.Items[0].ToString();
\r
1154 //---------------------------------------------------
\r
1155 // The query Generation function.
\r
1156 //---------------------------------------------------
\r
1157 public string GenerateTheQuery()
\r
1159 string source = text_source.Text;
\r
1160 string dvdTitle = drp_dvdtitle.Text;
\r
1161 string chapterStart = drop_chapterStart.Text;
\r
1162 string chapterFinish = drop_chapterFinish.Text;
\r
1163 int totalChapters = drop_chapterFinish.Items.Count - 1;
\r
1164 string dvdChapter = "";
\r
1167 MessageBox.Show("No Source has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1170 source = " -i " + '"' + source+ '"'; //'"'+
\r
1173 if (dvdTitle == "Automatic")
\r
1177 string[] titleInfo = dvdTitle.Split(' ');
\r
1178 dvdTitle = " -t "+ titleInfo[0];
\r
1181 if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))
\r
1183 else if (chapterFinish == chapterStart)
\r
1184 dvdChapter = " -c " + chapterStart;
\r
1186 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;
\r
1188 string querySource = source+ dvdTitle+ dvdChapter;
\r
1189 // ----------------------------------------------------------------------
\r
1193 string destination = text_destination.Text;
\r
1194 string videoEncoder = drp_videoEncoder.Text;
\r
1195 string audioEncoder = drp_audioCodec.Text;
\r
1196 string width = text_width.Text;
\r
1197 string height = text_height.Text;
\r
1199 if (destination == "")
\r
1200 MessageBox.Show("No destination has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1202 destination = " -o " + '"' + destination + '"'; //'"'+
\r
1205 switch (videoEncoder)
\r
1208 videoEncoder = " -e ffmpeg";
\r
1211 videoEncoder = " -e xvid";
\r
1214 videoEncoder = " -e x264";
\r
1216 case "H.264 Baseline 1.3":
\r
1217 videoEncoder = " -e x264b13";
\r
1219 case "H.264 (iPod)":
\r
1220 videoEncoder = " -e x264b30";
\r
1223 videoEncoder = " -e x264";
\r
1227 switch (audioEncoder)
\r
1230 audioEncoder = " -E faac";
\r
1233 audioEncoder = " -E lame";
\r
1236 audioEncoder = " -E vorbis";
\r
1239 audioEncoder = " -E ac3";
\r
1242 audioEncoder = " -E faac";
\r
1247 width = " -w "+ width;
\r
1251 height = " -l "+ height;
\r
1254 string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height;
\r
1255 // ----------------------------------------------------------------------
\r
1257 // Picture Settings Tab
\r
1259 string cropSetting = drp_crop.Text;
\r
1260 string cropTop = text_top.Text;
\r
1261 string cropBottom = text_bottom.Text;
\r
1262 string cropLeft = text_left.Text;
\r
1263 string cropRight = text_right.Text;
\r
1264 string subtitles = drp_subtitle.Text;
\r
1265 string cropOut = "";
\r
1266 // Returns Crop Query
\r
1268 if (cropSetting == "Auto Crop")
\r
1270 else if (cropSetting == "No Crop")
\r
1271 cropOut = " --crop 0:0:0:0 ";
\r
1273 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;
\r
1275 if (subtitles == "None")
\r
1277 else if (subtitles == "")
\r
1282 tempSub = subtitles.Split(' ');
\r
1283 subtitles = " -s "+ tempSub[0];
\r
1286 string queryPictureSettings = cropOut+ subtitles;
\r
1287 // ----------------------------------------------------------------------
\r
1289 // Video Settings Tab
\r
1291 string videoBitrate = text_bitrate.Text;
\r
1292 string videoFilesize = text_filesize.Text;
\r
1293 int videoQuality = slider_videoQuality.Value;
\r
1294 string vidQSetting = "";
\r
1295 string twoPassEncoding = "";
\r
1296 string deinterlace = "";
\r
1297 string grayscale = "";
\r
1298 string videoFramerate = drp_videoFramerate.Text;
\r
1299 string pixelRatio = "";
\r
1300 string ChapterMarkers = "";
\r
1301 string turboH264 = "";
\r
1302 string largeFile = "";
\r
1304 if (videoBitrate != "")
\r
1305 videoBitrate = " -b "+ videoBitrate;
\r
1307 if (videoFilesize != "")
\r
1308 videoFilesize = " -S "+ videoFilesize;
\r
1310 // Video Quality Setting
\r
1312 if ((videoQuality == 0))
\r
1316 videoQuality = videoQuality/ 100;
\r
1317 if (videoQuality == 1)
\r
1319 vidQSetting = "1.0";
\r
1322 vidQSetting = " -q " + videoQuality.ToString();
\r
1325 if (check_2PassEncode.Checked)
\r
1326 twoPassEncoding = " -2 ";
\r
1328 if (check_DeInterlace.Checked)
\r
1329 deinterlace = " -d ";
\r
1331 if (check_grayscale.Checked)
\r
1332 grayscale = " -g ";
\r
1334 if (videoFramerate == "Automatic")
\r
1335 videoFramerate = "";
\r
1337 videoFramerate = " -r "+ videoFramerate;
\r
1339 if (CheckPixelRatio.Checked)
\r
1340 pixelRatio = " -p ";
\r
1342 if (Check_ChapterMarkers.Checked)
\r
1343 ChapterMarkers = " -m ";
\r
1345 if (check_turbo.Checked)
\r
1346 turboH264 = " -T ";
\r
1348 if (check_largeFile.Checked)
\r
1349 largeFile = " -4 ";
\r
1351 string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + deinterlace + grayscale + videoFramerate + pixelRatio + ChapterMarkers + turboH264 + largeFile;
\r
1352 // ----------------------------------------------------------------------
\r
1354 // Audio Settings Tab
\r
1356 string audioBitrate = drp_audioBitrate.Text;
\r
1357 string audioSampleRate = drp_audioSampleRate.Text;
\r
1358 string audioChannels = drp_audioChannels.Text;
\r
1359 string Mixdown = drp_audioMixDown.Text;
\r
1360 string SixChannelAudio = "";
\r
1362 if (audioBitrate != "")
\r
1363 audioBitrate = " -B "+ audioBitrate;
\r
1365 if (audioSampleRate != "")
\r
1366 audioSampleRate = " -R "+ audioSampleRate;
\r
1368 if (audioChannels == "Automatic")
\r
1369 audioChannels = "";
\r
1370 else if (audioChannels == "")
\r
1371 audioChannels = "";
\r
1375 tempSub = audioChannels.Split(' ');
\r
1376 audioChannels = " -a "+ tempSub[0];
\r
1388 Mixdown = "stereo";
\r
1390 case "Dolby Surround":
\r
1393 case "Dolby Pro Logic II":
\r
1396 case "6 Channel Discrete":
\r
1400 Mixdown = "stero";
\r
1404 if (Mixdown != "")
\r
1405 SixChannelAudio = " -6 "+ Mixdown;
\r
1407 SixChannelAudio = "";
\r
1409 string queryAudioSettings = audioBitrate+ audioSampleRate+ audioChannels+ SixChannelAudio;
\r
1410 // ----------------------------------------------------------------------
\r
1414 string CRF = CheckCRF.CheckState.ToString();
\r
1415 string h264Advanced = rtf_h264advanced.Text;
\r
1421 if ((h264Advanced == ""))
\r
1422 h264Advanced = "";
\r
1424 h264Advanced = " -x "+ h264Advanced;
\r
1427 string h264Settings = CRF+ h264Advanced;
\r
1428 // ----------------------------------------------------------------------
\r
1430 // Processors (Program Settings)
\r
1432 string processors = Properties.Settings.Default.Processors;
\r
1433 // Number of Processors Handler
\r
1435 if (processors == "Automatic")
\r
1438 processors = " -C "+ processors+ " ";
\r
1441 string queryAdvancedSettings = processors;
\r
1442 // ----------------------------------------------------------------------
\r
1444 // Verbose option (Program Settings)
\r
1446 string verbose = "";
\r
1447 if (Properties.Settings.Default.verbose == "Checked")
\r
1450 // ----------------------------------------------------------------------
\r
1452 return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;
\r
1457 // This is the END of the road ------------------------------------------------------------------------------
\r