3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.m0k.org/>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Collections.Generic;
\r
10 using System.Windows.Forms;
\r
11 using System.Globalization;
\r
13 using System.Drawing;
\r
15 namespace Handbrake.Functions
\r
20 * Checks for updates and returns "true" boolean if one exists.
\r
22 public Boolean updateCheck()
\r
26 Functions.RssReader rssRead = new Functions.RssReader();
\r
27 string build = rssRead.build();
\r
29 int latest = int.Parse(build);
\r
30 int current = Properties.Settings.Default.hb_build;
\r
31 int skip = Properties.Settings.Default.skipversion;
\r
39 Boolean update = (latest > current);
\r
43 catch (Exception exc)
\r
45 MessageBox.Show(exc.ToString());
\r
51 * Function which generates the filename and path automatically based on the Source Name, DVD title and DVD Chapters
\r
53 public void autoName(frmMain mainWindow)
\r
55 if (Properties.Settings.Default.autoNaming == "Checked")
\r
57 if (mainWindow.drp_dvdtitle.Text != "Automatic")
\r
59 string source = mainWindow.text_source.Text;
\r
60 string[] sourceName = source.Split('\\');
\r
61 source = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");
\r
63 string title = mainWindow.drp_dvdtitle.Text;
\r
64 string[] titlesplit = title.Split(' ');
\r
65 title = titlesplit[0];
\r
67 string cs = mainWindow.drop_chapterStart.Text;
\r
68 string cf = mainWindow.drop_chapterFinish.Text;
\r
70 if (title == "Automatic")
\r
81 if (!mainWindow.text_destination.Text.Contains("\\"))
\r
83 string filePath = "";
\r
84 if (Properties.Settings.Default.autoNamePath.Trim() != "")
\r
85 filePath = Properties.Settings.Default.autoNamePath + "\\";
\r
86 mainWindow.text_destination.Text = filePath + source + "_T" + title + "_C" + cs + dash + cf + ".mp4";
\r
90 string dest = mainWindow.text_destination.Text;
\r
92 string[] destName = dest.Split('\\');
\r
95 string[] extension = dest.Split('.');
\r
96 string ext = extension[extension.Length - 1];
\r
98 destName[destName.Length - 1] = source + "_T" + title + "_C" + cs + dash + cf + "." + ext;
\r
100 string fullDest = "";
\r
101 foreach (string part in destName)
\r
103 if (fullDest != "")
\r
104 fullDest = fullDest + "\\" + part;
\r
106 fullDest = fullDest + part;
\r
109 mainWindow.text_destination.Text = fullDest;
\r
116 * This function takes in a Query which has been parsed by QueryParser and sets up the GUI.
\r
118 public void presetLoader(frmMain mainWindow, Functions.QueryParser presetQuery, string name)
\r
120 // ---------------------------
\r
122 // ---------------------------
\r
126 if (presetQuery.Source != "")
\r
127 mainWindow.text_source.Text = presetQuery.Source;
\r
129 if (presetQuery.DVDTitle != 0)
\r
130 mainWindow.drp_dvdtitle.Text = presetQuery.DVDTitle.ToString();
\r
132 if (presetQuery.DVDChapterStart != 0)
\r
133 mainWindow.drop_chapterStart.Text = presetQuery.DVDChapterStart.ToString();
\r
135 if (presetQuery.DVDChapterFinish != 0)
\r
136 mainWindow.drop_chapterFinish.Text = presetQuery.DVDChapterFinish.ToString();
\r
138 if (presetQuery.Format != "")
\r
140 string destination = mainWindow.text_destination.Text;
\r
141 destination = destination.Replace(".mp4", "." + presetQuery.Format);
\r
142 destination = destination.Replace(".m4v", "." + presetQuery.Format);
\r
143 destination = destination.Replace(".avi", "." + presetQuery.Format);
\r
144 destination = destination.Replace(".mkv", "." + presetQuery.Format);
\r
145 destination = destination.Replace(".ogm", "." + presetQuery.Format);
\r
146 mainWindow.text_destination.Text = destination;
\r
152 #region destination
\r
154 if (presetQuery.Destination != "")
\r
155 mainWindow.text_destination.Text = presetQuery.Destination;
\r
157 mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;
\r
158 mainWindow.drp_audioCodec.Text = presetQuery.AudioEncoder;
\r
162 // Picture Settings Tab
\r
164 mainWindow.drp_crop.Text = "Manual";
\r
165 mainWindow.text_top.Text = presetQuery.CropTop;
\r
166 mainWindow.text_bottom.Text = presetQuery.CropBottom;
\r
167 mainWindow.text_left.Text = presetQuery.CropLeft;
\r
168 mainWindow.text_right.Text = presetQuery.CropRight;
\r
170 mainWindow.drp_deInterlace_option.Text = presetQuery.DeInterlace;
\r
171 mainWindow.drp_deNoise.Text = presetQuery.DeNoise;
\r
173 if (presetQuery.DeTelecine == true)
\r
174 mainWindow.check_detelecine.CheckState = CheckState.Checked;
\r
176 mainWindow.check_detelecine.CheckState = CheckState.Unchecked;
\r
179 if (presetQuery.DeBlock == true)
\r
180 mainWindow.check_deblock.CheckState = CheckState.Checked;
\r
182 mainWindow.check_deblock.CheckState = CheckState.Unchecked;
\r
184 if (presetQuery.ChapterMarkers == true)
\r
185 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
187 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;
\r
189 if (presetQuery.Anamorphic == true)
\r
190 mainWindow.CheckPixelRatio.CheckState = CheckState.Checked;
\r
192 mainWindow.CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
194 if (presetQuery.LooseAnamorphic == true)
\r
195 mainWindow.check_lAnamorphic.CheckState = CheckState.Checked;
\r
197 mainWindow.check_lAnamorphic.CheckState = CheckState.Unchecked;
\r
199 if (presetQuery.Width != 0)
\r
200 mainWindow.text_width.Text = presetQuery.Width.ToString();
\r
203 mainWindow.text_width.Text = "";
\r
204 mainWindow.text_width.BackColor = Color.White;
\r
207 if (presetQuery.Height != 0)
\r
208 mainWindow.text_height.Text = presetQuery.Height.ToString();
\r
211 mainWindow.text_height.Text = "";
\r
212 mainWindow.text_height.BackColor = Color.White;
\r
215 if (presetQuery.VFR == true)
\r
216 mainWindow.check_vfr.CheckState = CheckState.Checked;
\r
218 mainWindow.check_vfr.CheckState = CheckState.Unchecked;
\r
221 // Video Settings Tab
\r
223 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;
\r
224 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;
\r
225 mainWindow.slider_videoQuality.Value = presetQuery.VideoQuality;
\r
226 if (mainWindow.slider_videoQuality.Value != 0)
\r
228 int ql = presetQuery.VideoQuality;
\r
229 mainWindow.SliderValue.Text = ql.ToString() + "%";
\r
232 if (presetQuery.TwoPass == true)
\r
233 mainWindow.check_2PassEncode.CheckState = CheckState.Checked;
\r
235 mainWindow.check_2PassEncode.CheckState = CheckState.Unchecked;
\r
237 if (presetQuery.Grayscale == true)
\r
238 mainWindow.check_grayscale.CheckState = CheckState.Checked;
\r
240 mainWindow.check_grayscale.CheckState = CheckState.Unchecked;
\r
242 mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;
\r
244 if (presetQuery.TurboFirstPass == true)
\r
245 mainWindow.check_turbo.CheckState = CheckState.Checked;
\r
247 mainWindow.check_turbo.CheckState = CheckState.Unchecked;
\r
249 if (presetQuery.LargeMP4 == true)
\r
250 mainWindow.check_largeFile.CheckState = CheckState.Checked;
\r
252 mainWindow.check_largeFile.CheckState = CheckState.Unchecked;
\r
254 if (presetQuery.IpodAtom == true)
\r
255 mainWindow.check_iPodAtom.CheckState = CheckState.Checked;
\r
257 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
259 if (presetQuery.OptimizeMP4 == true)
\r
260 mainWindow.check_optimiseMP4.CheckState = CheckState.Checked;
\r
262 mainWindow.check_optimiseMP4.CheckState = CheckState.Unchecked;
\r
266 // Audio Settings Tab
\r
268 mainWindow.drp_audioBitrate.Text = presetQuery.AudioBitrate;
\r
269 mainWindow.drp_audioSampleRate.Text = presetQuery.AudioSampleBitrate;
\r
270 mainWindow.drp_track1Audio.Text = presetQuery.AudioTrack1;
\r
271 mainWindow.drp_track2Audio.Text = presetQuery.AudioTrack2;
\r
272 mainWindow.drp_audioMixDown.Text = presetQuery.AudioTrackMix;
\r
273 mainWindow.drp_subtitle.Text = presetQuery.Subtitles;
\r
275 if (presetQuery.ForcedSubtitles == true)
\r
277 mainWindow.check_forced.CheckState = CheckState.Checked;
\r
278 mainWindow.check_forced.Enabled = true;
\r
281 mainWindow.check_forced.CheckState = CheckState.Unchecked;
\r
283 // Dynamic Range Compression (Should be a float but we use double for ease)
\r
284 double value = presetQuery.DRC;
\r
286 value = value - 10;
\r
287 mainWindow.slider_drc.Value = int.Parse(value.ToString());
\r
289 double actualValue = presetQuery.DRC / 10;
\r
290 mainWindow.lbl_drc.Text = actualValue.ToString();
\r
295 // H264 Tab & Preset Name
\r
297 mainWindow.rtf_h264advanced.Text = presetQuery.H264Query;
\r
299 // Set the preset name
\r
300 mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";
\r
305 * This takes all the widgets on frmMain
\r
307 public string GenerateTheQuery(frmMain mainWindow)
\r
312 string source = mainWindow.text_source.Text;
\r
313 string dvdTitle = mainWindow.drp_dvdtitle.Text;
\r
314 string chapterStart = mainWindow.drop_chapterStart.Text;
\r
315 string chapterFinish = mainWindow.drop_chapterFinish.Text;
\r
316 int totalChapters = mainWindow.drop_chapterFinish.Items.Count - 1;
\r
317 string dvdChapter = "";
\r
319 if ((source != "") || (source != "Click 'Browse' to continue"))
\r
320 source = " -i " + '"' + source + '"';
\r
322 if (dvdTitle == "Automatic")
\r
326 string[] titleInfo = dvdTitle.Split(' ');
\r
327 dvdTitle = " -t " + titleInfo[0];
\r
330 if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))
\r
332 else if (chapterFinish == chapterStart)
\r
333 dvdChapter = " -c " + chapterStart;
\r
335 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;
\r
337 string querySource = source + dvdTitle + dvdChapter;
\r
341 #region Destination
\r
343 string destination = mainWindow.text_destination.Text;
\r
344 string videoEncoder = mainWindow.drp_videoEncoder.Text;
\r
345 string audioEncoder = mainWindow.drp_audioCodec.Text;
\r
346 string width = mainWindow.text_width.Text;
\r
347 string height = mainWindow.text_height.Text;
\r
349 if (destination != "")
\r
350 destination = " -o " + '"' + destination + '"'; //'"'+
\r
353 switch (videoEncoder)
\r
356 videoEncoder = " -e ffmpeg";
\r
359 videoEncoder = " -e xvid";
\r
362 videoEncoder = " -e x264";
\r
364 case "H.264 (iPod)":
\r
365 videoEncoder = " -e x264b30";
\r
368 videoEncoder = " -e x264";
\r
372 switch (audioEncoder)
\r
375 audioEncoder = " -E faac";
\r
378 audioEncoder = " -E lame";
\r
381 audioEncoder = " -E vorbis";
\r
384 audioEncoder = " -E ac3";
\r
387 audioEncoder = " -E faac";
\r
392 width = " -w " + width;
\r
395 if (height == "Auto")
\r
399 else if (height != "")
\r
401 height = " -l " + height;
\r
405 string queryDestination = destination + videoEncoder + audioEncoder + width + height;
\r
408 // Picture Settings Tab
\r
409 #region Picture Settings Tab
\r
411 string cropSetting = mainWindow.drp_crop.Text;
\r
412 string cropTop = mainWindow.text_top.Text;
\r
413 string cropBottom = mainWindow.text_bottom.Text;
\r
414 string cropLeft = mainWindow.text_left.Text;
\r
415 string cropRight = mainWindow.text_right.Text;
\r
416 string cropOut = "";
\r
417 string deInterlace_Option = mainWindow.drp_deInterlace_option.Text;
\r
418 string deinterlace = "";
\r
419 string grayscale = "";
\r
420 string pixelRatio = "";
\r
422 string deblock = "";
\r
423 string detelecine = "";
\r
424 string lanamorphic = "";
\r
428 if (cropSetting == "Automatic")
\r
430 else if (cropSetting == "No Crop")
\r
431 cropOut = " --crop 0:0:0:0 ";
\r
434 if (mainWindow.text_top.Text == "")
\r
436 if (mainWindow.text_bottom.Text == "")
\r
438 if (mainWindow.text_left.Text == "")
\r
440 if (mainWindow.text_right.Text == "")
\r
443 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;
\r
446 switch (deInterlace_Option)
\r
452 deinterlace = " --deinterlace=fast";
\r
455 deinterlace = " --deinterlace=slow";
\r
458 deinterlace = " --deinterlace=slower";
\r
461 deinterlace = " --deinterlace=slowest";
\r
468 if (mainWindow.check_grayscale.Checked)
\r
469 grayscale = " -g ";
\r
471 if (mainWindow.CheckPixelRatio.Checked)
\r
472 pixelRatio = " -p ";
\r
474 if (mainWindow.check_deblock.Checked)
\r
475 deblock = " --deblock";
\r
477 if (mainWindow.check_detelecine.Checked)
\r
478 detelecine = " --detelecine";
\r
480 if (mainWindow.check_vfr.Checked)
\r
483 if (mainWindow.check_lAnamorphic.Checked)
\r
484 lanamorphic = " -P ";
\r
486 string queryPictureSettings = cropOut + deinterlace + deblock + detelecine + vfr + grayscale + pixelRatio + lanamorphic;
\r
489 // Video Settings Tab
\r
490 #region Video Settings Tab
\r
492 string videoBitrate = mainWindow.text_bitrate.Text;
\r
493 string videoFilesize = mainWindow.text_filesize.Text;
\r
494 double videoQuality = mainWindow.slider_videoQuality.Value;
\r
495 string vidQSetting = "";
\r
496 string twoPassEncoding = "";
\r
497 string videoFramerate = mainWindow.drp_videoFramerate.Text;
\r
498 string turboH264 = "";
\r
499 string largeFile = "";
\r
500 string denoise = "";
\r
501 string ipodAtom = "";
\r
502 string optimizeMP4 = "";
\r
504 if (videoBitrate != "")
\r
505 videoBitrate = " -b " + videoBitrate;
\r
507 if (videoFilesize != "")
\r
508 videoFilesize = " -S " + videoFilesize;
\r
510 // Video Quality Setting
\r
512 if ((videoQuality == 0))
\r
516 videoQuality = videoQuality / 100;
\r
517 if (videoQuality == 1)
\r
519 vidQSetting = "1.0";
\r
521 vidQSetting = " -q " + videoQuality.ToString(new CultureInfo("en-US"));
\r
524 if (mainWindow.check_2PassEncode.Checked)
\r
525 twoPassEncoding = " -2 ";
\r
527 if (videoFramerate == "Automatic")
\r
528 videoFramerate = "";
\r
530 videoFramerate = " -r " + videoFramerate;
\r
532 if (mainWindow.check_turbo.Checked)
\r
533 turboH264 = " -T ";
\r
535 if (mainWindow.check_largeFile.Checked)
\r
536 largeFile = " -4 ";
\r
539 switch (mainWindow.drp_deNoise.Text)
\r
545 denoise = " --denoise=weak";
\r
548 denoise = " --denoise=medium";
\r
551 denoise = " --denoise=strong";
\r
558 if (mainWindow.check_iPodAtom.Checked)
\r
561 if (mainWindow.check_optimiseMP4.Checked)
\r
562 optimizeMP4 = " -O ";
\r
565 string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + videoFramerate + turboH264 + ipodAtom + optimizeMP4 + largeFile + denoise;
\r
568 // Audio Settings Tab
\r
569 #region Audio Settings Tab
\r
571 string audioBitrate = mainWindow.drp_audioBitrate.Text;
\r
572 string audioSampleRate = mainWindow.drp_audioSampleRate.Text;
\r
573 string track1 = mainWindow.drp_track1Audio.Text;
\r
574 string track2 = mainWindow.drp_track2Audio.Text;
\r
575 string audioChannels = "";
\r
576 string Mixdown = mainWindow.drp_audioMixDown.Text;
\r
577 string SixChannelAudio = "";
\r
578 string subtitles = mainWindow.drp_subtitle.Text;
\r
579 string subScan = "";
\r
580 string forced = "";
\r
583 if (audioBitrate != "")
\r
584 audioBitrate = " -B " + audioBitrate;
\r
586 if (audioSampleRate != "")
\r
587 audioSampleRate = " -R " + audioSampleRate;
\r
590 if (track1 == "Automatic")
\r
591 audioChannels = "";
\r
592 else if (track1 == "")
\r
593 audioChannels = "";
\r
594 else if (track1 == "None")
\r
595 audioChannels = " -a none";
\r
599 tempSub = track1.Split(' ');
\r
600 audioChannels = " -a " + tempSub[0];
\r
604 if (audioChannels != "")
\r
606 if ((track2 != "") && (track2 != "None"))
\r
609 tempSub = track2.Split(' ');
\r
610 audioChannels = audioChannels + "," + tempSub[0];
\r
615 if ((track2 != "") && (track2 != "None"))
\r
618 tempSub = track2.Split(' ');
\r
619 audioChannels = " -a " + tempSub[0];
\r
634 Mixdown = "stereo";
\r
636 case "Dolby Surround":
\r
639 case "Dolby Pro Logic II":
\r
642 case "6 Channel Discrete":
\r
651 SixChannelAudio = " -6 " + Mixdown;
\r
653 SixChannelAudio = "";
\r
655 if (subtitles == "None")
\r
657 else if (subtitles == "")
\r
659 else if (subtitles == "Autoselect")
\r
667 tempSub = subtitles.Split(' ');
\r
668 subtitles = " -s " + tempSub[0];
\r
671 if (mainWindow.check_forced.Checked)
\r
674 //Dynamic Range Compression (expects a float but a double is used for ease)
\r
675 double value = mainWindow.slider_drc.Value / 10.0;
\r
677 drc = " -D " + value;
\r
679 string queryAudioSettings = audioBitrate + audioSampleRate + drc + audioChannels + SixChannelAudio + subScan + subtitles + forced;
\r
682 // Chapter Markers Tab
\r
683 #region Chapter Markers
\r
685 string ChapterMarkers = "";
\r
687 if (mainWindow.Check_ChapterMarkers.Checked)
\r
689 Boolean saveCSV = chapterCSVSave(mainWindow);
\r
690 if (saveCSV == false)
\r
692 MessageBox.Show("Unable to save Chapter Makrers file! \n Chapter marker names will NOT be saved in your encode \n\n", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
693 ChapterMarkers = " -m ";
\r
697 string path = Path.Combine(Path.GetTempPath(), "chapters.csv");
\r
699 ChapterMarkers = " --markers=" + path;
\r
703 string chapter_markers = ChapterMarkers;
\r
709 string h264Advanced = mainWindow.rtf_h264advanced.Text;
\r
711 if ((h264Advanced == ""))
\r
714 h264Advanced = " -x " + h264Advanced;
\r
717 string h264Settings = h264Advanced;
\r
721 #region Processors / Other
\r
723 string processors = Properties.Settings.Default.Processors;
\r
724 // Number of Processors Handler
\r
726 if (processors == "Automatic")
\r
729 processors = " -C " + processors + " ";
\r
732 string queryAdvancedSettings = processors;
\r
734 string verbose = "";
\r
735 if (Properties.Settings.Default.verbose == "Checked")
\r
739 return querySource + queryDestination + queryPictureSettings + queryVideoSettings + h264Settings + queryAudioSettings + ChapterMarkers + queryAdvancedSettings + verbose;
\r
743 * Set's up the DataGridView on the Chapters tab (frmMain)
\r
745 public void chapterNaming(frmMain mainWindow)
\r
749 mainWindow.data_chpt.Rows.Clear();
\r
754 if (mainWindow.drop_chapterFinish.Text != "Auto")
\r
755 finish = int.Parse(mainWindow.drop_chapterFinish.Text);
\r
757 if (mainWindow.drop_chapterStart.Text != "Auto")
\r
758 start = int.Parse(mainWindow.drop_chapterStart.Text);
\r
760 rowCount = finish - (start - 1);
\r
762 while (i < rowCount)
\r
764 DataGridViewRow row = new DataGridViewRow();
\r
766 mainWindow.data_chpt.Rows.Insert(i, row);
\r
767 mainWindow.data_chpt.Rows[i].Cells[0].Value = (i + 1);
\r
768 mainWindow.data_chpt.Rows[i].Cells[1].Value = "Chapter " + (i + 1);
\r
772 catch (Exception exc)
\r
774 MessageBox.Show("chapterNaming() Error has occured: \n" + exc.ToString());
\r
779 * This function saves the data in the chapters tab, dataGridView into a CSV file called chapters.csv in this applications
\r
780 * running directory.
\r
782 private Boolean chapterCSVSave(frmMain mainWindow)
\r
786 string path = Path.Combine(Path.GetTempPath(), "chapters.csv");
\r
788 StringBuilder csv = new StringBuilder();
\r
790 foreach (DataGridViewRow row in mainWindow.data_chpt.Rows)
\r
792 csv.Append(row.Cells[0].Value.ToString());
\r
794 csv.Append(row.Cells[1].Value.ToString());
\r
795 csv.Append(Environment.NewLine);
\r
797 StreamWriter file = new StreamWriter(path);
\r
798 file.Write(csv.ToString());
\r
804 catch (Exception exc)
\r
806 MessageBox.Show(exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
811 // End of Functions
\r