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
86 if (Properties.Settings.Default.autoNamePath.Trim() != "Click 'Browse' to set the default location")
\r
87 filePath = Properties.Settings.Default.autoNamePath + "\\";
\r
89 mainWindow.text_destination.Text = filePath + source + "_T" + title + "_C" + cs + dash + cf + ".mp4";
\r
93 string dest = mainWindow.text_destination.Text;
\r
95 string[] destName = dest.Split('\\');
\r
98 string[] extension = dest.Split('.');
\r
99 string ext = extension[extension.Length - 1];
\r
101 destName[destName.Length - 1] = source + "_T" + title + "_C" + cs + dash + cf + "." + ext;
\r
103 string fullDest = "";
\r
104 foreach (string part in destName)
\r
106 if (fullDest != "")
\r
107 fullDest = fullDest + "\\" + part;
\r
109 fullDest = fullDest + part;
\r
112 mainWindow.text_destination.Text = fullDest;
\r
119 * This function takes in a Query which has been parsed by QueryParser and sets up the GUI.
\r
121 public void presetLoader(frmMain mainWindow, Functions.QueryParser presetQuery, string name)
\r
123 // ---------------------------
\r
125 // ---------------------------
\r
129 // Reset some vaules to stock first to prevent errors.
\r
130 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
132 // Now load all the new settings onto the main window
\r
133 if (presetQuery.Source != "")
\r
134 mainWindow.text_source.Text = presetQuery.Source;
\r
136 if (presetQuery.DVDTitle != 0)
\r
137 mainWindow.drp_dvdtitle.Text = presetQuery.DVDTitle.ToString();
\r
139 if (presetQuery.DVDChapterStart != 0)
\r
140 mainWindow.drop_chapterStart.Text = presetQuery.DVDChapterStart.ToString();
\r
142 if (presetQuery.DVDChapterFinish != 0)
\r
143 mainWindow.drop_chapterFinish.Text = presetQuery.DVDChapterFinish.ToString();
\r
145 if (presetQuery.Format != "")
\r
147 string destination = mainWindow.text_destination.Text;
\r
148 destination = destination.Replace(".mp4", "." + presetQuery.Format);
\r
149 destination = destination.Replace(".m4v", "." + presetQuery.Format);
\r
150 destination = destination.Replace(".avi", "." + presetQuery.Format);
\r
151 destination = destination.Replace(".mkv", "." + presetQuery.Format);
\r
152 destination = destination.Replace(".ogm", "." + presetQuery.Format);
\r
153 mainWindow.text_destination.Text = destination;
\r
159 #region destination
\r
161 if (presetQuery.Destination != "")
\r
162 mainWindow.text_destination.Text = presetQuery.Destination;
\r
164 mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;
\r
165 mainWindow.drp_audioCodec.Text = presetQuery.AudioEncoder;
\r
167 if (presetQuery.AudioEncoder == "AAC + AC3")
\r
169 mainWindow.text_destination.Text = mainWindow.text_destination.Text.Replace(".mp4", ".m4v");
\r
172 if (presetQuery.IpodAtom == true)
\r
173 mainWindow.check_iPodAtom.CheckState = CheckState.Checked;
\r
175 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
177 if (presetQuery.OptimizeMP4 == true)
\r
178 mainWindow.check_optimiseMP4.CheckState = CheckState.Checked;
\r
180 mainWindow.check_optimiseMP4.CheckState = CheckState.Unchecked;
\r
184 // Picture Settings Tab
\r
186 mainWindow.drp_crop.Text = "Manual";
\r
187 mainWindow.text_top.Text = presetQuery.CropTop;
\r
188 mainWindow.text_bottom.Text = presetQuery.CropBottom;
\r
189 mainWindow.text_left.Text = presetQuery.CropLeft;
\r
190 mainWindow.text_right.Text = presetQuery.CropRight;
\r
192 mainWindow.drp_deInterlace_option.Text = presetQuery.DeInterlace;
\r
193 mainWindow.drp_deNoise.Text = presetQuery.DeNoise;
\r
195 if (presetQuery.DeTelecine == true)
\r
196 mainWindow.check_detelecine.CheckState = CheckState.Checked;
\r
198 mainWindow.check_detelecine.CheckState = CheckState.Unchecked;
\r
201 if (presetQuery.DeBlock == true)
\r
202 mainWindow.check_deblock.CheckState = CheckState.Checked;
\r
204 mainWindow.check_deblock.CheckState = CheckState.Unchecked;
\r
207 if (presetQuery.Anamorphic == true)
\r
208 mainWindow.CheckPixelRatio.CheckState = CheckState.Checked;
\r
210 mainWindow.CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
212 if (presetQuery.LooseAnamorphic == true)
\r
213 mainWindow.check_lAnamorphic.CheckState = CheckState.Checked;
\r
215 mainWindow.check_lAnamorphic.CheckState = CheckState.Unchecked;
\r
217 if (presetQuery.Width != 0)
\r
218 mainWindow.text_width.Text = presetQuery.Width.ToString();
\r
221 mainWindow.text_width.Text = "";
\r
222 mainWindow.text_width.BackColor = Color.White;
\r
225 if (presetQuery.Height != 0)
\r
226 mainWindow.text_height.Text = presetQuery.Height.ToString();
\r
229 mainWindow.text_height.Text = "";
\r
230 mainWindow.text_height.BackColor = Color.White;
\r
233 if (presetQuery.VFR == true)
\r
234 mainWindow.check_vfr.CheckState = CheckState.Checked;
\r
236 mainWindow.check_vfr.CheckState = CheckState.Unchecked;
\r
239 // Video Settings Tab
\r
241 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;
\r
242 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;
\r
243 mainWindow.slider_videoQuality.Value = presetQuery.VideoQuality;
\r
244 if (mainWindow.slider_videoQuality.Value != 0)
\r
246 int ql = presetQuery.VideoQuality;
\r
247 mainWindow.SliderValue.Text = ql.ToString() + "%";
\r
250 if (presetQuery.TwoPass == true)
\r
251 mainWindow.check_2PassEncode.CheckState = CheckState.Checked;
\r
253 mainWindow.check_2PassEncode.CheckState = CheckState.Unchecked;
\r
255 if (presetQuery.Grayscale == true)
\r
256 mainWindow.check_grayscale.CheckState = CheckState.Checked;
\r
258 mainWindow.check_grayscale.CheckState = CheckState.Unchecked;
\r
260 mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;
\r
262 if (presetQuery.TurboFirstPass == true)
\r
263 mainWindow.check_turbo.CheckState = CheckState.Checked;
\r
265 mainWindow.check_turbo.CheckState = CheckState.Unchecked;
\r
267 if (presetQuery.LargeMP4 == true)
\r
268 mainWindow.check_largeFile.CheckState = CheckState.Checked;
\r
270 mainWindow.check_largeFile.CheckState = CheckState.Unchecked;
\r
276 // Chapter Markers Tab
\r
277 #region Chapter Markers
\r
279 if (presetQuery.ChapterMarkers == true)
\r
281 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
282 mainWindow.text_destination.Text = mainWindow.text_destination.Text.Replace(".mp4", ".m4v");
\r
285 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;
\r
289 // Audio Settings Tab
\r
291 mainWindow.drp_audioBitrate.Text = presetQuery.AudioBitrate;
\r
292 mainWindow.drp_audioSampleRate.Text = presetQuery.AudioSampleBitrate;
\r
293 mainWindow.drp_track1Audio.Text = presetQuery.AudioTrack1;
\r
294 mainWindow.drp_track2Audio.Text = presetQuery.AudioTrack2;
\r
295 mainWindow.drp_audioMixDown.Text = presetQuery.AudioTrackMix;
\r
296 mainWindow.drp_subtitle.Text = presetQuery.Subtitles;
\r
298 if (presetQuery.ForcedSubtitles == true)
\r
300 mainWindow.check_forced.CheckState = CheckState.Checked;
\r
301 mainWindow.check_forced.Enabled = true;
\r
304 mainWindow.check_forced.CheckState = CheckState.Unchecked;
\r
306 // Dynamic Range Compression (Should be a float but we use double for ease)
\r
307 double value = presetQuery.DRC;
\r
309 value = value - 10;
\r
310 mainWindow.slider_drc.Value = int.Parse(value.ToString());
\r
312 double actualValue = presetQuery.DRC / 10;
\r
313 mainWindow.lbl_drc.Text = actualValue.ToString();
\r
318 // H264 Tab & Preset Name
\r
320 mainWindow.rtf_h264advanced.Text = presetQuery.H264Query;
\r
322 // Set the preset name
\r
323 mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";
\r
328 * This takes all the widgets on frmMain
\r
330 public string GenerateTheQuery(frmMain mainWindow)
\r
335 string source = mainWindow.text_source.Text;
\r
336 string dvdTitle = mainWindow.drp_dvdtitle.Text;
\r
337 string chapterStart = mainWindow.drop_chapterStart.Text;
\r
338 string chapterFinish = mainWindow.drop_chapterFinish.Text;
\r
339 int totalChapters = mainWindow.drop_chapterFinish.Items.Count - 1;
\r
340 string dvdChapter = "";
\r
342 if ((source != "") || (source != "Click 'Browse' to continue"))
\r
343 source = " -i " + '"' + source + '"';
\r
345 if (dvdTitle == "Automatic")
\r
349 string[] titleInfo = dvdTitle.Split(' ');
\r
350 dvdTitle = " -t " + titleInfo[0];
\r
353 if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))
\r
355 else if (chapterFinish == chapterStart)
\r
356 dvdChapter = " -c " + chapterStart;
\r
358 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;
\r
360 string querySource = source + dvdTitle + dvdChapter;
\r
364 #region Destination
\r
366 string destination = mainWindow.text_destination.Text;
\r
367 string videoEncoder = mainWindow.drp_videoEncoder.Text;
\r
368 string audioEncoder = mainWindow.drp_audioCodec.Text;
\r
369 string width = mainWindow.text_width.Text;
\r
370 string height = mainWindow.text_height.Text;
\r
372 if (destination != "")
\r
373 destination = " -o " + '"' + destination + '"'; //'"'+
\r
376 switch (videoEncoder)
\r
379 videoEncoder = " -e ffmpeg";
\r
382 videoEncoder = " -e xvid";
\r
385 videoEncoder = " -e x264";
\r
387 case "H.264 (iPod)":
\r
388 videoEncoder = " -e x264b30";
\r
391 videoEncoder = " -e x264";
\r
395 switch (audioEncoder)
\r
398 audioEncoder = " -E faac";
\r
401 audioEncoder = " -E lame";
\r
404 audioEncoder = " -E vorbis";
\r
407 audioEncoder = " -E ac3";
\r
410 audioEncoder = " -E aac+ac3";
\r
413 audioEncoder = " -E faac";
\r
418 width = " -w " + width;
\r
421 if (height == "Auto")
\r
425 else if (height != "")
\r
427 height = " -l " + height;
\r
431 string queryDestination = destination + videoEncoder + audioEncoder + width + height;
\r
434 // Picture Settings Tab
\r
435 #region Picture Settings Tab
\r
437 string cropSetting = mainWindow.drp_crop.Text;
\r
438 string cropTop = mainWindow.text_top.Text;
\r
439 string cropBottom = mainWindow.text_bottom.Text;
\r
440 string cropLeft = mainWindow.text_left.Text;
\r
441 string cropRight = mainWindow.text_right.Text;
\r
442 string cropOut = "";
\r
443 string deInterlace_Option = mainWindow.drp_deInterlace_option.Text;
\r
444 string deinterlace = "";
\r
445 string grayscale = "";
\r
446 string pixelRatio = "";
\r
448 string deblock = "";
\r
449 string detelecine = "";
\r
450 string lanamorphic = "";
\r
454 if (cropSetting == "Automatic")
\r
456 else if (cropSetting == "No Crop")
\r
457 cropOut = " --crop 0:0:0:0 ";
\r
460 if (mainWindow.text_top.Text == "")
\r
462 if (mainWindow.text_bottom.Text == "")
\r
464 if (mainWindow.text_left.Text == "")
\r
466 if (mainWindow.text_right.Text == "")
\r
469 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;
\r
472 switch (deInterlace_Option)
\r
478 deinterlace = " --deinterlace=fast";
\r
481 deinterlace = " --deinterlace=slow";
\r
484 deinterlace = " --deinterlace=slower";
\r
487 deinterlace = " --deinterlace=slowest";
\r
494 if (mainWindow.check_grayscale.Checked)
\r
495 grayscale = " -g ";
\r
497 if (mainWindow.CheckPixelRatio.Checked)
\r
498 pixelRatio = " -p ";
\r
500 if (mainWindow.check_deblock.Checked)
\r
501 deblock = " --deblock";
\r
503 if (mainWindow.check_detelecine.Checked)
\r
504 detelecine = " --detelecine";
\r
506 if (mainWindow.check_vfr.Checked)
\r
509 if (mainWindow.check_lAnamorphic.Checked)
\r
510 lanamorphic = " -P ";
\r
512 string queryPictureSettings = cropOut + deinterlace + deblock + detelecine + vfr + grayscale + pixelRatio + lanamorphic;
\r
515 // Video Settings Tab
\r
516 #region Video Settings Tab
\r
518 string videoBitrate = mainWindow.text_bitrate.Text;
\r
519 string videoFilesize = mainWindow.text_filesize.Text;
\r
520 double videoQuality = mainWindow.slider_videoQuality.Value;
\r
521 string vidQSetting = "";
\r
522 string twoPassEncoding = "";
\r
523 string videoFramerate = mainWindow.drp_videoFramerate.Text;
\r
524 string vid_frame_rate = "";
\r
525 string turboH264 = "";
\r
526 string largeFile = "";
\r
527 string denoise = "";
\r
528 string ipodAtom = "";
\r
529 string optimizeMP4 = "";
\r
531 if (videoBitrate != "")
\r
532 videoBitrate = " -b " + videoBitrate;
\r
534 if (videoFilesize != "")
\r
535 videoFilesize = " -S " + videoFilesize;
\r
537 // Video Quality Setting
\r
539 if ((videoQuality == 0))
\r
543 videoQuality = videoQuality / 100;
\r
544 if (videoQuality == 1)
\r
546 vidQSetting = "1.0";
\r
548 vidQSetting = " -q " + videoQuality.ToString(new CultureInfo("en-US"));
\r
551 if (mainWindow.check_2PassEncode.Checked)
\r
552 twoPassEncoding = " -2 ";
\r
554 if (videoFramerate == "Automatic")
\r
555 vid_frame_rate = "";
\r
558 if (!mainWindow.check_vfr.Checked)
\r
559 vid_frame_rate = " -r " + videoFramerate;
\r
562 if (mainWindow.check_turbo.Checked)
\r
563 turboH264 = " -T ";
\r
565 if (mainWindow.check_largeFile.Checked)
\r
566 largeFile = " -4 ";
\r
569 switch (mainWindow.drp_deNoise.Text)
\r
575 denoise = " --denoise=weak";
\r
578 denoise = " --denoise=medium";
\r
581 denoise = " --denoise=strong";
\r
588 if (mainWindow.check_iPodAtom.Checked)
\r
591 if (mainWindow.check_optimiseMP4.Checked)
\r
592 optimizeMP4 = " -O ";
\r
595 string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + vid_frame_rate + turboH264 + ipodAtom + optimizeMP4 + largeFile + denoise;
\r
598 // Audio Settings Tab
\r
599 #region Audio Settings Tab
\r
601 string audioBitrate = mainWindow.drp_audioBitrate.Text;
\r
602 string audioSampleRate = mainWindow.drp_audioSampleRate.Text;
\r
603 string track1 = mainWindow.drp_track1Audio.Text;
\r
604 string track2 = mainWindow.drp_track2Audio.Text;
\r
605 string audioChannels = "";
\r
606 string Mixdown = mainWindow.drp_audioMixDown.Text;
\r
607 string SixChannelAudio = "";
\r
608 string subtitles = mainWindow.drp_subtitle.Text;
\r
609 string subScan = "";
\r
610 string forced = "";
\r
613 if (audioBitrate != "")
\r
614 audioBitrate = " -B " + audioBitrate;
\r
616 if (audioSampleRate != "")
\r
617 audioSampleRate = " -R " + audioSampleRate;
\r
620 if (track1 == "Automatic")
\r
621 audioChannels = "";
\r
622 else if (track1 == "")
\r
623 audioChannels = "";
\r
624 else if (track1 == "None")
\r
625 audioChannels = " -a none";
\r
629 tempSub = track1.Split(' ');
\r
630 audioChannels = " -a " + tempSub[0];
\r
634 if (audioChannels != "")
\r
636 if ((track2 != "") && (track2 != "None"))
\r
639 tempSub = track2.Split(' ');
\r
640 audioChannels = audioChannels + "," + tempSub[0];
\r
645 if ((track2 != "") && (track2 != "None"))
\r
648 tempSub = track2.Split(' ');
\r
649 audioChannels = " -a " + tempSub[0];
\r
664 Mixdown = "stereo";
\r
666 case "Dolby Surround":
\r
669 case "Dolby Pro Logic II":
\r
672 case "6 Channel Discrete":
\r
681 SixChannelAudio = " -6 " + Mixdown;
\r
683 SixChannelAudio = "";
\r
685 if (subtitles == "None")
\r
687 else if (subtitles == "")
\r
689 else if (subtitles == "Autoselect")
\r
697 tempSub = subtitles.Split(' ');
\r
698 subtitles = " -s " + tempSub[0];
\r
701 if (mainWindow.check_forced.Checked)
\r
704 //Dynamic Range Compression (expects a float but a double is used for ease)
\r
705 double value = mainWindow.slider_drc.Value / 10.0;
\r
707 drc = " -D " + value;
\r
709 string queryAudioSettings = audioBitrate + audioSampleRate + drc + audioChannels + SixChannelAudio + subScan + subtitles + forced;
\r
712 // Chapter Markers Tab
\r
713 #region Chapter Markers
\r
715 string ChapterMarkers = "";
\r
717 if (mainWindow.Check_ChapterMarkers.Checked)
\r
719 Boolean saveCSV = chapterCSVSave(mainWindow);
\r
720 if (saveCSV == false)
\r
722 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
723 ChapterMarkers = " -m ";
\r
727 string path = Path.Combine(Path.GetTempPath(), "chapters.csv");
\r
729 ChapterMarkers = " --markers=" + "\"" + path + "\"";
\r
733 string chapter_markers = ChapterMarkers;
\r
739 string h264Advanced = mainWindow.rtf_h264advanced.Text;
\r
741 if ((h264Advanced == ""))
\r
744 h264Advanced = " -x " + h264Advanced;
\r
747 string h264Settings = h264Advanced;
\r
751 #region Processors / Other
\r
753 string processors = Properties.Settings.Default.Processors;
\r
754 // Number of Processors Handler
\r
756 if (processors == "Automatic")
\r
759 processors = " -C " + processors + " ";
\r
762 string queryAdvancedSettings = processors;
\r
764 string verbose = " -v ";
\r
767 return querySource + queryDestination + queryPictureSettings + queryVideoSettings + h264Settings + queryAudioSettings + ChapterMarkers + queryAdvancedSettings + verbose;
\r
771 * Set's up the DataGridView on the Chapters tab (frmMain)
\r
773 public void chapterNaming(frmMain mainWindow)
\r
777 mainWindow.data_chpt.Rows.Clear();
\r
782 if (mainWindow.drop_chapterFinish.Text != "Auto")
\r
783 finish = int.Parse(mainWindow.drop_chapterFinish.Text);
\r
785 if (mainWindow.drop_chapterStart.Text != "Auto")
\r
786 start = int.Parse(mainWindow.drop_chapterStart.Text);
\r
788 rowCount = finish - (start - 1);
\r
790 while (i < rowCount)
\r
792 DataGridViewRow row = new DataGridViewRow();
\r
794 mainWindow.data_chpt.Rows.Insert(i, row);
\r
795 mainWindow.data_chpt.Rows[i].Cells[0].Value = (i + 1);
\r
796 mainWindow.data_chpt.Rows[i].Cells[1].Value = "Chapter " + (i + 1);
\r
800 catch (Exception exc)
\r
802 MessageBox.Show("chapterNaming() Error has occured: \n" + exc.ToString());
\r
807 * This function saves the data in the chapters tab, dataGridView into a CSV file called chapters.csv in this applications
\r
808 * running directory.
\r
810 private Boolean chapterCSVSave(frmMain mainWindow)
\r
814 string path = Path.Combine(Path.GetTempPath(), "chapters.csv");
\r
816 StringBuilder csv = new StringBuilder();
\r
818 foreach (DataGridViewRow row in mainWindow.data_chpt.Rows)
\r
820 csv.Append(row.Cells[0].Value.ToString());
\r
822 csv.Append(row.Cells[1].Value.ToString());
\r
823 csv.Append(Environment.NewLine);
\r
825 StreamWriter file = new StreamWriter(path);
\r
826 file.Write(csv.ToString());
\r
832 catch (Exception exc)
\r
834 MessageBox.Show(exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
839 // End of Functions
\r