OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.ComponentModel;\r
4 using System.Data;\r
5 using System.Drawing;\r
6 using System.Text;\r
7 using System.Windows.Forms;\r
8 using System.Net;\r
9 using System.IO;\r
10 using System.Diagnostics;\r
11 using System.Threading;\r
12 \r
13 namespace Handbrake\r
14 {\r
15     public partial class frmMain : Form\r
16     {\r
17         private Process hbProc;\r
18         private Parsing.DVD thisDVD;\r
19 \r
20         // --------------------------------------------------------------\r
21         // Some windows that require only 1 instance.\r
22         // --------------------------------------------------------------\r
23         private frmQueue queueWindow = new frmQueue();  \r
24         \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         public frmMain()\r
31         {\r
32             \r
33             InitializeComponent();\r
34 \r
35             // Set the Version number lable to the corect version.\r
36             Version.Text = "Version " + Properties.Settings.Default.GuiVersion;\r
37 \r
38             // Run the update checker.\r
39             updateCheck();\r
40 \r
41             // Now load the users default if required.\r
42             loadUserDefaults();\r
43         }\r
44 \r
45         public void loadUserDefaults()\r
46         { \r
47             try\r
48             {\r
49                 if (Properties.Settings.Default.defaultSettings == "Checked")\r
50                 {\r
51                     // Source\r
52                     text_source.Text = Properties.Settings.Default.DVDSource;\r
53                     drp_dvdtitle.Text = Properties.Settings.Default.DVDTitle;\r
54                     drop_chapterStart.Text = Properties.Settings.Default.ChapterStart;\r
55                     drop_chapterFinish.Text = Properties.Settings.Default.ChapterFinish;\r
56 \r
57                     // Destination\r
58                     text_destination.Text = Properties.Settings.Default.VideoDest;\r
59                     drp_videoEncoder.Text = Properties.Settings.Default.VideoEncoder;\r
60                     drp_audioCodec.Text = Properties.Settings.Default.AudioEncoder;\r
61                     text_width.Text = Properties.Settings.Default.Width;\r
62                     text_height.Text = Properties.Settings.Default.Height;\r
63 \r
64                     // Picture Settings Tab\r
65                     drp_crop.Text = Properties.Settings.Default.CroppingOption;\r
66                     text_top.Text = Properties.Settings.Default.CropTop;\r
67                     text_bottom.Text = Properties.Settings.Default.CropBottom;\r
68                     text_left.Text = Properties.Settings.Default.CropLeft;\r
69                     text_right.Text = Properties.Settings.Default.CropRight;\r
70                     drp_subtitle.Text = Properties.Settings.Default.Subtitles;\r
71 \r
72                     // Video Settings Tab\r
73                     text_bitrate.Text = Properties.Settings.Default.VideoBitrate;\r
74                     text_filesize.Text = Properties.Settings.Default.VideoFilesize;\r
75                     slider_videoQuality.Value = Properties.Settings.Default.VideoQuality;\r
76 \r
77                     if (Properties.Settings.Default.TwoPass == "Checked")\r
78                     {\r
79                         check_2PassEncode.CheckState = CheckState.Checked;\r
80                     }\r
81                     if (Properties.Settings.Default.DeInterlace == "Checked")\r
82                     {\r
83                         check_DeInterlace.CheckState = CheckState.Checked;\r
84                     }\r
85                     if (Properties.Settings.Default.Grayscale == "Checked")\r
86                     {\r
87                         check_grayscale.CheckState = CheckState.Checked;\r
88                     }\r
89 \r
90                     drp_videoFramerate.Text = Properties.Settings.Default.Framerate;\r
91 \r
92                     if (Properties.Settings.Default.PixelRatio == "Checked")\r
93                     {\r
94                         CheckPixelRatio.CheckState = CheckState.Checked;\r
95                     }\r
96                     if (Properties.Settings.Default.turboFirstPass == "Checked")\r
97                     {\r
98                         check_turbo.CheckState = CheckState.Checked;\r
99                     }\r
100                     if (Properties.Settings.Default.largeFile == "Checked")\r
101                     {\r
102                         check_largeFile.CheckState = CheckState.Checked;\r
103                     }\r
104                     // Audio Settings Tab\r
105                     drp_audioBitrate.Text = Properties.Settings.Default.AudioBitrate;\r
106                     drp_audioSampleRate.Text = Properties.Settings.Default.AudioSampleRate;\r
107                     drp_audioChannels.Text = Properties.Settings.Default.AudioChannels;\r
108 \r
109                     // H264 Tab\r
110                     if (Properties.Settings.Default.CRF == "Checked")\r
111                     {\r
112                         CheckCRF.CheckState = CheckState.Checked;\r
113                     }\r
114                     rtf_h264advanced.Text = Properties.Settings.Default.H264;\r
115                 }\r
116             }\r
117             catch (Exception)\r
118             {\r
119                 // No real need to alert the user. Try/Catch only in just incase there is a problem reading the settings xml file.\r
120             }\r
121         }\r
122 \r
123         public void updateCheck()\r
124         {\r
125             if (Properties.Settings.Default.updateStatus == "Checked")\r
126             {\r
127                 try\r
128                 {\r
129                     String updateFile = Properties.Settings.Default.updateFile;\r
130                     WebClient client = new WebClient();\r
131                     String data = client.DownloadString(updateFile);\r
132                     String[] versionData = data.Split('\n');\r
133 \r
134                     if ((versionData[0] != Properties.Settings.Default.GuiVersion) || (versionData[1] != Properties.Settings.Default.CliVersion))\r
135                     {\r
136                         lbl_update.Visible = true;\r
137                     }\r
138                 }\r
139                 catch (Exception)\r
140                 {\r
141                     // Silently ignore the error\r
142                 }\r
143             }\r
144         }\r
145 \r
146         // -------------------------------------------------------------- \r
147         // The main Menu bar.\r
148         // -------------------------------------------------------------- \r
149 \r
150         #region File Menu\r
151 \r
152         private void mnu_open_Click(object sender, EventArgs e)\r
153         {\r
154             string filename;\r
155             File_Open.ShowDialog();\r
156             filename = File_Open.FileName;\r
157             if (filename != "")\r
158             {\r
159                 try\r
160                 {\r
161                     // Create StreamReader & open file\r
162                     StreamReader line = new StreamReader(filename);\r
163                     string temporyLine; // Used for reading the line into a varible before processing on the checkState items below.\r
164                     \r
165                     // Read in the data and set the correct GUI component with the setting.\r
166                     text_source.Text = line.ReadLine();\r
167                     drp_dvdtitle.Text = line.ReadLine();\r
168                     drop_chapterStart.Text = line.ReadLine();\r
169                     drop_chapterFinish.Text = line.ReadLine();\r
170                     text_destination.Text = line.ReadLine();\r
171                     drp_videoEncoder.Text = line.ReadLine();\r
172                     drp_audioCodec.Text = line.ReadLine();\r
173                     text_width.Text = line.ReadLine();\r
174                     text_height.Text = line.ReadLine();\r
175                     text_top.Text = line.ReadLine();\r
176                     text_bottom.Text = line.ReadLine();\r
177                     text_left.Text = line.ReadLine();\r
178                     text_right.Text = line.ReadLine();\r
179                     drp_subtitle.Text = line.ReadLine();\r
180                     text_bitrate.Text = line.ReadLine();\r
181                     text_filesize.Text = line.ReadLine();\r
182                     slider_videoQuality.Value = int.Parse(line.ReadLine());\r
183 \r
184                     temporyLine = line.ReadLine();\r
185                     if (temporyLine == "Checked")\r
186                     {\r
187                         check_2PassEncode.CheckState = CheckState.Checked;\r
188                     }\r
189 \r
190                     temporyLine = line.ReadLine();\r
191                     if (temporyLine == "Checked")\r
192                     {\r
193                         check_DeInterlace.CheckState = CheckState.Checked;\r
194                     }\r
195 \r
196                     temporyLine = line.ReadLine();\r
197                     if (temporyLine == "Checked")\r
198                     {\r
199                         check_grayscale.CheckState = CheckState.Checked;\r
200                     }\r
201 \r
202                     drp_videoFramerate.Text = line.ReadLine();\r
203 \r
204                     temporyLine = line.ReadLine();\r
205                     if (temporyLine == "Checked")\r
206                     {\r
207                         Check_ChapterMarkers.CheckState = CheckState.Checked;\r
208                     }\r
209 \r
210                     temporyLine = line.ReadLine();\r
211                     if (temporyLine == "Checked")\r
212                     {\r
213                         CheckPixelRatio.CheckState = CheckState.Checked;\r
214                     }\r
215 \r
216                     temporyLine = line.ReadLine();\r
217                     if (temporyLine == "Checked")\r
218                     {\r
219                         check_turbo.CheckState = CheckState.Checked;\r
220                     }\r
221 \r
222                     temporyLine = line.ReadLine();\r
223                     if (temporyLine == "Checked")\r
224                     {\r
225                         check_largeFile.CheckState = CheckState.Checked;\r
226                     }\r
227    \r
228                     drp_audioBitrate.Text = line.ReadLine();\r
229                     drp_audioSampleRate.Text = line.ReadLine();\r
230                     drp_audioChannels.Text = line.ReadLine();\r
231                     drp_audioMixDown.Text = line.ReadLine();\r
232                     \r
233                     // Advanced H264 Options\r
234                     temporyLine = line.ReadLine();\r
235                     if (temporyLine == "Checked")\r
236                     {\r
237                         CheckCRF.CheckState = CheckState.Checked;\r
238                     }\r
239                     rtf_h264advanced.Text = line.ReadLine();\r
240 \r
241                     // Close the stream\r
242                     line.Close();\r
243 \r
244 \r
245                     // Fix for SliderValue not appearing when Opening saved file\r
246                     SliderValue.Text = slider_videoQuality.Value + "%";\r
247 \r
248                 } catch (Exception){\r
249                     MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
250                 }\r
251             }\r
252         }\r
253 \r
254         private void mnu_save_Click(object sender, EventArgs e)\r
255         {\r
256 \r
257             string filename;\r
258             File_Save.ShowDialog();\r
259             filename = File_Save.FileName;\r
260             if (filename != "")\r
261             {\r
262                 try\r
263                 {\r
264                     // Create a StreamWriter and open the file\r
265                     StreamWriter line = new StreamWriter(filename);\r
266 \r
267                     //Source\r
268                     line.WriteLine(text_source.Text);\r
269                     line.WriteLine(drp_dvdtitle.Text);\r
270                     line.WriteLine(drop_chapterStart.Text);\r
271                     line.WriteLine(drop_chapterFinish.Text);\r
272                     //Destination\r
273                     line.WriteLine(text_destination.Text);\r
274                     line.WriteLine(drp_videoEncoder.Text);\r
275                     line.WriteLine(drp_audioCodec.Text);\r
276                     line.WriteLine(text_width.Text);\r
277                     line.WriteLine(text_height.Text);\r
278                     //Picture Settings Tab\r
279                     line.WriteLine(text_top.Text);\r
280                     line.WriteLine(text_bottom.Text);\r
281                     line.WriteLine(text_left.Text);\r
282                     line.WriteLine(text_right.Text);\r
283                     line.WriteLine(drp_subtitle.Text);\r
284                     //Video Settings Tab\r
285                     line.WriteLine(text_bitrate.Text);\r
286                     line.WriteLine(text_filesize.Text);\r
287                     line.WriteLine(slider_videoQuality.Value.ToString());\r
288                     line.WriteLine(check_2PassEncode.CheckState.ToString());\r
289                     line.WriteLine(check_DeInterlace.CheckState.ToString());\r
290                     line.WriteLine(check_grayscale.CheckState.ToString());\r
291                     line.WriteLine(drp_videoFramerate.Text);\r
292                     line.WriteLine(Check_ChapterMarkers.CheckState.ToString());\r
293                     line.WriteLine(CheckPixelRatio.CheckState.ToString());\r
294                     line.WriteLine(check_turbo.CheckState.ToString());\r
295                     line.WriteLine(check_largeFile.CheckState.ToString());\r
296                     //Audio Settings Tab\r
297                     line.WriteLine(drp_audioBitrate.Text);\r
298                     line.WriteLine(drp_audioSampleRate.Text);\r
299                     line.WriteLine(drp_audioChannels.Text);\r
300                     line.WriteLine(drp_audioMixDown.Text);\r
301                     //H264 Tab\r
302                     line.WriteLine(CheckCRF.CheckState.ToString());\r
303                     line.WriteLine(rtf_h264advanced.Text);\r
304                     // close the stream\r
305                     line.Close();\r
306                     MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
307                 }\r
308                 catch(Exception)\r
309                 {\r
310                     MessageBox.Show("Unable to write to the file. Please make sure the location has the correct permissions for file writing.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
311                 }\r
312                 \r
313             }\r
314         }\r
315 \r
316         private void mnu_update_Click(object sender, EventArgs e)\r
317         {\r
318             Form Update = new frmUpdate();\r
319             Update.ShowDialog();\r
320         }\r
321 \r
322         private void mnu_exit_Click(object sender, EventArgs e)\r
323         {\r
324             this.Close();\r
325         }\r
326 \r
327         #endregion\r
328 \r
329         #region Tools Menu\r
330 \r
331         private void mnu_encode_Click(object sender, EventArgs e)\r
332         {\r
333             showQueue();\r
334         }\r
335 \r
336         private frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
337         private void mnu_viewDVDdata_Click(object sender, EventArgs e)\r
338         {\r
339             dvdInfoWindow.Show();\r
340 \r
341             // BUG *******************************************************\r
342             // Cross-thread operation not valid: Control 'rtf_dvdInfo' accessed from a thread other than the thread it was created on.\r
343             // This happens when the DVD is scanned and this item is then selected.\r
344             // If this item is selected so a blank copy of the window appears, then a DVD is scanned, there is no cross-thread issue.\r
345             // ***********************************************************\r
346 \r
347         }\r
348 \r
349         private void mnu_options_Click(object sender, EventArgs e)\r
350         {\r
351             Form Options = new frmOptions();\r
352             Options.ShowDialog();\r
353         }\r
354 \r
355         #endregion\r
356 \r
357         #region Presets Menu\r
358 \r
359         private void mnu_preset_ipod133_Click(object sender, EventArgs e)\r
360         {\r
361             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
362             text_width.Text = "640";\r
363             text_height.Text = "480";\r
364             drp_videoEncoder.Text = "H.264 (iPod)";\r
365             text_bitrate.Text = "1000";\r
366             text_filesize.Text = "";\r
367             slider_videoQuality.Value = 0;\r
368             SliderValue.Text = "0%";\r
369             drp_audioBitrate.Text = "160";\r
370             rtf_h264advanced.Text = "";\r
371             drp_crop.Text = "No Crop";\r
372         }\r
373 \r
374         private void mnu_preset_ipod178_Click(object sender, EventArgs e)\r
375         {\r
376             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
377             text_width.Text = "640";\r
378             text_height.Text = "352";\r
379             drp_videoEncoder.Text = "H.264 (iPod)";\r
380             text_bitrate.Text = "1000";\r
381             text_filesize.Text = "";\r
382             slider_videoQuality.Value = 0;\r
383             SliderValue.Text = "0%";\r
384             drp_audioBitrate.Text = "160";\r
385             rtf_h264advanced.Text = "";\r
386             drp_crop.Text = "No Crop";\r
387         }\r
388 \r
389         private void mnu_preset_ipod235_Click(object sender, EventArgs e)\r
390         {\r
391             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
392             text_width.Text = "640";\r
393             text_height.Text = "272";\r
394             drp_videoEncoder.Text = "H.264 (iPod)";\r
395             text_bitrate.Text = "1000";\r
396             text_filesize.Text = "";\r
397             slider_videoQuality.Value = 0;\r
398             SliderValue.Text = "0%";\r
399             drp_audioBitrate.Text = "160";\r
400             rtf_h264advanced.Text = "";\r
401             drp_crop.Text = "No Crop";\r
402         }\r
403 \r
404         private void mnu_appleTv_Click(object sender, EventArgs e)\r
405         {\r
406             text_width.Text = "";\r
407             text_height.Text = "";\r
408             drp_videoEncoder.Text = "H.264";\r
409             text_bitrate.Text = "3000";\r
410             text_filesize.Text = "";\r
411             slider_videoQuality.Value = 0;\r
412             SliderValue.Text = "0%";\r
413             drp_audioBitrate.Text = "160";\r
414             CheckPixelRatio.CheckState = CheckState.Checked;\r
415             drp_audioSampleRate.Text = "48";\r
416             rtf_h264advanced.Text = "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";\r
417             drp_crop.Text = "No Crop";\r
418             \r
419         }\r
420 \r
421         private void mnu_presetPS3_Click(object sender, EventArgs e)\r
422         {\r
423             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
424             text_width.Text = "";\r
425             text_height.Text = "";\r
426             drp_videoEncoder.Text = "H.264";\r
427             text_bitrate.Text = "3000";\r
428             text_filesize.Text = "";\r
429             slider_videoQuality.Value = 0;\r
430             SliderValue.Text = "0%";\r
431             drp_audioBitrate.Text = "160";\r
432             CheckPixelRatio.CheckState = CheckState.Checked;\r
433             drp_audioSampleRate.Text = "48";\r
434             rtf_h264advanced.Text = "level=41";\r
435             drp_crop.Text = "No Crop";\r
436         }\r
437 \r
438         private void mnu_ProgramDefaultOptions_Click(object sender, EventArgs e)\r
439         {\r
440             //Source\r
441             Properties.Settings.Default.DVDSource = text_source.Text;\r
442             Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;\r
443             Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;\r
444             Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;\r
445             //Destination\r
446             Properties.Settings.Default.VideoDest = text_destination.Text;\r
447             Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;\r
448             Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;\r
449             Properties.Settings.Default.Width = text_width.Text;\r
450             Properties.Settings.Default.Height = text_height.Text;\r
451             //Picture Settings Tab\r
452             Properties.Settings.Default.CroppingOption = drp_crop.Text;\r
453             Properties.Settings.Default.CropTop = text_top.Text;\r
454             Properties.Settings.Default.CropBottom = text_bottom.Text;\r
455             Properties.Settings.Default.CropLeft = text_left.Text;\r
456             Properties.Settings.Default.CropRight = text_right.Text;\r
457             Properties.Settings.Default.Subtitles = drp_subtitle.Text;\r
458             //Video Settings Tab\r
459             Properties.Settings.Default.VideoBitrate = text_bitrate.Text;\r
460             Properties.Settings.Default.VideoFilesize = text_filesize.Text;\r
461             Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;\r
462             Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();\r
463             Properties.Settings.Default.DeInterlace = check_DeInterlace.CheckState.ToString();\r
464             Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();\r
465             Properties.Settings.Default.Framerate = drp_videoFramerate.Text;\r
466             Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();\r
467             Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();\r
468             Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString();\r
469             //Audio Settings Tab\r
470             Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;\r
471             Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;\r
472             Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;\r
473             //H264 Tab\r
474             Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();\r
475             Properties.Settings.Default.H264 = rtf_h264advanced.Text;\r
476             Properties.Settings.Default.Save();\r
477         }\r
478 \r
479         #endregion\r
480 \r
481         #region Help Menu\r
482 \r
483         private void mnu_wiki_Click(object sender, EventArgs e)\r
484         {\r
485            Process.Start("http://handbrake.m0k.org/trac");\r
486         }\r
487 \r
488         private void mnu_onlineDocs_Click(object sender, EventArgs e)\r
489         {\r
490             Process.Start("http://handbrake.m0k.org/?page_id=11");\r
491         }\r
492 \r
493         private void mnu_faq_Click(object sender, EventArgs e)\r
494         {\r
495             Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");\r
496         }\r
497 \r
498         private void mnu_homepage_Click(object sender, EventArgs e)\r
499         {\r
500            Process.Start("http://handbrake.m0k.org");\r
501         }\r
502 \r
503         private void mnu_forum_Click(object sender, EventArgs e)\r
504         {\r
505             Process.Start("http://handbrake.m0k.org/forum");\r
506         }\r
507 \r
508         private void mnu_about_Click(object sender, EventArgs e)\r
509         {\r
510                         Form About = new frmAbout();\r
511             About.ShowDialog();\r
512         }\r
513 \r
514         #endregion\r
515 \r
516         // -------------------------------------------------------------- \r
517         // Buttons on the main Window\r
518         // --------------------------------------------------------------\r
519         private void btn_Browse_Click(object sender, EventArgs e)\r
520         {\r
521             \r
522             String filename ="";\r
523             text_source.Text = "";\r
524 \r
525             if (RadioDVD.Checked)\r
526             {\r
527                 DVD_Open.ShowDialog();\r
528                 filename = DVD_Open.SelectedPath;\r
529                 if (filename != "")\r
530                 {\r
531                     text_source.Text = filename;\r
532                     Form frmReadDVD = new frmReadDVD(filename, this, dvdInfoWindow);\r
533                     frmReadDVD.ShowDialog();\r
534                 }\r
535             }\r
536             else\r
537             {\r
538                 ISO_Open.ShowDialog();\r
539                 filename = ISO_Open.FileName;\r
540                 if (filename != "")\r
541                 {\r
542                     text_source.Text = filename;\r
543                     Form frmReadDVD = new frmReadDVD(filename, this, dvdInfoWindow);\r
544                     frmReadDVD.ShowDialog();\r
545                 }\r
546             }  \r
547 \r
548             // Quick check to make sure some titles were found.\r
549             if (filename != "")\r
550             {\r
551                 if (drp_dvdtitle.Items.Count == 0)\r
552                 {\r
553                     MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
554                 }\r
555             }\r
556             else\r
557             {\r
558                 text_source.Text = "Click 'Browse' to continue";\r
559             }\r
560 \r
561         }\r
562 \r
563         private void btn_destBrowse_Click(object sender, EventArgs e)\r
564         {\r
565             // TODO: Need to write some code to check if there is a reasonable amount of disk space left.\r
566 \r
567             DVD_Save.ShowDialog();\r
568             text_destination.Text = DVD_Save.FileName;\r
569 \r
570             if (Check_ChapterMarkers.Checked)\r
571             {\r
572                 string destination = text_destination.Text;\r
573                 destination = destination.Replace(".mp4", ".m4v");\r
574                 text_destination.Text = destination;\r
575             }\r
576         }\r
577 \r
578         private void btn_h264Clear_Click(object sender, EventArgs e)\r
579         {\r
580             rtf_h264advanced.Text = "";\r
581         }\r
582 \r
583         private void GenerateQuery_Click(object sender, EventArgs e)\r
584         {\r
585             String query = GenerateTheQuery();\r
586             QueryEditorText.Text = query;\r
587         }\r
588 \r
589         private void btn_ClearQuery_Click(object sender, EventArgs e)\r
590         {\r
591             QueryEditorText.Text = "";\r
592         }\r
593 \r
594         private void btn_queue_Click(object sender, EventArgs e)\r
595         {\r
596             String query = GenerateTheQuery();\r
597             queueWindow.list_queue.Items.Add(query);\r
598             queueWindow.Show();\r
599         }\r
600 \r
601         private void showQueue()\r
602         {\r
603             queueWindow.Show();\r
604         }\r
605 \r
606         private void btn_encode_Click(object sender, EventArgs e)\r
607         {\r
608             String query = "";\r
609             lbl_encode.Visible = true;\r
610  \r
611             if (QueryEditorText.Text == "")\r
612             {\r
613                 query = GenerateTheQuery();\r
614             }\r
615             else\r
616             {\r
617                 query = QueryEditorText.Text;\r
618             }\r
619 \r
620             ThreadPool.QueueUserWorkItem(procMonitor, query);\r
621         }\r
622 \r
623         private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
624         {\r
625             if (this.InvokeRequired)\r
626             {\r
627                 this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),\r
628                     new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
629                 return;\r
630             }\r
631             lbl_encode.Text = string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
632         }\r
633 \r
634         private void procMonitor(object state)\r
635         {\r
636             Functions.CLI process = new Functions.CLI();\r
637             hbProc = process.runCli(this, (string)state, true, true, false, true);\r
638 \r
639             MessageBox.Show("The encode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
640 \r
641             Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);\r
642             //TODO: prevent this event from being subscribed more than once\r
643             encode.OnEncodeProgress += encode_OnEncodeProgress;\r
644             while (!encode.EndOfStream)\r
645             {\r
646                 encode.ReadLine();\r
647             }\r
648 \r
649             \r
650             hbProc.WaitForExit();\r
651             hbProc.Close();\r
652             hbProc.Dispose();\r
653             hbProc = null;\r
654             MessageBox.Show("The encode process has now ended.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
655         }\r
656         \r
657         //---------------------------------------------------\r
658         //  Items that require actions on frmMain\r
659         //---------------------------------------------------\r
660 \r
661         private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)\r
662         {\r
663             lbl_chptWarn.Visible = false;\r
664             QueryEditorText.Text = "";\r
665             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
666             {\r
667                 try\r
668                 {\r
669                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
670                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
671 \r
672                     if (chapterFinish < chapterStart)\r
673                     {\r
674                         lbl_chptWarn.Visible = true;\r
675                         lbl_chptWarn.Text = "Invalid Chapter Range!";\r
676                     }\r
677                 }\r
678                 catch (Exception)\r
679                 {\r
680                     lbl_chptWarn.Visible = true;\r
681                     lbl_chptWarn.Text = "Invalid Chapter Range!";\r
682                 }\r
683             }\r
684 \r
685             \r
686         }\r
687 \r
688         private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)\r
689         {\r
690             lbl_chptWarn.Visible = false;\r
691             QueryEditorText.Text = "";\r
692             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
693             {\r
694                 try\r
695                 {\r
696                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
697                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
698 \r
699                     if (chapterFinish < chapterStart)\r
700                     {\r
701                         lbl_chptWarn.Visible = true;\r
702                         lbl_chptWarn.Text = "Invalid Chapter Range!";\r
703                     }\r
704                 }\r
705                 catch (Exception)\r
706                 {\r
707                     lbl_chptWarn.Visible = true;\r
708                     lbl_chptWarn.Text = "Invalid Chapter Range!";\r
709                 }\r
710             }\r
711         }\r
712 \r
713         private void text_bitrate_TextChanged(object sender, EventArgs e)\r
714         {\r
715             text_filesize.Text = "";\r
716             slider_videoQuality.Value = 0;\r
717             SliderValue.Text = "0%";\r
718             CheckCRF.CheckState = CheckState.Unchecked;\r
719         }\r
720 \r
721         private void text_filesize_TextChanged(object sender, EventArgs e)\r
722         {\r
723             text_bitrate.Text = "";\r
724             slider_videoQuality.Value = 0;\r
725             SliderValue.Text = "0%";\r
726             CheckCRF.CheckState = CheckState.Unchecked;\r
727         }\r
728 \r
729         private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
730         {\r
731             SliderValue.Text = slider_videoQuality.Value.ToString() + "%";\r
732             text_bitrate.Text = "";\r
733             text_filesize.Text = "";\r
734         }\r
735 \r
736         private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
737         {\r
738             Process.Start("http://handbrake.m0k.org/trac/wiki/x264Options");\r
739         }\r
740 \r
741         private void text_width_TextChanged(object sender, EventArgs e)\r
742         {\r
743 \r
744             try\r
745             {\r
746                 if (CheckPixelRatio.Checked)\r
747                 {\r
748                     text_width.Text = "";\r
749                     text_width.BackColor = Color.White;\r
750                 }\r
751                 else\r
752                 {\r
753                     if ((int.Parse(text_width.Text) % 16) != 0)\r
754                     {\r
755                         text_width.BackColor = Color.LightCoral;\r
756                     }\r
757                     else\r
758                     {\r
759                         text_width.BackColor = Color.LightGreen;\r
760                     }\r
761                 }\r
762 \r
763                 if (lbl_Aspect.Text != "Select a Title")\r
764                 {\r
765                     double height = int.Parse(text_width.Text) / double.Parse(lbl_Aspect.Text);\r
766                     double mod16 = height % 16;\r
767                     height = height - mod16;\r
768 \r
769                     if (text_width.Text == "")\r
770                     {\r
771                         text_height.Text = "";\r
772                         text_width.BackColor = Color.White;\r
773                     }\r
774                     else\r
775                     {\r
776                         text_height.Text = height.ToString();\r
777                     }\r
778                 }\r
779             }\r
780             catch (Exception)\r
781             {\r
782                 // No need to throw an error here.\r
783             }\r
784                \r
785           \r
786         }\r
787 \r
788         private void text_height_TextChanged(object sender, EventArgs e)\r
789         {\r
790             try\r
791             {\r
792                 if (CheckPixelRatio.Checked)\r
793                 {\r
794                     text_height.Text = "";\r
795                     text_width.BackColor = Color.White;\r
796                 }\r
797                 else\r
798                 {\r
799                     if ((int.Parse(text_height.Text) % 16) != 0)\r
800                     {\r
801                         text_height.BackColor = Color.LightCoral;\r
802                     }\r
803                     else\r
804                     {\r
805                         text_height.BackColor = Color.LightGreen;\r
806                     }\r
807                 }\r
808             } catch(Exception){\r
809                 // No need to alert the user.\r
810             }\r
811         }\r
812 \r
813         private void drp_crop_SelectedIndexChanged(object sender, EventArgs e)\r
814         {\r
815             if ((string)drp_crop.SelectedItem == "Manual")\r
816             {\r
817             text_left.Enabled = true;\r
818             text_right.Enabled = true;\r
819             text_top.Enabled = true;\r
820             text_bottom.Enabled = true;\r
821             }\r
822 \r
823             if ((string)drp_crop.SelectedItem == "Auto Crop")\r
824             {\r
825                 text_left.Enabled = false;\r
826                 text_right.Enabled = false;\r
827                 text_top.Enabled = false;\r
828                 text_bottom.Enabled = false;\r
829                 text_left.Text = "";\r
830                 text_right.Text = "";\r
831                 text_top.Text = "";\r
832                 text_bottom.Text = "";\r
833 \r
834                 if (lbl_RecomendedCrop.Text != "Select a Title")\r
835                 {\r
836                     string[] temp = new string[4];\r
837                     temp = lbl_RecomendedCrop.Text.Split('/');\r
838                     text_left.Text = temp[2];\r
839                     text_right.Text = temp[3];\r
840                     text_top.Text = temp[0];\r
841                     text_bottom.Text = temp[1];\r
842                 }\r
843             }\r
844 \r
845             if ((string)drp_crop.SelectedItem == "No Crop")\r
846             {\r
847                 text_left.Enabled = false;\r
848                 text_right.Enabled = false;\r
849                 text_top.Enabled = false;\r
850                 text_bottom.Enabled = false;\r
851                 text_left.Text = "0";\r
852                 text_right.Text = "0";\r
853                 text_top.Text = "0";\r
854                 text_bottom.Text = "0";\r
855 \r
856             }\r
857         }\r
858         \r
859         private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)\r
860         {\r
861             text_width.Text = "";\r
862             text_height.Text = "";\r
863             text_width.BackColor = Color.White;\r
864             text_height.BackColor = Color.White;\r
865         }\r
866 \r
867         private void drp_dvdtitle_Click(object sender, EventArgs e)\r
868         {\r
869             if (drp_dvdtitle.Items.Count == 1)\r
870             {\r
871                 MessageBox.Show("There are no titles to select. Please scan the DVD by clicking the 'browse' button above before trying to select a title.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
872             }\r
873         }\r
874 \r
875         private void drp_audioCodec_SelectedIndexChanged(object sender, EventArgs e)\r
876         {\r
877 \r
878             //CLI Audio mixdown Names: mono stereo dpl1 dpl2 6ch\r
879 \r
880             drp_audioMixDown.Items.Clear();\r
881 \r
882             if (drp_audioCodec.Text == "AAC")\r
883             {\r
884                 drp_audioMixDown.Items.Clear();\r
885                 drp_audioMixDown.Items.Add("Mono");\r
886                 drp_audioMixDown.Items.Add("Stereo");\r
887                 drp_audioMixDown.Items.Add("Dolby Surround");\r
888                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
889                 drp_audioMixDown.Items.Add("6 Channel Discrete");\r
890                 \r
891                 drp_audioBitrate.Items.Clear();\r
892                 drp_audioBitrate.Items.Add("32");\r
893                 drp_audioBitrate.Items.Add("40");\r
894                 drp_audioBitrate.Items.Add("48");\r
895                 drp_audioBitrate.Items.Add("56");\r
896                 drp_audioBitrate.Items.Add("64");\r
897                 drp_audioBitrate.Items.Add("80");\r
898                 drp_audioBitrate.Items.Add("86");\r
899                 drp_audioBitrate.Items.Add("112");\r
900                 drp_audioBitrate.Items.Add("128");\r
901                 drp_audioBitrate.Items.Add("160");\r
902 \r
903             }\r
904             else\r
905             {\r
906                 drp_audioMixDown.Items.Clear();\r
907                 drp_audioMixDown.Items.Add("Stereo");\r
908                 drp_audioMixDown.Items.Add("Dolby Surround");\r
909                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
910 \r
911                 drp_audioBitrate.Items.Clear();\r
912                 drp_audioBitrate.Items.Add("32");\r
913                 drp_audioBitrate.Items.Add("40");\r
914                 drp_audioBitrate.Items.Add("48");\r
915                 drp_audioBitrate.Items.Add("56");\r
916                 drp_audioBitrate.Items.Add("64");\r
917                 drp_audioBitrate.Items.Add("80");\r
918                 drp_audioBitrate.Items.Add("86");\r
919                 drp_audioBitrate.Items.Add("112");\r
920                 drp_audioBitrate.Items.Add("128");\r
921                 drp_audioBitrate.Items.Add("160");\r
922                 drp_audioBitrate.Items.Add("192");\r
923                 drp_audioBitrate.Items.Add("224");\r
924                 drp_audioBitrate.Items.Add("256");\r
925                 drp_audioBitrate.Items.Add("320");\r
926                 drp_audioBitrate.Items.Add("384");\r
927             }\r
928         }\r
929 \r
930         private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e)\r
931         {\r
932             if (drp_audioCodec.Text == "AAC")\r
933             {\r
934                 if (drp_audioMixDown.Text == "6 Channel Discrete")\r
935                 {\r
936 \r
937                     drp_audioBitrate.Items.Clear();\r
938                     drp_audioBitrate.Items.Add("32");\r
939                     drp_audioBitrate.Items.Add("40");\r
940                     drp_audioBitrate.Items.Add("48");\r
941                     drp_audioBitrate.Items.Add("56");\r
942                     drp_audioBitrate.Items.Add("64");\r
943                     drp_audioBitrate.Items.Add("80");\r
944                     drp_audioBitrate.Items.Add("86");\r
945                     drp_audioBitrate.Items.Add("112");\r
946                     drp_audioBitrate.Items.Add("128");\r
947                     drp_audioBitrate.Items.Add("160");\r
948                     drp_audioBitrate.Items.Add("192");\r
949                     drp_audioBitrate.Items.Add("224");\r
950                     drp_audioBitrate.Items.Add("256");\r
951                     drp_audioBitrate.Items.Add("320");\r
952                     drp_audioBitrate.Items.Add("384");\r
953                 }\r
954             }\r
955         }\r
956 \r
957         private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)\r
958         {\r
959             if (Check_ChapterMarkers.Checked)\r
960             {\r
961                 string destination = text_destination.Text;\r
962                 destination = destination.Replace(".mp4", ".m4v");\r
963                 text_destination.Text = destination;\r
964             }\r
965         }\r
966 \r
967         private void check_largeFile_CheckedChanged(object sender, EventArgs e)\r
968         {\r
969             if (!text_destination.Text.Contains(".mp4"))\r
970             {\r
971                 MessageBox.Show("This option is only compatible with the mp4 file container.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
972                 check_largeFile.CheckState = CheckState.Unchecked;\r
973             }\r
974         }\r
975 \r
976         private void check_turbo_CheckedChanged(object sender, EventArgs e)\r
977         {\r
978             if (!drp_videoEncoder.Text.Contains("H.264"))\r
979             {\r
980                 MessageBox.Show("This option is only compatible with the H.264 encoder's", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
981                 check_turbo.CheckState = CheckState.Unchecked;\r
982             }\r
983         }\r
984 \r
985         private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)\r
986         {\r
987             //Turn off some options which are H.264 only when the user selects a non h.264 encoder\r
988             if (!drp_videoEncoder.Text.Contains("H.264"))\r
989             {\r
990                 check_turbo.CheckState = CheckState.Unchecked;\r
991                 CheckCRF.CheckState = CheckState.Unchecked;\r
992             }\r
993         }\r
994 \r
995         private void CheckCRF_CheckedChanged(object sender, EventArgs e)\r
996         {\r
997             if (slider_videoQuality.Value == 0)\r
998             {\r
999                 MessageBox.Show("This option is can only be used with the 'Video Quality' slider.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1000                 CheckCRF.CheckState = CheckState.Unchecked;\r
1001             }\r
1002         }\r
1003 \r
1004         public void setStreamReader(Parsing.DVD dvd)\r
1005         {\r
1006             this.thisDVD = dvd;\r
1007         }\r
1008 \r
1009         private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)\r
1010         {\r
1011             // Reset some values on the form\r
1012             lbl_Aspect.Text = "Select a Title";\r
1013             lbl_RecomendedCrop.Text = "Select a Title";\r
1014             drop_chapterStart.Items.Clear();\r
1015             drop_chapterFinish.Items.Clear();\r
1016             QueryEditorText.Text = "";\r
1017 \r
1018             // If the dropdown is set to automatic nothing else needs to be done.\r
1019             // Otheriwse if its not, title data has to be loased from parsing.\r
1020             if (drp_dvdtitle.Text != "Automatic")\r
1021             {\r
1022                 Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;\r
1023 \r
1024                 // Set the Aspect Ratio\r
1025                 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();\r
1026 \r
1027                 // Set the Recommended Cropping values\r
1028                 lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);\r
1029                 \r
1030                 // Populate the Start chapter Dropdown\r
1031                 drop_chapterStart.Items.Clear();\r
1032                 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());\r
1033                 if (drop_chapterStart.Items.Count > 0)\r
1034                 {\r
1035                     drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();\r
1036                 }\r
1037 \r
1038                 // Populate the Final Chapter Dropdown\r
1039                 drop_chapterFinish.Items.Clear();\r
1040                 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());\r
1041                 if (drop_chapterFinish.Items.Count > 0)\r
1042                 {\r
1043                     drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
1044                 }\r
1045 \r
1046                 // Populate the Audio Channels Dropdown\r
1047                 drp_audioChannels.Items.Clear();\r
1048                 drp_audioChannels.Items.Add("Automatic");\r
1049                 drp_audioChannels.Items.AddRange(selectedTitle.AudioTracks.ToArray());\r
1050                 if (drp_audioChannels.Items.Count > 0)\r
1051                 {\r
1052                     drp_audioChannels.Text = drp_audioChannels.Items[0].ToString();\r
1053                 }\r
1054 \r
1055                 // Populate the Subtitles dropdown\r
1056                 drp_subtitle.Items.Clear();\r
1057                 drp_subtitle.Items.Add("None");\r
1058                 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());\r
1059                 if (drp_subtitle.Items.Count > 0)\r
1060                 {\r
1061                     drp_subtitle.Text = drp_subtitle.Items[0].ToString();\r
1062                 }\r
1063             }\r
1064         }\r
1065 \r
1066         //---------------------------------------------------\r
1067         //  The query Generation function.\r
1068         //---------------------------------------------------\r
1069         public string GenerateTheQuery()\r
1070         {\r
1071             string source = text_source.Text;\r
1072             string dvdTitle = drp_dvdtitle.Text;\r
1073             string chapterStart = drop_chapterStart.Text;\r
1074             string chapterFinish = drop_chapterFinish.Text;\r
1075             int totalChapters = drop_chapterFinish.Items.Count - 1;\r
1076             string dvdChapter = "";\r
1077 \r
1078             if (source ==  "")\r
1079                 MessageBox.Show("No Source has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1080             else\r
1081             {\r
1082                 source = " -i " + '"' + source+ '"'; //'"'+\r
1083             }\r
1084 \r
1085             if (dvdTitle ==  "Automatic")\r
1086                 dvdTitle = "";\r
1087             else\r
1088             {\r
1089                 string[] titleInfo = dvdTitle.Split(' ');\r
1090                 dvdTitle = " -t "+ titleInfo[0];\r
1091             }\r
1092 \r
1093             if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))\r
1094                 dvdChapter = "";\r
1095             else if (chapterFinish == chapterStart)\r
1096                 dvdChapter = " -c " + chapterStart;\r
1097             else\r
1098                 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;\r
1099 \r
1100             string querySource = source+ dvdTitle+ dvdChapter;\r
1101             // ----------------------------------------------------------------------\r
1102 \r
1103             // Destination\r
1104 \r
1105             string destination = text_destination.Text;\r
1106             string videoEncoder = drp_videoEncoder.Text;\r
1107             string audioEncoder = drp_audioCodec.Text;\r
1108             string width = text_width.Text;\r
1109             string height = text_height.Text;\r
1110 \r
1111             if (destination ==  "")\r
1112                 MessageBox.Show("No destination has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1113             else\r
1114                 destination = " -o " + '"' + destination + '"'; //'"'+ \r
1115 \r
1116 \r
1117             switch (videoEncoder)\r
1118             {\r
1119                 case "Mpeg 4":\r
1120                     videoEncoder = " -e ffmpeg";\r
1121                     break;\r
1122                 case "Xvid":\r
1123                     videoEncoder = " -e xvid";\r
1124                     break;\r
1125                 case "H.264":\r
1126                     videoEncoder = " -e x264";\r
1127                     break;\r
1128                 case "H.264 Baseline 1.3":\r
1129                     videoEncoder = " -e x264b13";\r
1130                     break;\r
1131                 case "H.264 (iPod)":\r
1132                     videoEncoder = " -e x264b30";\r
1133                     break;\r
1134                 default:\r
1135                     videoEncoder = " -e x264";\r
1136                     break;\r
1137             }\r
1138            \r
1139             switch (audioEncoder)\r
1140             {\r
1141                 case "AAC":\r
1142                     audioEncoder = " -E faac";\r
1143                     break;\r
1144                 case "MP3":\r
1145                     audioEncoder = " -E lame";\r
1146                     break;\r
1147                 case "Vorbis":\r
1148                     audioEncoder = " -E vorbis";\r
1149                     break;\r
1150                 case "AC3":\r
1151                     audioEncoder = " -E ac3";\r
1152                     break;\r
1153                 default:\r
1154                     audioEncoder = " -E faac";\r
1155                     break;\r
1156             }\r
1157 \r
1158             if (width !=  "")\r
1159                 width = " -w "+ width;\r
1160             \r
1161 \r
1162             if (height !=  "")\r
1163                 height = " -l "+ height;\r
1164             \r
1165 \r
1166             string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height;\r
1167             // ----------------------------------------------------------------------\r
1168 \r
1169             // Picture Settings Tab\r
1170 \r
1171             string cropSetting = drp_crop.Text;\r
1172             string cropTop = text_top.Text;\r
1173             string cropBottom = text_bottom.Text;\r
1174             string cropLeft = text_left.Text;\r
1175             string cropRight = text_right.Text;\r
1176             string subtitles = drp_subtitle.Text;\r
1177             string cropOut = "";\r
1178             // Returns Crop Query\r
1179 \r
1180             if (cropSetting == "Auto Crop")\r
1181                 cropOut = "";\r
1182             else if (cropSetting == "No Crop")\r
1183                 cropOut = " --crop 0:0:0:0 ";\r
1184             else\r
1185                 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;\r
1186 \r
1187             if (subtitles ==  "None")\r
1188                 subtitles = "";\r
1189             else if (subtitles ==  "")\r
1190                 subtitles = "";\r
1191             else\r
1192             {\r
1193                 string[] tempSub;\r
1194                 tempSub = subtitles.Split(' ');\r
1195                 subtitles = " -s "+ tempSub[0];\r
1196             }\r
1197 \r
1198             string queryPictureSettings = cropOut+ subtitles;\r
1199             // ----------------------------------------------------------------------\r
1200 \r
1201             // Video Settings Tab\r
1202 \r
1203             string videoBitrate = text_bitrate.Text;\r
1204             string videoFilesize = text_filesize.Text;\r
1205             int videoQuality = slider_videoQuality.Value;\r
1206             string vidQSetting = "";\r
1207             string twoPassEncoding = "";\r
1208             string deinterlace = "";\r
1209             string grayscale = "";\r
1210             string videoFramerate = drp_videoFramerate.Text;\r
1211             string pixelRatio = "";\r
1212             string ChapterMarkers = "";\r
1213             string turboH264 = "";\r
1214             string largeFile = "";\r
1215 \r
1216             if (videoBitrate !=  "")\r
1217                 videoBitrate = " -b "+ videoBitrate;\r
1218 \r
1219             if (videoFilesize !=  "")\r
1220                 videoFilesize = " -S "+ videoFilesize;\r
1221 \r
1222             // Video Quality Setting\r
1223 \r
1224             if ((videoQuality ==  0))\r
1225                 vidQSetting = "";\r
1226             else\r
1227             {\r
1228                 videoQuality = videoQuality/ 100;\r
1229                 if (videoQuality ==  1)\r
1230                 {\r
1231                     vidQSetting = "1.0";\r
1232                 }\r
1233 \r
1234                 vidQSetting = " -q " + videoQuality.ToString();\r
1235             }\r
1236 \r
1237             if (check_2PassEncode.Checked)\r
1238                 twoPassEncoding = " -2 ";\r
1239 \r
1240             if (check_DeInterlace.Checked)\r
1241                 deinterlace = " -d ";\r
1242 \r
1243             if (check_grayscale.Checked)\r
1244                 grayscale = " -g ";\r
1245 \r
1246             if (videoFramerate ==  "Automatic")\r
1247                 videoFramerate = "";\r
1248             else\r
1249                 videoFramerate = " -r "+ videoFramerate;\r
1250 \r
1251             if (CheckPixelRatio.Checked)\r
1252                 pixelRatio = " -p ";\r
1253 \r
1254             if (Check_ChapterMarkers.Checked)\r
1255                 ChapterMarkers = " -m ";\r
1256 \r
1257             if (check_turbo.Checked)\r
1258                 turboH264 = " -T ";\r
1259 \r
1260             if (check_largeFile.Checked)\r
1261                 largeFile = " -4 ";\r
1262 \r
1263             string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + deinterlace + grayscale + videoFramerate + pixelRatio + ChapterMarkers + turboH264 + largeFile;\r
1264             // ----------------------------------------------------------------------\r
1265 \r
1266             // Audio Settings Tab\r
1267 \r
1268             string audioBitrate = drp_audioBitrate.Text;\r
1269             string audioSampleRate = drp_audioSampleRate.Text;\r
1270             string audioChannels = drp_audioChannels.Text;\r
1271             string Mixdown = drp_audioMixDown.Text;\r
1272             string SixChannelAudio = "";\r
1273 \r
1274             if (audioBitrate !=  "")\r
1275                 audioBitrate = " -B "+ audioBitrate;\r
1276 \r
1277             if (audioSampleRate !=  "")\r
1278                 audioSampleRate = " -R "+ audioSampleRate;\r
1279 \r
1280             if (audioChannels ==  "Automatic")\r
1281                 audioChannels = "";\r
1282             else if (audioChannels ==  "")\r
1283                 audioChannels = "";\r
1284             else\r
1285             {\r
1286                 string[] tempSub;\r
1287                 tempSub = audioChannels.Split(' ');\r
1288                 audioChannels = " -a "+ tempSub[0];\r
1289             }\r
1290 \r
1291             switch (Mixdown)\r
1292             {\r
1293                 case "Automatic":\r
1294                     Mixdown = "";\r
1295                     break;\r
1296                 case "Mono":\r
1297                     Mixdown = "mono";\r
1298                     break;\r
1299                 case "Stereo":\r
1300                     Mixdown = "stereo";\r
1301                     break;\r
1302                 case "Dolby Surround":\r
1303                     Mixdown = "dpl1";\r
1304                     break;\r
1305                 case "Dolby Pro Logic II":\r
1306                     Mixdown = "dpl2";\r
1307                     break;\r
1308                 case "6 Channel Discrete":\r
1309                     Mixdown = "6ch";\r
1310                     break;\r
1311                 default:\r
1312                     Mixdown = "stero";\r
1313                     break;\r
1314             }\r
1315 \r
1316             if (Mixdown !=  "")\r
1317                 SixChannelAudio = " -6 "+ Mixdown;\r
1318             else\r
1319                 SixChannelAudio = "";\r
1320 \r
1321             string queryAudioSettings = audioBitrate+ audioSampleRate+ audioChannels+ SixChannelAudio;\r
1322             // ----------------------------------------------------------------------\r
1323 \r
1324             //  H.264 Tab\r
1325 \r
1326             string CRF = CheckCRF.CheckState.ToString();\r
1327             string h264Advanced = rtf_h264advanced.Text;\r
1328             if ((CRF ==  "1"))\r
1329                 CRF = " -Q ";\r
1330             else\r
1331                 CRF = "";\r
1332 \r
1333             if ((h264Advanced ==  ""))\r
1334                 h264Advanced = "";\r
1335             else\r
1336                 h264Advanced = " -x "+ h264Advanced;\r
1337     \r
1338 \r
1339             string h264Settings = CRF+ h264Advanced;\r
1340             // ----------------------------------------------------------------------\r
1341 \r
1342             // Processors (Program Settings)\r
1343 \r
1344             string processors = Properties.Settings.Default.Processors;\r
1345             //  Number of Processors Handler\r
1346 \r
1347             if (processors ==  "Automatic")\r
1348                 processors = "";\r
1349             else\r
1350                 processors = " -C "+ processors+ " ";\r
1351 \r
1352 \r
1353             string queryAdvancedSettings = processors;\r
1354             // ----------------------------------------------------------------------\r
1355 \r
1356             //  Verbose option (Program Settings)\r
1357 \r
1358             string verbose = "";\r
1359             if (Properties.Settings.Default.verbose ==  "Checked")\r
1360                 verbose = " -v ";\r
1361 \r
1362             // ----------------------------------------------------------------------\r
1363 \r
1364             return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;\r
1365         }\r
1366 \r
1367         private void frmMain_Load(object sender, EventArgs e)\r
1368         {\r
1369 \r
1370         }\r
1371 \r
1372         // This is the END of the road ------------------------------------------------------------------------------\r
1373     }\r
1374 }