OSDN Git Service

Change the fifo size from being statically tuned for a Mac Pro with 4 CPUs to dynamic...
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Collections.Specialized;\r
4 using System.ComponentModel;\r
5 using System.Data;\r
6 using System.Drawing;\r
7 using System.Text;\r
8 using System.Windows.Forms;\r
9 using System.Net;\r
10 using System.IO;\r
11 using System.Diagnostics;\r
12 using System.Threading;\r
13 using System.Runtime.InteropServices;\r
14 \r
15 \r
16 namespace Handbrake\r
17 {\r
18 \r
19     public partial class frmMain : Form\r
20     {\r
21         // -------------------------------------------------------------- \r
22         // Applicaiton Startup Stuff\r
23         // --------------------------------------------------------------\r
24 \r
25         #region Application Startup\r
26 \r
27         private Process hbProc;\r
28         private Parsing.DVD thisDVD;        \r
29         private frmQueue queueWindow = new frmQueue();  \r
30 \r
31         public frmMain()\r
32         {\r
33 \r
34             // Load the splash screen on another thread. Once completed wait for 1 second.\r
35             ThreadPool.QueueUserWorkItem(showSplash); \r
36             Thread.Sleep(1000);\r
37 \r
38             InitializeComponent();\r
39 \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
44 \r
45             // Set the Version number lable to the corect version.\r
46             Version.Text = "Version " + Properties.Settings.Default.CliVersion;\r
47 \r
48             // Run the update checker.\r
49             updateCheck();\r
50 \r
51             // Now load the users default if required. (Will overide the above setting)\r
52             loadUserDefaults();\r
53 \r
54             // Enable or disable tooltips\r
55             tooltip();\r
56 \r
57             // Hide the presets part of the window\r
58             this.Width = 590;\r
59 \r
60             showPresets();\r
61 \r
62             /*\r
63              * This code can be used for storing preset and preset name information in future versions.\r
64              * Please ignore it for the moment.\r
65             // Create and initialize a new StringCollection.\r
66             StringCollection myCol = new StringCollection();\r
67             // Add a range of elements from an array to the end of the StringCollection.\r
68             String[] myArr = new String[] { "RED", "orange", "yellow", "RED", "green", "blue", "RED", "indigo", "violet", "RED" };\r
69             myCol.AddRange(myArr);\r
70             Properties.Settings.Default.BuiltInPresets = myCol;\r
71             MessageBox.Show(Properties.Settings.Default.BuiltInPresets.ToString());\r
72             */\r
73         }\r
74 \r
75         private void showSplash(object sender)\r
76         {\r
77             // Display splash screen for 1.5 Seconds\r
78             Form splash = new frmSplashScreen();\r
79             splash.Show();\r
80             Thread.Sleep(1500);  \r
81             splash.Close(); // Then close.\r
82         }\r
83 \r
84         private void loadUserDefaults()\r
85         { \r
86             try\r
87             {\r
88                 // Load the users default settings or if the user has not got this option enabled, load the normal preset.\r
89                 if (Properties.Settings.Default.defaultSettings == "Checked")\r
90                 {\r
91                     // Source\r
92                     text_source.Text = Properties.Settings.Default.DVDSource;\r
93                     drp_dvdtitle.Text = Properties.Settings.Default.DVDTitle;\r
94                     drop_chapterStart.Text = Properties.Settings.Default.ChapterStart;\r
95                     drop_chapterFinish.Text = Properties.Settings.Default.ChapterFinish;\r
96 \r
97                     // Destination\r
98                     text_destination.Text = Properties.Settings.Default.VideoDest;\r
99                     drp_videoEncoder.Text = Properties.Settings.Default.VideoEncoder;\r
100                     drp_audioCodec.Text = Properties.Settings.Default.AudioEncoder;\r
101                     text_width.Text = Properties.Settings.Default.Width;\r
102                     text_height.Text = Properties.Settings.Default.Height;\r
103 \r
104                     // Picture Settings Tab\r
105                     drp_crop.Text = Properties.Settings.Default.CroppingOption;\r
106                     text_top.Text = Properties.Settings.Default.CropTop;\r
107                     text_bottom.Text = Properties.Settings.Default.CropBottom;\r
108                     text_left.Text = Properties.Settings.Default.CropLeft;\r
109                     text_right.Text = Properties.Settings.Default.CropRight;\r
110                     drp_subtitle.Text = Properties.Settings.Default.Subtitles;\r
111 \r
112                     // Video Settings Tab\r
113                     text_bitrate.Text = Properties.Settings.Default.VideoBitrate;\r
114                     text_filesize.Text = Properties.Settings.Default.VideoFilesize;\r
115                     slider_videoQuality.Value = Properties.Settings.Default.VideoQuality;\r
116 \r
117                     if (Properties.Settings.Default.TwoPass == "Checked")\r
118                     {\r
119                         check_2PassEncode.CheckState = CheckState.Checked;\r
120                     }\r
121 \r
122                     drp_deInterlace_option.Text = Properties.Settings.Default.DeInterlace;\r
123                     drp_deNoise.Text = Properties.Settings.Default.denoise;\r
124 \r
125                     if (Properties.Settings.Default.detelecine == "Checked")\r
126                     {\r
127                         check_detelecine.CheckState = CheckState.Checked;\r
128                     }\r
129 \r
130                     if (Properties.Settings.Default.detelecine == "Checked")\r
131                     {\r
132                         check_deblock.CheckState = CheckState.Checked;\r
133                     }\r
134 \r
135 \r
136                     if (Properties.Settings.Default.Grayscale == "Checked")\r
137                     {\r
138                         check_grayscale.CheckState = CheckState.Checked;\r
139                     }\r
140 \r
141                     drp_videoFramerate.Text = Properties.Settings.Default.Framerate;\r
142 \r
143                     if (Properties.Settings.Default.PixelRatio == "Checked")\r
144                     {\r
145                         CheckPixelRatio.CheckState = CheckState.Checked;\r
146                     }\r
147                     if (Properties.Settings.Default.turboFirstPass == "Checked")\r
148                     {\r
149                         check_turbo.CheckState = CheckState.Checked;\r
150                     }\r
151                     if (Properties.Settings.Default.largeFile == "Checked")\r
152                     {\r
153                         check_largeFile.CheckState = CheckState.Checked;\r
154                     }\r
155                     // Audio Settings Tab\r
156                     drp_audioBitrate.Text = Properties.Settings.Default.AudioBitrate;\r
157                     drp_audioSampleRate.Text = Properties.Settings.Default.AudioSampleRate;\r
158                     drp_audioChannels.Text = Properties.Settings.Default.AudioChannels;\r
159 \r
160                     // H264 Tab\r
161                     if (Properties.Settings.Default.CRF == "Checked")\r
162                     {\r
163                         CheckCRF.CheckState = CheckState.Checked;\r
164                     }\r
165                     rtf_h264advanced.Text = Properties.Settings.Default.H264;\r
166 \r
167                     groupBox_output.Text = "Output Settings (Preset: " + Properties.Settings.Default.selectedPreset + ")";\r
168                 }\r
169                 else\r
170                 {\r
171                     // Load the default preset on lauch\r
172                     ListBox_Presets.SelectedItem = "Normal";\r
173                 }\r
174             }\r
175             catch (Exception)\r
176             {\r
177                 // No real need to alert the user. Try/Catch only in just incase there is a problem reading the settings xml file.\r
178             }\r
179         }\r
180 \r
181         private Boolean updateCheck()\r
182         {\r
183             try\r
184             {\r
185                 if (Properties.Settings.Default.updateStatus == "Checked")\r
186                 {\r
187                     String updateFile = Properties.Settings.Default.updateFile;\r
188                     WebClient client = new WebClient();\r
189                     String data = client.DownloadString(updateFile);\r
190                     String[] versionData = data.Split('\n');\r
191 \r
192                     int verdata = int.Parse(versionData[0].Replace(".", ""));\r
193                     int vergui = int.Parse(Properties.Settings.Default.GuiVersion.Replace(".", ""));\r
194                     int verd1 = int.Parse(versionData[1].Replace(".", ""));\r
195                     int cliversion = int.Parse(Properties.Settings.Default.CliVersion.Replace(".", ""));\r
196 \r
197                     Boolean update = ((verdata > vergui) || (verd1 > cliversion));\r
198    \r
199                     lbl_update.Visible = update;\r
200 \r
201                     return update;   \r
202                 }\r
203                 else\r
204                 {\r
205                     return false;\r
206                 }\r
207             }\r
208             catch (Exception)\r
209             {\r
210                 // Silently ignore the error\r
211                 return false;\r
212             }\r
213         }\r
214 \r
215         private void tooltip()\r
216         {\r
217             if (Properties.Settings.Default.tooltipEnable == "Checked")\r
218             {\r
219                 ToolTip.Active = true;\r
220             }\r
221         }\r
222 \r
223         private void showPresets()\r
224         {\r
225             if (Properties.Settings.Default.showPresets == "Checked")\r
226             {\r
227                 btn_presets.Visible = false;\r
228                 this.Width = 881;\r
229             }\r
230 \r
231         }\r
232 \r
233         #endregion\r
234 \r
235         // -------------------------------------------------------------- \r
236         // The main Menu bar.\r
237         // -------------------------------------------------------------- \r
238 \r
239         #region File Menu\r
240 \r
241         private void mnu_exit_Click(object sender, EventArgs e)\r
242         {\r
243             Application.Exit();\r
244         }\r
245 \r
246         #endregion\r
247 \r
248         #region Tools Menu\r
249 \r
250         private void mnu_encode_Click(object sender, EventArgs e)\r
251         {\r
252             showQueue();\r
253         }\r
254    \r
255         private void mnu_viewDVDdata_Click(object sender, EventArgs e)\r
256         {\r
257             frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
258             dvdInfoWindow.Show();\r
259         }\r
260 \r
261         private void mnu_options_Click(object sender, EventArgs e)\r
262         {\r
263             Form Options = new frmOptions();\r
264             Options.ShowDialog();\r
265         }\r
266 \r
267         #endregion\r
268 \r
269         #region Presets Menu\r
270 \r
271         private void mnu_presetReset_Click(object sender, EventArgs e)\r
272         {\r
273             ListBox_Presets.Items.Clear();\r
274             ListBox_Presets.Items.Add("Animation");\r
275             ListBox_Presets.Items.Add("AppleTV");\r
276             ListBox_Presets.Items.Add("Bedlam");\r
277             ListBox_Presets.Items.Add("Blind");\r
278             ListBox_Presets.Items.Add("Broke");\r
279             ListBox_Presets.Items.Add("Classic");\r
280             ListBox_Presets.Items.Add("Constant Quality Rate");\r
281             ListBox_Presets.Items.Add("Deux Six Quatre");\r
282             ListBox_Presets.Items.Add("Film");\r
283             ListBox_Presets.Items.Add("iPhone");\r
284             ListBox_Presets.Items.Add("iPod High-Rez");\r
285             ListBox_Presets.Items.Add("iPod Low-Rez");\r
286             ListBox_Presets.Items.Add("Normal");\r
287             ListBox_Presets.Items.Add("PS3");\r
288             ListBox_Presets.Items.Add("PSP");\r
289             ListBox_Presets.Items.Add("QuickTime");\r
290             ListBox_Presets.Items.Add("Television");\r
291 \r
292             if (presetStatus == false)\r
293             {\r
294                 this.Width = 881;\r
295                 presetStatus = true;\r
296                 btn_presets.Text = "Hide Presets";\r
297             }\r
298         }\r
299 \r
300         private void mnu_SelectDefault_Click(object sender, EventArgs e)\r
301         {\r
302             ListBox_Presets.SelectedItem = "Normal";\r
303             if (presetStatus == false)\r
304             {\r
305                 this.Width = 881;\r
306                 presetStatus = true;\r
307                 btn_presets.Text = "Hide Presets";\r
308             }\r
309         }\r
310 \r
311         #endregion\r
312 \r
313         #region Help Menu\r
314 \r
315 \r
316         private void mnu_quickStart_Click(object sender, EventArgs e)\r
317         {\r
318             Form QuickStart = new frmQuickStart();\r
319             QuickStart.ShowDialog();\r
320         }\r
321 \r
322         private void mnu_wiki_Click(object sender, EventArgs e)\r
323         {\r
324            Process.Start("http://handbrake.m0k.org/trac");\r
325         }\r
326 \r
327         private void mnu_faq_Click(object sender, EventArgs e)\r
328         {\r
329             Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");\r
330         }\r
331 \r
332         private void mnu_onlineDocs_Click(object sender, EventArgs e)\r
333         {\r
334             Process.Start("http://handbrake.m0k.org/?page_id=11");\r
335         }\r
336 \r
337         private void mnu_homepage_Click(object sender, EventArgs e)\r
338         {\r
339            Process.Start("http://handbrake.m0k.org");\r
340         }\r
341 \r
342         private void mnu_forum_Click(object sender, EventArgs e)\r
343         {\r
344             Process.Start("http://handbrake.m0k.org/forum");\r
345         }\r
346 \r
347         private void mnu_UpdateCheck_Click(object sender, EventArgs e)\r
348         {\r
349             Boolean update = updateCheck();\r
350             if (update == true)\r
351             {\r
352                 MessageBox.Show("There is a new update available. Please visit http://handbrake.m0k.org for details!", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
353             }\r
354             else\r
355             {\r
356                 MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
357             }\r
358         }\r
359 \r
360         private void mnu_about_Click(object sender, EventArgs e)\r
361         {\r
362                         Form About = new frmAbout();\r
363             About.ShowDialog();\r
364         }\r
365 \r
366         #endregion\r
367 \r
368         // -------------------------------------------------------------- \r
369         // Buttons on the main Window\r
370         // --------------------------------------------------------------\r
371 \r
372         #region Buttons\r
373 \r
374         private void btn_Browse_Click(object sender, EventArgs e)\r
375         {\r
376             String filename = ""; \r
377                     text_source.Text = "";\r
378             frmDvdInfo dvdInfoWindow = new frmDvdInfo();                 \r
379                     if (RadioDVD.Checked) \r
380                     { \r
381                         DVD_Open.ShowDialog(); \r
382                         filename = DVD_Open.SelectedPath; \r
383                         if (filename != "") \r
384                         { \r
385                             Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); \r
386                             text_source.Text = filename; \r
387                             frmRD.ShowDialog(); \r
388                         } \r
389                      } \r
390                      else \r
391                      { \r
392                         ISO_Open.ShowDialog(); \r
393                         filename = ISO_Open.FileName; \r
394                         if (filename != "") \r
395                         { \r
396                             Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); \r
397                             text_source.Text = filename; \r
398                             frmRD.ShowDialog(); \r
399                         } \r
400                      }   \r
401                  \r
402                      // Check if there was titles in the dvd title dropdown \r
403                      if (filename == "") \r
404                      { \r
405                         text_source.Text = "Click 'Browse' to continue"; \r
406                      } \r
407                     \r
408              // If there are no titles in the dropdown menu then the scan has obviously failed. Display an error message explaining to the user.\r
409                      if (drp_dvdtitle.Items.Count == 0) \r
410                      { \r
411                         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
412                      }                  \r
413         }\r
414 \r
415         private void btn_destBrowse_Click(object sender, EventArgs e)\r
416         {\r
417             DVD_Save.ShowDialog();\r
418             text_destination.Text = DVD_Save.FileName;\r
419 \r
420             if (Check_ChapterMarkers.Checked)\r
421             {\r
422                 string destination = text_destination.Text;\r
423                 destination = destination.Replace(".mp4", ".m4v");\r
424                 text_destination.Text = destination;\r
425             }\r
426         }\r
427 \r
428         private void btn_h264Clear_Click(object sender, EventArgs e)\r
429         {\r
430             rtf_h264advanced.Text = "";\r
431         }\r
432 \r
433         private void GenerateQuery_Click(object sender, EventArgs e)\r
434         {\r
435             String query = GenerateTheQuery();\r
436             QueryEditorText.Text = query;\r
437         }\r
438 \r
439         private void btn_ClearQuery_Click(object sender, EventArgs e)\r
440         {\r
441             QueryEditorText.Text = "";\r
442         }\r
443 \r
444         private void btn_queue_Click(object sender, EventArgs e)\r
445         {\r
446             if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "")\r
447                 MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
448             else\r
449             {\r
450                 string query;\r
451                 if (QueryEditorText.Text == "")\r
452                 {\r
453                     query = GenerateTheQuery();\r
454                 }\r
455                 else\r
456                 {\r
457                     query = QueryEditorText.Text;\r
458                 }\r
459                 queueWindow.list_queue.Items.Add(query);\r
460                 queueWindow.Show();\r
461             } \r
462         }\r
463 \r
464         private void btn_copy_Click(object sender, EventArgs e)\r
465         {\r
466             Clipboard.SetText(QueryEditorText.Text, TextDataFormat.Text);\r
467         }\r
468 \r
469         private void showQueue()\r
470         {\r
471             queueWindow.Show();\r
472         }\r
473 \r
474         #endregion\r
475 \r
476         // -------------------------------------------------------------- \r
477         // Main Window Preset System\r
478         // --------------------------------------------------------------\r
479 \r
480         #region Preset System\r
481 \r
482         // Varibles\r
483         private Boolean presetStatus = false;\r
484 \r
485         // Buttons\r
486         private void btn_presets_Click(object sender, EventArgs e)\r
487         {\r
488             if (presetStatus == false)\r
489             {\r
490                 this.Width = 881;\r
491                 presetStatus = true;\r
492                 btn_presets.Text = "Hide Presets";\r
493             }\r
494             else\r
495             {\r
496                 this.Width = 590;\r
497                 presetStatus = false;\r
498                 btn_presets.Text = "Show Presets";\r
499             }\r
500 \r
501         }\r
502 \r
503         private void btn_addPreset_Click(object sender, EventArgs e)\r
504         {\r
505             string filename;\r
506             File_Open.ShowDialog();\r
507             filename = File_Open.FileName;\r
508             if (filename != "")\r
509             {\r
510                 try\r
511                 {\r
512                     // Create StreamReader & open file\r
513                     StreamReader line = new StreamReader(filename);\r
514                     string temporyLine; // Used for reading the line into a varible before processing on the checkState items below.\r
515 \r
516                     // Read in the data and set the correct GUI component with the setting.\r
517                     text_source.Text = line.ReadLine();\r
518                     drp_dvdtitle.Text = line.ReadLine();\r
519                     drop_chapterStart.Text = line.ReadLine();\r
520                     drop_chapterFinish.Text = line.ReadLine();\r
521                     text_destination.Text = line.ReadLine();\r
522                     drp_videoEncoder.Text = line.ReadLine();\r
523                     drp_audioCodec.Text = line.ReadLine();\r
524                     text_width.Text = line.ReadLine();\r
525                     text_height.Text = line.ReadLine();\r
526                     text_top.Text = line.ReadLine();\r
527                     text_bottom.Text = line.ReadLine();\r
528                     text_left.Text = line.ReadLine();\r
529                     text_right.Text = line.ReadLine();\r
530                     drp_subtitle.Text = line.ReadLine();\r
531                     text_bitrate.Text = line.ReadLine();\r
532                     text_filesize.Text = line.ReadLine();\r
533                     slider_videoQuality.Value = int.Parse(line.ReadLine());\r
534 \r
535                     temporyLine = line.ReadLine();\r
536                     if (temporyLine == "Checked")\r
537                     {\r
538                         check_2PassEncode.CheckState = CheckState.Checked;\r
539                     }\r
540 \r
541                     drp_deInterlace_option.Text = line.ReadLine();\r
542 \r
543                     temporyLine = line.ReadLine();\r
544                     if (temporyLine == "Checked")\r
545                     {\r
546                         check_grayscale.CheckState = CheckState.Checked;\r
547                     }\r
548 \r
549                     drp_videoFramerate.Text = line.ReadLine();\r
550 \r
551                     temporyLine = line.ReadLine();\r
552                     if (temporyLine == "Checked")\r
553                     {\r
554                         Check_ChapterMarkers.CheckState = CheckState.Checked;\r
555                     }\r
556 \r
557                     temporyLine = line.ReadLine();\r
558                     if (temporyLine == "Checked")\r
559                     {\r
560                         CheckPixelRatio.CheckState = CheckState.Checked;\r
561                     }\r
562 \r
563                     temporyLine = line.ReadLine();\r
564                     if (temporyLine == "Checked")\r
565                     {\r
566                         check_turbo.CheckState = CheckState.Checked;\r
567                     }\r
568 \r
569                     temporyLine = line.ReadLine();\r
570                     if (temporyLine == "Checked")\r
571                     {\r
572                         check_largeFile.CheckState = CheckState.Checked;\r
573                     }\r
574 \r
575                     drp_audioBitrate.Text = line.ReadLine();\r
576                     drp_audioSampleRate.Text = line.ReadLine();\r
577                     drp_audioChannels.Text = line.ReadLine();\r
578                     drp_audioMixDown.Text = line.ReadLine();\r
579 \r
580                     // Advanced H264 Options\r
581                     temporyLine = line.ReadLine();\r
582                     if (temporyLine == "Checked")\r
583                     {\r
584                         CheckCRF.CheckState = CheckState.Checked;\r
585                     }\r
586                     rtf_h264advanced.Text = line.ReadLine();\r
587 \r
588                     // Close the stream\r
589                     line.Close();\r
590 \r
591 \r
592                     // Fix for SliderValue not appearing when Opening saved file\r
593                     SliderValue.Text = slider_videoQuality.Value + "%";\r
594 \r
595                 }\r
596                 catch (Exception)\r
597                 {\r
598                     MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
599                 }\r
600             }\r
601         }\r
602 \r
603         private void btn_removePreset_Click(object sender, EventArgs e)\r
604         {\r
605             string filename;\r
606             File_Save.ShowDialog();\r
607             filename = File_Save.FileName;\r
608             if (filename != "")\r
609             {\r
610                 try\r
611                 {\r
612                     // Create a StreamWriter and open the file\r
613                     StreamWriter line = new StreamWriter(filename);\r
614 \r
615                     //Source\r
616                     line.WriteLine(text_source.Text);\r
617                     line.WriteLine(drp_dvdtitle.Text);\r
618                     line.WriteLine(drop_chapterStart.Text);\r
619                     line.WriteLine(drop_chapterFinish.Text);\r
620                     //Destination\r
621                     line.WriteLine(text_destination.Text);\r
622                     line.WriteLine(drp_videoEncoder.Text);\r
623                     line.WriteLine(drp_audioCodec.Text);\r
624                     line.WriteLine(text_width.Text);\r
625                     line.WriteLine(text_height.Text);\r
626                     //Picture Settings Tab\r
627                     line.WriteLine(text_top.Text);\r
628                     line.WriteLine(text_bottom.Text);\r
629                     line.WriteLine(text_left.Text);\r
630                     line.WriteLine(text_right.Text);\r
631                     line.WriteLine(drp_subtitle.Text);\r
632                     //Video Settings Tab\r
633                     line.WriteLine(text_bitrate.Text);\r
634                     line.WriteLine(text_filesize.Text);\r
635                     line.WriteLine(slider_videoQuality.Value.ToString());\r
636                     line.WriteLine(check_2PassEncode.CheckState.ToString());\r
637                     line.WriteLine(drp_deInterlace_option.Text);\r
638                     line.WriteLine(check_grayscale.CheckState.ToString());\r
639                     line.WriteLine(drp_videoFramerate.Text);\r
640                     line.WriteLine(Check_ChapterMarkers.CheckState.ToString());\r
641                     line.WriteLine(CheckPixelRatio.CheckState.ToString());\r
642                     line.WriteLine(check_turbo.CheckState.ToString());\r
643                     line.WriteLine(check_largeFile.CheckState.ToString());\r
644                     //Audio Settings Tab\r
645                     line.WriteLine(drp_audioBitrate.Text);\r
646                     line.WriteLine(drp_audioSampleRate.Text);\r
647                     line.WriteLine(drp_audioChannels.Text);\r
648                     line.WriteLine(drp_audioMixDown.Text);\r
649                     //H264 Tab\r
650                     line.WriteLine(CheckCRF.CheckState.ToString());\r
651                     line.WriteLine(rtf_h264advanced.Text);\r
652                     // close the stream\r
653                     line.Close();\r
654                     MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
655                 }\r
656                 catch (Exception)\r
657                 {\r
658                     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
659                 }\r
660 \r
661             }\r
662         }\r
663 \r
664         private void btn_setDefault_Click(object sender, EventArgs e)\r
665         {\r
666             //Source\r
667             Properties.Settings.Default.DVDSource = text_source.Text;\r
668             Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;\r
669             Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;\r
670             Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;\r
671             //Destination\r
672             Properties.Settings.Default.VideoDest = text_destination.Text;\r
673             Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;\r
674             Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;\r
675             Properties.Settings.Default.Width = text_width.Text;\r
676             Properties.Settings.Default.Height = text_height.Text;\r
677             //Picture Settings Tab\r
678             Properties.Settings.Default.CroppingOption = drp_crop.Text;\r
679             Properties.Settings.Default.CropTop = text_top.Text;\r
680             Properties.Settings.Default.CropBottom = text_bottom.Text;\r
681             Properties.Settings.Default.CropLeft = text_left.Text;\r
682             Properties.Settings.Default.CropRight = text_right.Text;\r
683             Properties.Settings.Default.Subtitles = drp_subtitle.Text;\r
684             //Video Settings Tab\r
685             Properties.Settings.Default.VideoBitrate = text_bitrate.Text;\r
686             Properties.Settings.Default.VideoFilesize = text_filesize.Text;\r
687             Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;\r
688             Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();\r
689             Properties.Settings.Default.DeInterlace = drp_deInterlace_option.Text;\r
690             Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();\r
691             Properties.Settings.Default.Framerate = drp_videoFramerate.Text;\r
692             Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();\r
693             Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();\r
694             Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString();\r
695             Properties.Settings.Default.detelecine = check_detelecine.CheckState.ToString();\r
696             Properties.Settings.Default.denoise = drp_deNoise.Text;\r
697             Properties.Settings.Default.deblock = check_deblock.CheckState.ToString();\r
698             //Audio Settings Tab\r
699             Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;\r
700             Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;\r
701             Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;\r
702             //H264 Tab\r
703             Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();\r
704             Properties.Settings.Default.H264 = rtf_h264advanced.Text;\r
705             try\r
706             {\r
707                 Properties.Settings.Default.selectedPreset = ListBox_Presets.SelectedItem.ToString();\r
708             }\r
709             catch (Exception exc)\r
710             {\r
711                 // If the user has not selected an item, then an exception may be thrown. Catch and ignore.\r
712             }\r
713             Properties.Settings.Default.Save();\r
714         }\r
715 \r
716         // Preset Seleciton\r
717         private void ListBox_Presets_SelectedIndexChanged(object sender, EventArgs e)\r
718         {\r
719             string selectedPreset = null;\r
720             if (ListBox_Presets.SelectedItem != null)\r
721             {\r
722                 selectedPreset = ListBox_Presets.SelectedItem.ToString();\r
723             }\r
724             else\r
725             {\r
726                 selectedPreset = "";\r
727             }\r
728 \r
729             switch (selectedPreset)\r
730             {\r
731                 case "Animation":\r
732                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "1000", "", 0, "0%", "160", CheckState.Checked, "48", "ref=5:mixed-refs:bframes=6:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=5:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip:filter=2,2", "Origional (Fast)", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Apple Animation)");\r
733                     setMkv();\r
734                     break;\r
735                 case "AppleTV":\r
736                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "2500", "", 0, "0%", "160", CheckState.Checked, "48", "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:trellis=2", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: Apple TV)");\r
737                     break;\r
738                 case "Bedlam":\r
739                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "1800", "", 0, "0%", "160", CheckState.Checked, "48", "ref=16:mixed-refs:bframes=6:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=7:me-range=64:analyse=all:8x8dct:trellis=2:no-fast-pskip:no-dct-decimate:filter=-2,-1", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Bedlam)");\r
740                     setMkv();\r
741                     break;\r
742                 case "Blind":\r
743                     setGuiSetttings(CheckState.Unchecked, "512", "", "H.264", "512", "", 0, "0%", "128", CheckState.Checked, "48", "", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: Blind)");\r
744                     break;\r
745                 case "Broke":\r
746                     setGuiSetttings(CheckState.Unchecked, "640", "", "H.264", "", "695", 0, "0%", "128", CheckState.Checked, "48", "ref=3:mixed-refs:bframes=6:bime:weightb:b-rdo:b-pyramid::direct=auto:me=umh:subme=6:trellis=1:analyse=all:8x8dct:no-fast-pskip", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Broke)");\r
747                     break;\r
748                 case "Classic":\r
749                     setGuiSetttings(CheckState.Unchecked, "", "", "H.264", "1000", "", 0, "0%", "160", CheckState.Unchecked, "48", "", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: Classic)");\r
750                     break;\r
751                 case "Constant Quality Rate":\r
752                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "", "", 64, "64%", "160", CheckState.Checked, "48", "ref=3:mixed-refs:bframes=3:b-pyramid:b-rdo:bime:weightb:filter=-2,-1:subme=6:trellis=1:analyse=all:8x8dct:me=umh", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AC3", "Output Settings (Preset: CQR)");\r
753                     setMkv();\r
754                     break;\r
755                 case "Deux Six Quatre":\r
756                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "1600", "", 0, "0%", "160", CheckState.Checked, "48", "ref=5:mixed-refs:bframes=3:bime:weightb:b-rdo:b-pyramid:me=umh:subme=7:trellis=1:analyse=all:8x8dct:no-fast-pskip", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AC3", "Output Settings (Preset: DSQ)");\r
757                     setMkv();\r
758                     break;\r
759                 case "Film":\r
760                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "2000", "", 0, "0%", "160", CheckState.Checked, "48", "ref=3:mixed-refs:bframes=3:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=6:analyse=all:8x8dct:trellis=1:no-fast-pskip", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AC3", "Output Settings (Preset: Film)");\r
761                     setMkv();\r
762                     break;\r
763                 case "iPhone":\r
764                     setGuiSetttings(CheckState.Unchecked, "480", "", "H.264", "960", "", 0, "0%", "128", CheckState.Checked, "48", "cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=1", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: iPhone)");\r
765                     break;\r
766                 case "iPod High-Rez":\r
767                     setGuiSetttings(CheckState.Unchecked, "640", "", "H.264", "1500", "", 0, "0%", "160", CheckState.Checked, "48", "keyint=300:keyint-min=30:bframes=0:cabac=0:ref=1:vbv-maxrate=1500:vbv-bufsize=2000:analyse=all:me=umh:subme=6:no-fast-pskip=1", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: iPod High Rez)");\r
768                     break;\r
769                 case "iPod Low-Rez":\r
770                     setGuiSetttings(CheckState.Unchecked, "320", "", "H.264", "700", "", 0, "0%", "160", CheckState.Checked, "48", "keyint=300:keyint-min=30:bframes=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:subme=6:no-fast-pskip=1", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: iPod Low Rez)");\r
771                     break;\r
772                 case "Normal":\r
773                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "1500", "", 0, "0%", "160", CheckState.Checked, "48", "ref=2:bframes=2:subme=5:me=umh", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Normal)");\r
774                     break;\r
775                 case "PS3":\r
776                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "2500", "", 0, "0%", "160", CheckState.Checked, "48", "level=41:subme=5:me=umh", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: PS3)");\r
777                     break;\r
778                 case "PSP":\r
779                     setGuiSetttings(CheckState.Unchecked, "368", "208", "Mpeg 4", "1024", "", 0, "0%", "160", CheckState.Unchecked, "48", "", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: PSP)");\r
780                     break;\r
781                 case "QuickTime":\r
782                     setGuiSetttings(CheckState.Checked, "", "", "H.264", "2000", "", 0, "0%", "160", CheckState.Checked, "48", "ref=3:mixed-refs:bframes=3:bime:weightb:b-rdo:direct-auto:me=umh:subme=5:analyse=all:8x8dct:trellis=1:no-fast-pskip", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Quicktime)");\r
783                     break;\r
784                 case "Television":\r
785                     setGuiSetttings(CheckState.Unchecked, "", "", "H.264", "1300", "", 0, "0%", "160", CheckState.Checked, "48", "ref=3:mixed-refs:bframes=6:bime:weightb:direct=auto:b-pyramid:me=umh:subme=6:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip", "Origional (Fast)", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Television)");\r
786                     setMkv();\r
787                     break;\r
788                 default:\r
789                     break;\r
790             }\r
791         }\r
792 \r
793         // Functions - It's a bit dirty but i'll sort this out later. Simply done to reduce the amount of code above.\r
794         private void setGuiSetttings(CheckState anamorphic, string width, string height, string vencoder, string bitrate, string filesize, int quality, string qpercent, string audioBit, CheckState chpt, string audioSample, string h264, string deinterlace, CheckState twopass, string crop, CheckState turbo, string audioCodec, string preset)\r
795         {\r
796             CheckPixelRatio.CheckState = anamorphic;\r
797             text_width.Text = width;\r
798             text_height.Text = height;\r
799             drp_videoEncoder.Text = vencoder;\r
800             text_bitrate.Text = bitrate;\r
801             text_filesize.Text = filesize;\r
802             slider_videoQuality.Value = quality;\r
803             SliderValue.Text = qpercent;\r
804             drp_audioBitrate.Text = audioBit;\r
805             Check_ChapterMarkers.CheckState = chpt;\r
806             drp_audioSampleRate.Text = audioSample;\r
807             rtf_h264advanced.Text = h264;\r
808             drp_deInterlace_option.Text = deinterlace;\r
809             check_2PassEncode.CheckState = twopass;\r
810             drp_crop.Text = crop;\r
811             check_turbo.CheckState = turbo;\r
812             drp_audioCodec.Text = audioCodec;\r
813 \r
814             groupBox_output.Text = preset;\r
815         }\r
816 \r
817         private void setMkv()\r
818         {\r
819             // Set file extension to MKV\r
820             string destination = text_destination.Text;\r
821             destination = destination.Replace(".mp4", ".mkv");\r
822             destination = destination.Replace(".avi", ".mkv");\r
823             destination = destination.Replace(".m4v", ".mkv");\r
824             destination = destination.Replace(".ogm", ".mkv");\r
825             text_destination.Text = destination;\r
826         }\r
827 \r
828         #endregion\r
829 \r
830         //---------------------------------------------------\r
831         // Encode / Cancel Buttons\r
832         // Encode Progress Text Handler\r
833         //---------------------------------------------------\r
834 \r
835         #region Encode/CLI\r
836 \r
837         Functions.CLI process = new Functions.CLI();\r
838 \r
839         private void btn_encode_Click(object sender, EventArgs e)\r
840         {\r
841             if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "")\r
842                 MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
843             else\r
844             {\r
845                 btn_eCancel.Enabled = true;\r
846                 String query = "";\r
847                 if (QueryEditorText.Text == "")\r
848                 {\r
849                     query = GenerateTheQuery();\r
850                 }\r
851                 else\r
852                 {\r
853                     query = QueryEditorText.Text;\r
854                 }\r
855 \r
856                 ThreadPool.QueueUserWorkItem(procMonitor, query);\r
857                 lbl_encode.Visible = true;\r
858                 lbl_encode.Text = "Encoding in Progress";\r
859             }\r
860         }\r
861 \r
862         private void btn_eCancel_Click(object sender, EventArgs e)\r
863         {\r
864             process.killCLI();\r
865             process.setNull();\r
866             lbl_encode.Text = "Encoding Canceled";\r
867         }\r
868 \r
869         [DllImport("user32.dll")]\r
870         public static extern void LockWorkStation();\r
871         [DllImport("user32.dll")]\r
872         public static extern int ExitWindowsEx(int uFlags, int dwReason); \r
873 \r
874         private void procMonitor(object state)\r
875         {\r
876             // Make sure we are not already encoding and if we are then display an error.\r
877             if (hbProc != null)\r
878             {\r
879                 MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
880             }\r
881             else\r
882             {\r
883                 hbProc = process.runCli(this, (string)state, false, false, false, false);\r
884                 hbProc.WaitForExit();\r
885 \r
886                 try\r
887                 {\r
888                     /*\r
889                     //*****************************************************************************************\r
890                     // BUG!\r
891                     // When the below code is used and standard error is set to true, hbcli is outputing a\r
892                     // video stream which has mild corruption issues every few seconds.\r
893                     // Maybe an issue with the Parser cauing the CLI to hickup/pause?\r
894                     //*****************************************************************************************\r
895 \r
896                     \r
897                     Parsing.Parser encode = new Parsing.Parser(hbProc.StandardOutput.BaseStream);\r
898                     encode.OnEncodeProgress += encode_OnEncodeProgress;\r
899                     while (!encode.EndOfStream)\r
900                     {\r
901                         encode.ReadLine();\r
902                     }\r
903 \r
904                     hbProc.WaitForExit();\r
905                     process.closeCLI();\r
906                      */\r
907                     \r
908                 }\r
909                 catch (Exception exc)\r
910                 {\r
911                     // Do nothing\r
912                     MessageBox.Show(exc.ToString());\r
913                 }\r
914 \r
915 \r
916                 setEncodeLabel();\r
917                 hbProc = null;\r
918 \r
919                 // Do something whent he encode ends.\r
920                 switch (Properties.Settings.Default.CompletionOption)\r
921                 {\r
922                     case "Shutdown":\r
923                         System.Diagnostics.Process.Start("Shutdown", "-s -t 60");\r
924                         break;\r
925                     case "Log Off":\r
926                         ExitWindowsEx(0, 0); \r
927                         break;\r
928                     case "Suspend":\r
929                         Application.SetSuspendState(PowerState.Suspend, true, true);\r
930                         break;\r
931                     case "Hibernate":\r
932                         Application.SetSuspendState(PowerState.Hibernate, true, true);\r
933                         break;\r
934                     case "Lock System":\r
935                         LockWorkStation();\r
936                         break;\r
937                     case "Quit HandBrake":\r
938                         Application.Exit();\r
939                         break;\r
940                     default:\r
941                         break;\r
942                 }\r
943             }\r
944         }\r
945 \r
946         private delegate void UpdateUIHandler();\r
947 \r
948         private void setEncodeLabel()\r
949         {\r
950             if (this.InvokeRequired)\r
951             {\r
952                 this.BeginInvoke(new UpdateUIHandler(setEncodeLabel));\r
953                 return;\r
954             }\r
955             lbl_encode.Text = "Encoding Finished";\r
956         }\r
957 \r
958         private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
959         {\r
960             \r
961             if (this.InvokeRequired)\r
962             {\r
963                 this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),\r
964                     new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
965                 return;\r
966             }\r
967             lbl_encode.Text = string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
968         }\r
969 \r
970         #endregion\r
971 \r
972         //---------------------------------------------------\r
973         //  Items that require actions on frmMain\r
974         //---------------------------------------------------\r
975 \r
976         #region frmMain Actions\r
977 \r
978         private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)\r
979         {\r
980             drop_chapterStart.BackColor = Color.White;\r
981             QueryEditorText.Text = "";\r
982             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
983             {\r
984                 try\r
985                 {\r
986                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
987                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
988 \r
989                     if (chapterFinish < chapterStart)\r
990                     {\r
991                         drop_chapterStart.BackColor = Color.LightCoral;\r
992                     }\r
993                 }\r
994                 catch (Exception)\r
995                 {\r
996                     drop_chapterStart.BackColor = Color.LightCoral;\r
997                 }\r
998             }\r
999 \r
1000             \r
1001         }\r
1002 \r
1003         private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)\r
1004         {\r
1005             drop_chapterFinish.BackColor = Color.White;\r
1006             QueryEditorText.Text = "";\r
1007             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
1008             {\r
1009                 try\r
1010                 {\r
1011                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
1012                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
1013 \r
1014                     if (chapterFinish < chapterStart)\r
1015                     {\r
1016                         drop_chapterFinish.BackColor = Color.LightCoral;\r
1017                     }\r
1018                 }\r
1019                 catch (Exception)\r
1020                 {\r
1021                     drop_chapterFinish.BackColor = Color.LightCoral;\r
1022                 }\r
1023             }\r
1024         }\r
1025 \r
1026         private void text_bitrate_TextChanged(object sender, EventArgs e)\r
1027         {\r
1028             text_filesize.Text = "";\r
1029             slider_videoQuality.Value = 0;\r
1030             SliderValue.Text = "0%";\r
1031             CheckCRF.CheckState = CheckState.Unchecked;\r
1032             CheckCRF.Enabled = false;\r
1033         }\r
1034 \r
1035         private void text_filesize_TextChanged(object sender, EventArgs e)\r
1036         {\r
1037             text_bitrate.Text = "";\r
1038             slider_videoQuality.Value = 0;\r
1039             SliderValue.Text = "0%";\r
1040             CheckCRF.CheckState = CheckState.Unchecked;\r
1041             CheckCRF.Enabled = false;\r
1042         }\r
1043 \r
1044         private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
1045         {\r
1046             SliderValue.Text = slider_videoQuality.Value.ToString() + "%";\r
1047             text_bitrate.Text = "";\r
1048             text_filesize.Text = "";\r
1049             CheckCRF.Enabled = true;\r
1050         }\r
1051 \r
1052         private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
1053         {\r
1054             Process.Start("http://handbrake.m0k.org/trac/wiki/x264Options");\r
1055         }\r
1056 \r
1057         private void text_width_TextChanged(object sender, EventArgs e)\r
1058         {\r
1059 \r
1060             try\r
1061             {\r
1062                 if (CheckPixelRatio.Checked)\r
1063                 {\r
1064                     text_width.Text = "";\r
1065                     text_width.BackColor = Color.White;\r
1066                 }\r
1067                 else\r
1068                 {\r
1069                     if ((int.Parse(text_width.Text) % 16) != 0)\r
1070                     {\r
1071                         text_width.BackColor = Color.LightCoral;\r
1072                     }\r
1073                     else\r
1074                     {\r
1075                         text_width.BackColor = Color.LightGreen;\r
1076                     }\r
1077                 }\r
1078 \r
1079                 if (lbl_Aspect.Text != "Select a Title")\r
1080                 {\r
1081                     double height = int.Parse(text_width.Text) / double.Parse(lbl_Aspect.Text);\r
1082                     double mod16 = height % 16;\r
1083                     height = height - mod16;\r
1084 \r
1085                     if (text_width.Text == "")\r
1086                     {\r
1087                         text_height.Text = "";\r
1088                         text_width.BackColor = Color.White;\r
1089                     }\r
1090                     else\r
1091                     {\r
1092                         text_height.Text = height.ToString();\r
1093                     }\r
1094                 }\r
1095             }\r
1096             catch (Exception)\r
1097             {\r
1098                 // No need to throw an error here.\r
1099                 // Note on non english systems, this will throw an error because of double.Parse(lbl_Aspect.Text); not working.\r
1100             }\r
1101                \r
1102           \r
1103         }\r
1104 \r
1105         private void text_height_TextChanged(object sender, EventArgs e)\r
1106         {\r
1107             try\r
1108             {\r
1109                 if (text_height.Text != "Auto")\r
1110                 {\r
1111                     if (CheckPixelRatio.Checked)\r
1112                     {\r
1113                         text_height.Text = "";\r
1114                         text_width.BackColor = Color.White;\r
1115                     }\r
1116                     else\r
1117                     {\r
1118                         if ((int.Parse(text_height.Text) % 16) != 0)\r
1119                         {\r
1120                             text_height.BackColor = Color.LightCoral;\r
1121                         }\r
1122                         else\r
1123                         {\r
1124                             text_height.BackColor = Color.LightGreen;\r
1125                         }\r
1126                     }\r
1127                 }\r
1128             } catch(Exception){\r
1129                 // No need to alert the user.\r
1130             }\r
1131         }\r
1132 \r
1133         private void drp_crop_SelectedIndexChanged(object sender, EventArgs e)\r
1134         {\r
1135             if ((string)drp_crop.SelectedItem == "Manual")\r
1136             {\r
1137             text_left.Enabled = true;\r
1138             text_right.Enabled = true;\r
1139             text_top.Enabled = true;\r
1140             text_bottom.Enabled = true;\r
1141             }\r
1142 \r
1143             if ((string)drp_crop.SelectedItem == "Auto Crop")\r
1144             {\r
1145                 text_left.Enabled = false;\r
1146                 text_right.Enabled = false;\r
1147                 text_top.Enabled = false;\r
1148                 text_bottom.Enabled = false;\r
1149                 text_left.Text = "";\r
1150                 text_right.Text = "";\r
1151                 text_top.Text = "";\r
1152                 text_bottom.Text = "";\r
1153 \r
1154                 if (lbl_RecomendedCrop.Text != "Select a Title")\r
1155                 {\r
1156                     string[] temp = new string[4];\r
1157                     temp = lbl_RecomendedCrop.Text.Split('/');\r
1158                     text_left.Text = temp[2];\r
1159                     text_right.Text = temp[3];\r
1160                     text_top.Text = temp[0];\r
1161                     text_bottom.Text = temp[1];\r
1162                 }\r
1163             }\r
1164 \r
1165             if ((string)drp_crop.SelectedItem == "No Crop")\r
1166             {\r
1167                 text_left.Enabled = false;\r
1168                 text_right.Enabled = false;\r
1169                 text_top.Enabled = false;\r
1170                 text_bottom.Enabled = false;\r
1171                 text_left.Text = "0";\r
1172                 text_right.Text = "0";\r
1173                 text_top.Text = "0";\r
1174                 text_bottom.Text = "0";\r
1175 \r
1176             }\r
1177         }\r
1178         \r
1179         private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)\r
1180         {\r
1181             text_width.Text = "";\r
1182             text_height.Text = "";\r
1183             text_width.BackColor = Color.White;\r
1184             text_height.BackColor = Color.White;\r
1185         }\r
1186 \r
1187         private void drp_dvdtitle_Click(object sender, EventArgs e)\r
1188         {\r
1189             if (drp_dvdtitle.Items.Count == 0)\r
1190             {\r
1191                 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
1192             }\r
1193         }\r
1194 \r
1195         private void drp_audioCodec_SelectedIndexChanged(object sender, EventArgs e)\r
1196         {\r
1197 \r
1198             //CLI Audio mixdown Names: mono stereo dpl1 dpl2 6ch\r
1199 \r
1200             drp_audioMixDown.Items.Clear();\r
1201 \r
1202             if (drp_audioCodec.Text == "AAC")\r
1203             {\r
1204                 drp_audioMixDown.Items.Clear();\r
1205                 drp_audioMixDown.Items.Add("Mono");\r
1206                 drp_audioMixDown.Items.Add("Stereo");\r
1207                 drp_audioMixDown.Items.Add("Dolby Surround");\r
1208                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
1209                 drp_audioMixDown.Items.Add("6 Channel Discrete");\r
1210                 \r
1211                 drp_audioBitrate.Items.Clear();\r
1212                 drp_audioBitrate.Items.Add("32");\r
1213                 drp_audioBitrate.Items.Add("40");\r
1214                 drp_audioBitrate.Items.Add("48");\r
1215                 drp_audioBitrate.Items.Add("56");\r
1216                 drp_audioBitrate.Items.Add("64");\r
1217                 drp_audioBitrate.Items.Add("80");\r
1218                 drp_audioBitrate.Items.Add("86");\r
1219                 drp_audioBitrate.Items.Add("112");\r
1220                 drp_audioBitrate.Items.Add("128");\r
1221                 drp_audioBitrate.Items.Add("160");\r
1222 \r
1223             }\r
1224             else\r
1225             {\r
1226                 drp_audioMixDown.Items.Clear();\r
1227                 drp_audioMixDown.Items.Add("Stereo");\r
1228                 drp_audioMixDown.Items.Add("Dolby Surround");\r
1229                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
1230 \r
1231                 drp_audioBitrate.Items.Clear();\r
1232                 drp_audioBitrate.Items.Add("32");\r
1233                 drp_audioBitrate.Items.Add("40");\r
1234                 drp_audioBitrate.Items.Add("48");\r
1235                 drp_audioBitrate.Items.Add("56");\r
1236                 drp_audioBitrate.Items.Add("64");\r
1237                 drp_audioBitrate.Items.Add("80");\r
1238                 drp_audioBitrate.Items.Add("86");\r
1239                 drp_audioBitrate.Items.Add("112");\r
1240                 drp_audioBitrate.Items.Add("128");\r
1241                 drp_audioBitrate.Items.Add("160");\r
1242                 drp_audioBitrate.Items.Add("192");\r
1243                 drp_audioBitrate.Items.Add("224");\r
1244                 drp_audioBitrate.Items.Add("256");\r
1245                 drp_audioBitrate.Items.Add("320");\r
1246             }\r
1247         }\r
1248 \r
1249         private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e)\r
1250         {\r
1251             if (drp_audioCodec.Text == "AAC")\r
1252             {\r
1253                 if (drp_audioMixDown.Text == "6 Channel Discrete")\r
1254                 {\r
1255 \r
1256                     drp_audioBitrate.Items.Clear();\r
1257                     drp_audioBitrate.Items.Add("32");\r
1258                     drp_audioBitrate.Items.Add("40");\r
1259                     drp_audioBitrate.Items.Add("48");\r
1260                     drp_audioBitrate.Items.Add("56");\r
1261                     drp_audioBitrate.Items.Add("64");\r
1262                     drp_audioBitrate.Items.Add("80");\r
1263                     drp_audioBitrate.Items.Add("86");\r
1264                     drp_audioBitrate.Items.Add("112");\r
1265                     drp_audioBitrate.Items.Add("128");\r
1266                     drp_audioBitrate.Items.Add("160");\r
1267                     drp_audioBitrate.Items.Add("192");\r
1268                     drp_audioBitrate.Items.Add("224");\r
1269                     drp_audioBitrate.Items.Add("256");\r
1270                     drp_audioBitrate.Items.Add("320");\r
1271                     drp_audioBitrate.Items.Add("384");\r
1272                 }\r
1273             }\r
1274         }\r
1275 \r
1276         private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)\r
1277         {\r
1278             if (Check_ChapterMarkers.Checked)\r
1279             {\r
1280                 string destination = text_destination.Text;\r
1281                 destination = destination.Replace(".mp4", ".m4v");\r
1282                 text_destination.Text = destination;\r
1283             }\r
1284             else\r
1285             {\r
1286                 string destination = text_destination.Text;\r
1287                 destination = destination.Replace(".m4v", ".mp4");\r
1288                 text_destination.Text = destination;\r
1289             }\r
1290         }\r
1291 \r
1292         private void check_largeFile_CheckedChanged(object sender, EventArgs e)\r
1293         {\r
1294             if (!text_destination.Text.Contains(".mp4"))\r
1295             {\r
1296                 MessageBox.Show("This option is only compatible with the mp4 file container.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1297                 check_largeFile.CheckState = CheckState.Unchecked;\r
1298             }\r
1299         }\r
1300 \r
1301         private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)\r
1302         {\r
1303             //Turn off some options which are H.264 only when the user selects a non h.264 encoder\r
1304             if (!drp_videoEncoder.Text.Contains("H.264"))\r
1305             {\r
1306                 check_turbo.CheckState = CheckState.Unchecked;\r
1307                 CheckCRF.CheckState = CheckState.Unchecked;\r
1308                 CheckCRF.Enabled = false;\r
1309                 check_turbo.Enabled = false;\r
1310                 h264Tab.Enabled = false;\r
1311                 rtf_h264advanced.Text = "";\r
1312             }\r
1313             else\r
1314             {\r
1315                 CheckCRF.Enabled = true;\r
1316                 check_turbo.Enabled = true;\r
1317                 h264Tab.Enabled = true;\r
1318             }\r
1319 \r
1320         }\r
1321 \r
1322         public void setStreamReader(Parsing.DVD dvd)\r
1323         {\r
1324             this.thisDVD = dvd;\r
1325         }\r
1326 \r
1327         private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)\r
1328         {\r
1329             // Reset some values on the form\r
1330             lbl_Aspect.Text = "Select a Title";\r
1331             lbl_RecomendedCrop.Text = "Select a Title";\r
1332             drop_chapterStart.Items.Clear();\r
1333             drop_chapterFinish.Items.Clear();\r
1334             QueryEditorText.Text = "";\r
1335 \r
1336             // If the dropdown is set to automatic nothing else needs to be done.\r
1337             // Otheriwse if its not, title data has to be loased from parsing.\r
1338             if (drp_dvdtitle.Text != "Automatic")\r
1339             {\r
1340                 Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;\r
1341 \r
1342                 // Set the Aspect Ratio\r
1343                 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();\r
1344 \r
1345                 // Set the Recommended Cropping values\r
1346                 lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);\r
1347                 \r
1348                 // Populate the Start chapter Dropdown\r
1349                 drop_chapterStart.Items.Clear();\r
1350                 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());\r
1351                 if (drop_chapterStart.Items.Count > 0)\r
1352                 {\r
1353                     drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();\r
1354                 }\r
1355 \r
1356                 // Populate the Final Chapter Dropdown\r
1357                 drop_chapterFinish.Items.Clear();\r
1358                 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());\r
1359                 if (drop_chapterFinish.Items.Count > 0)\r
1360                 {\r
1361                     drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
1362                 }\r
1363 \r
1364                 // Populate the Audio Channels Dropdown\r
1365                 drp_audioChannels.Items.Clear();\r
1366                 drp_audioChannels.Items.Add("Automatic");\r
1367                 drp_audioChannels.Items.AddRange(selectedTitle.AudioTracks.ToArray());\r
1368                 if (drp_audioChannels.Items.Count > 0)\r
1369                 {\r
1370                     drp_audioChannels.Text = drp_audioChannels.Items[0].ToString();\r
1371                 }\r
1372 \r
1373                 // Populate the Subtitles dropdown\r
1374                 drp_subtitle.Items.Clear();\r
1375                 drp_subtitle.Items.Add("None");\r
1376                 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());\r
1377                 if (drp_subtitle.Items.Count > 0)\r
1378                 {\r
1379                     drp_subtitle.Text = drp_subtitle.Items[0].ToString();\r
1380                 }\r
1381             }\r
1382         }\r
1383 \r
1384         #endregion\r
1385 \r
1386         //---------------------------------------------------\r
1387         //  Some Functions\r
1388         //  - Query Generation\r
1389         //---------------------------------------------------\r
1390 \r
1391         #region Program Functions\r
1392 \r
1393         public string GenerateTheQuery()\r
1394         {\r
1395             string source = text_source.Text;\r
1396             string dvdTitle = drp_dvdtitle.Text;\r
1397             string chapterStart = drop_chapterStart.Text;\r
1398             string chapterFinish = drop_chapterFinish.Text;\r
1399             int totalChapters = drop_chapterFinish.Items.Count - 1;\r
1400             string dvdChapter = "";\r
1401 \r
1402             source = " -i " + '"' + source+ '"';\r
1403 \r
1404             if (dvdTitle ==  "Automatic")\r
1405                 dvdTitle = "";\r
1406             else\r
1407             {\r
1408                 string[] titleInfo = dvdTitle.Split(' ');\r
1409                 dvdTitle = " -t "+ titleInfo[0];\r
1410             }\r
1411 \r
1412             if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))\r
1413                 dvdChapter = "";\r
1414             else if (chapterFinish == chapterStart)\r
1415                 dvdChapter = " -c " + chapterStart;\r
1416             else\r
1417                 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;\r
1418 \r
1419             string querySource = source+ dvdTitle+ dvdChapter;\r
1420             // ----------------------------------------------------------------------\r
1421 \r
1422             // Destination\r
1423 \r
1424             string destination = text_destination.Text;\r
1425             string videoEncoder = drp_videoEncoder.Text;\r
1426             string audioEncoder = drp_audioCodec.Text;\r
1427             string width = text_width.Text;\r
1428             string height = text_height.Text;\r
1429 \r
1430             if (destination ==  "")\r
1431                 MessageBox.Show("No destination has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1432             else\r
1433                 destination = " -o " + '"' + destination + '"'; //'"'+ \r
1434 \r
1435 \r
1436             switch (videoEncoder)\r
1437             {\r
1438                 case "Mpeg 4":\r
1439                     videoEncoder = " -e ffmpeg";\r
1440                     break;\r
1441                 case "Xvid":\r
1442                     videoEncoder = " -e xvid";\r
1443                     break;\r
1444                 case "H.264":\r
1445                     videoEncoder = " -e x264";\r
1446                     break;\r
1447                 case "H.264 Baseline 1.3":\r
1448                     videoEncoder = " -e x264b13";\r
1449                     break;\r
1450                 case "H.264 (iPod)":\r
1451                     videoEncoder = " -e x264b30";\r
1452                     break;\r
1453                 default:\r
1454                     videoEncoder = " -e x264";\r
1455                     break;\r
1456             }\r
1457            \r
1458             switch (audioEncoder)\r
1459             {\r
1460                 case "AAC":\r
1461                     audioEncoder = " -E faac";\r
1462                     break;\r
1463                 case "MP3":\r
1464                     audioEncoder = " -E lame";\r
1465                     break;\r
1466                 case "Vorbis":\r
1467                     audioEncoder = " -E vorbis";\r
1468                     break;\r
1469                 case "AC3":\r
1470                     audioEncoder = " -E ac3";\r
1471                     break;\r
1472                 default:\r
1473                     audioEncoder = " -E faac";\r
1474                     break;\r
1475             }\r
1476 \r
1477             if (width !=  "")\r
1478                 width = " -w "+ width;\r
1479 \r
1480 \r
1481             if (height == "Auto")\r
1482             {\r
1483                 height = "";\r
1484             }\r
1485             else if (height != "")\r
1486             {\r
1487                 height = " -l " + height;\r
1488             }\r
1489             \r
1490 \r
1491             string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height;\r
1492             // ----------------------------------------------------------------------\r
1493 \r
1494             // Picture Settings Tab\r
1495 \r
1496             string cropSetting = drp_crop.Text;\r
1497             string cropTop = text_top.Text;\r
1498             string cropBottom = text_bottom.Text;\r
1499             string cropLeft = text_left.Text;\r
1500             string cropRight = text_right.Text;\r
1501             string subtitles = drp_subtitle.Text;\r
1502             string cropOut = "";\r
1503             string deInterlace_Option = drp_deInterlace_option.Text;\r
1504             string deinterlace = "";\r
1505             string grayscale = "";\r
1506             string pixelRatio = "";\r
1507             string ChapterMarkers = "";\r
1508             // Returns Crop Query\r
1509 \r
1510             if (cropSetting == "Auto Crop")\r
1511                 cropOut = "";\r
1512             else if (cropSetting == "No Crop")\r
1513                 cropOut = " --crop 0:0:0:0 ";\r
1514             else\r
1515             {\r
1516                 if (text_top.Text == "")\r
1517                     cropTop = "0";\r
1518                 if (text_bottom.Text == "")\r
1519                     cropBottom = "0";\r
1520                 if (text_left.Text == "")\r
1521                     cropLeft = "0";\r
1522                 if (text_right.Text == "")\r
1523                     cropRight = "0";\r
1524 \r
1525                 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;\r
1526             }\r
1527 \r
1528             if (subtitles ==  "None")\r
1529                 subtitles = "";\r
1530             else if (subtitles ==  "")\r
1531                 subtitles = "";\r
1532             else\r
1533             {\r
1534                 string[] tempSub;\r
1535                 tempSub = subtitles.Split(' ');\r
1536                 subtitles = " -s "+ tempSub[0];\r
1537             }\r
1538 \r
1539             switch (deInterlace_Option)\r
1540             {\r
1541                 case "None":\r
1542                     deinterlace = "";\r
1543                     break;\r
1544                 case "Origional (Fast)":\r
1545                     deinterlace = " --deinterlace=1";\r
1546                     break;\r
1547                 case "yadif (Slow)":\r
1548                     deinterlace = " --deinterlace=" + '"' + "0" + '"';\r
1549                     break;\r
1550                 case "yadif + mcdeint (Slower)":\r
1551                     deinterlace = " --deinterlace=" + '"' + "2:-1:1" + '"';\r
1552                     break;\r
1553                 case "yadif + mcdeint (Slowest)":\r
1554                     deinterlace = " --deinterlace=" + '"' + "1:-1:1" + '"';\r
1555                     break;\r
1556                 default:\r
1557                     deinterlace = "";\r
1558                     break;\r
1559             }\r
1560 \r
1561             if (check_grayscale.Checked)\r
1562                 grayscale = " -g ";\r
1563 \r
1564             if (CheckPixelRatio.Checked)\r
1565                 pixelRatio = " -p ";\r
1566 \r
1567             if (Check_ChapterMarkers.Checked)\r
1568                 ChapterMarkers = " -m ";\r
1569 \r
1570             string queryPictureSettings = cropOut + subtitles + deinterlace + grayscale + pixelRatio + ChapterMarkers;\r
1571             // ----------------------------------------------------------------------\r
1572 \r
1573             // Video Settings Tab\r
1574 \r
1575             string videoBitrate = text_bitrate.Text;\r
1576             string videoFilesize = text_filesize.Text;\r
1577             double videoQuality = slider_videoQuality.Value;\r
1578             string vidQSetting = "";\r
1579             string twoPassEncoding = "";\r
1580             string videoFramerate = drp_videoFramerate.Text;\r
1581             string turboH264 = "";\r
1582             string largeFile = "";\r
1583             string deblock = "";\r
1584             string detelecine = "";\r
1585             string denoise = "";\r
1586             string CRF = CheckCRF.CheckState.ToString();\r
1587 \r
1588 \r
1589             if ((CRF == "Checked"))\r
1590                 CRF = " -Q ";\r
1591             else\r
1592                 CRF = "";\r
1593 \r
1594             if (videoBitrate !=  "")\r
1595                 videoBitrate = " -b "+ videoBitrate;\r
1596 \r
1597             if (videoFilesize !=  "")\r
1598                 videoFilesize = " -S "+ videoFilesize;\r
1599 \r
1600             // Video Quality Setting\r
1601 \r
1602             if ((videoQuality ==  0))\r
1603                 vidQSetting = "";\r
1604             else\r
1605             {\r
1606                 videoQuality = videoQuality / 100;\r
1607                 if (videoQuality ==  1)\r
1608                 {\r
1609                     vidQSetting = "1.0";\r
1610                 }\r
1611 \r
1612                 vidQSetting = " -q " + videoQuality.ToString();\r
1613             }\r
1614 \r
1615             if (check_2PassEncode.Checked)\r
1616                 twoPassEncoding = " -2 ";\r
1617 \r
1618             if (videoFramerate ==  "Automatic")\r
1619                 videoFramerate = "";\r
1620             else\r
1621                 videoFramerate = " -r "+ videoFramerate;\r
1622 \r
1623             if (check_turbo.Checked)\r
1624                 turboH264 = " -T ";\r
1625 \r
1626             if (check_largeFile.Checked)\r
1627                 largeFile = " -4 ";\r
1628 \r
1629             if (check_deblock.Checked)\r
1630                 deblock = " --deblock";\r
1631 \r
1632             if (check_detelecine.Checked)\r
1633                 detelecine = " --detelecine";\r
1634 \r
1635             switch (drp_deNoise.Text)\r
1636             {\r
1637                 case "None":\r
1638                     denoise = "";\r
1639                     break;\r
1640                 case "Weak":\r
1641                     denoise = " --denoise=2:1:2:3";\r
1642                     break;\r
1643                 case "Medium":\r
1644                     denoise = " --denoise=3:2:2:3";\r
1645                     break;\r
1646                 case "Strong":\r
1647                     denoise = " --denoise=7:7:5:5";\r
1648                     break;\r
1649                 default:\r
1650                     denoise = "";\r
1651                     break;\r
1652             }\r
1653 \r
1654             string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + videoFramerate + turboH264 + largeFile + deblock + detelecine + denoise;\r
1655             // ----------------------------------------------------------------------\r
1656 \r
1657             // Audio Settings Tab\r
1658 \r
1659             string audioBitrate = drp_audioBitrate.Text;\r
1660             string audioSampleRate = drp_audioSampleRate.Text;\r
1661             string audioChannels = drp_audioChannels.Text;\r
1662             string Mixdown = drp_audioMixDown.Text;\r
1663             string SixChannelAudio = "";\r
1664 \r
1665             if (audioBitrate !=  "")\r
1666                 audioBitrate = " -B "+ audioBitrate;\r
1667 \r
1668             if (audioSampleRate !=  "")\r
1669                 audioSampleRate = " -R "+ audioSampleRate;\r
1670 \r
1671             if (audioChannels ==  "Automatic")\r
1672                 audioChannels = "";\r
1673             else if (audioChannels ==  "")\r
1674                 audioChannels = "";\r
1675             else\r
1676             {\r
1677                 string[] tempSub;\r
1678                 tempSub = audioChannels.Split(' ');\r
1679                 audioChannels = " -a "+ tempSub[0];\r
1680             }\r
1681 \r
1682             switch (Mixdown)\r
1683             {\r
1684                 case "Automatic":\r
1685                     Mixdown = "";\r
1686                     break;\r
1687                 case "Mono":\r
1688                     Mixdown = "mono";\r
1689                     break;\r
1690                 case "Stereo":\r
1691                     Mixdown = "stereo";\r
1692                     break;\r
1693                 case "Dolby Surround":\r
1694                     Mixdown = "dpl1";\r
1695                     break;\r
1696                 case "Dolby Pro Logic II":\r
1697                     Mixdown = "dpl2";\r
1698                     break;\r
1699                 case "6 Channel Discrete":\r
1700                     Mixdown = "6ch";\r
1701                     break;\r
1702                 default:\r
1703                     Mixdown = "stero";\r
1704                     break;\r
1705             }\r
1706 \r
1707             if (Mixdown !=  "")\r
1708                 SixChannelAudio = " -6 "+ Mixdown;\r
1709             else\r
1710                 SixChannelAudio = "";\r
1711 \r
1712             string queryAudioSettings = audioBitrate+ audioSampleRate+ audioChannels+ SixChannelAudio;\r
1713             // ----------------------------------------------------------------------\r
1714 \r
1715             //  H.264 Tab\r
1716 \r
1717             \r
1718             string h264Advanced = rtf_h264advanced.Text;\r
1719             \r
1720             if ((h264Advanced ==  ""))\r
1721                 h264Advanced = "";\r
1722             else\r
1723                 h264Advanced = " -x "+ h264Advanced;\r
1724     \r
1725 \r
1726             string h264Settings = h264Advanced;\r
1727             // ----------------------------------------------------------------------\r
1728 \r
1729             // Processors (Program Settings)\r
1730 \r
1731             string processors = Properties.Settings.Default.Processors;\r
1732             //  Number of Processors Handler\r
1733 \r
1734             if (processors ==  "Automatic")\r
1735                 processors = "";\r
1736             else\r
1737                 processors = " -C "+ processors+ " ";\r
1738 \r
1739 \r
1740             string queryAdvancedSettings = processors;\r
1741             // ----------------------------------------------------------------------\r
1742 \r
1743             //  Verbose option (Program Settings)\r
1744 \r
1745             string verbose = "";\r
1746             if (Properties.Settings.Default.verbose ==  "Checked")\r
1747                 verbose = " -v ";\r
1748 \r
1749             // ----------------------------------------------------------------------\r
1750 \r
1751             return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;\r
1752         }\r
1753 \r
1754         #endregion\r
1755 \r
1756         // This is the END of the road ------------------------------------------------------------------------------\r
1757     }\r
1758 }\r