2 using System.Collections.Generic;
\r
4 using System.Text.RegularExpressions;
\r
5 using System.Windows.Forms;
\r
7 namespace Handbrake.Functions
\r
12 // All the Main Window GUI options
\r
15 private string q_source;
\r
17 /// Returns a String
\r
18 /// Full path of the source.
\r
20 public string Source
\r
24 return this.q_source;
\r
28 private string q_destination;
\r
30 /// Returns a String
\r
31 /// Full path of the destination.
\r
33 public string Destination
\r
37 return this.q_destination;
\r
41 private string q_format;
\r
43 /// Returns a String
\r
44 /// Full path of the destination.
\r
46 public string Format
\r
50 return this.q_format;
\r
54 private int q_dvdTitle;
\r
56 /// Returns an Integer
\r
57 /// DVD Title number.
\r
63 return this.q_dvdTitle;
\r
67 private int q_chaptersStart;
\r
70 /// DVD Chapter number or chapter range.
\r
72 public int DVDChapterStart
\r
76 return this.q_chaptersStart;
\r
80 private int q_chaptersFinish;
\r
83 /// DVD Chapter number or chapter range.
\r
85 public int DVDChapterFinish
\r
89 return this.q_chaptersFinish;
\r
93 private string q_videoEncoder;
\r
95 /// Returns an String
\r
96 /// The Video Encoder used.
\r
98 public string VideoEncoder
\r
102 return this.q_videoEncoder;
\r
106 private string q_audioEncoder;
\r
108 /// Returns an String
\r
109 /// The Audio Encoder used.
\r
111 public string AudioEncoder
\r
115 return this.q_audioEncoder;
\r
119 private int q_videoWidth;
\r
122 /// The selected Width for the encoding.
\r
128 return this.q_videoWidth;
\r
132 private int q_videoHeight;
\r
135 /// The selected Height for the encoding.
\r
141 return this.q_videoHeight;
\r
145 private string q_cropValues;
\r
147 /// Returns an String
\r
148 /// Cropping values.
\r
150 public string CropValues
\r
154 return this.q_cropValues;
\r
158 private string q_croptop;
\r
160 /// Returns an String
\r
161 /// Cropping values.
\r
163 public string CropTop
\r
167 return this.q_croptop;
\r
171 private string q_cropbottom;
\r
173 /// Returns an String
\r
174 /// Cropping values.
\r
176 public string CropBottom
\r
180 return this.q_cropbottom;
\r
184 private string q_cropLeft;
\r
186 /// Returns an String
\r
187 /// Cropping values.
\r
189 public string CropLeft
\r
193 return this.q_cropLeft;
\r
197 private string q_cropRight;
\r
199 /// Returns an String
\r
200 /// Cropping values.
\r
202 public string CropRight
\r
206 return this.q_cropRight;
\r
210 private Boolean q_detelecine;
\r
212 /// Returns a boolean to indicate wither DeTelecine is on or off
\r
214 public Boolean DeTelecine
\r
218 return this.q_detelecine;
\r
222 private Boolean q_deBlock;
\r
224 /// Returns a boolean to indicate wither DeBlock is on or off.
\r
226 public Boolean DeBlock
\r
230 return this.q_deBlock;
\r
234 private string q_deinterlace;
\r
236 /// Returns a string with the De-Interlace option used.
\r
238 public string DeInterlace
\r
242 return this.q_deinterlace;
\r
246 private string q_denoise;
\r
248 /// Returns a string with the DeNoise option used.
\r
250 public string DeNoise
\r
254 return this.q_denoise;
\r
258 private Boolean q_anamorphic;
\r
260 /// Returns a boolean to indicate wither Anamorphic is on or off.
\r
262 public Boolean Anamorphic
\r
266 return this.q_anamorphic;
\r
270 private Boolean q_chapterMarkers;
\r
272 /// Returns a boolean to indicate wither Chapter Markers is on or off.
\r
274 public Boolean ChapterMarkers
\r
278 return this.q_chapterMarkers;
\r
282 private Boolean q_grayscale;
\r
284 /// Returns a boolean to indicate wither Grayscale is on or off.
\r
286 public Boolean Grayscale
\r
290 return this.q_grayscale;
\r
294 private Boolean q_twoPass;
\r
296 /// Returns a boolean to indicate wither Two Pass Encoding is on or off.
\r
298 public Boolean TwoPass
\r
302 return this.q_twoPass;
\r
306 private Boolean q_turboFirst;
\r
308 /// Returns a boolean to indicate wither Chapter Markers is on or off.
\r
310 public Boolean TurboFirstPass
\r
314 return this.q_turboFirst;
\r
318 private Boolean q_largeMp4;
\r
320 /// Returns a boolean to indicate wither Larger MP4 files is on or off.
\r
322 public Boolean LargeMP4
\r
326 return this.q_largeMp4;
\r
330 private string q_videoFramerate;
\r
332 /// Returns a string with the video Framerate
\r
334 public string VideoFramerate
\r
338 return this.q_videoFramerate;
\r
342 private string q_avgBitrate;
\r
344 /// Returns a string with the average video bitrate
\r
346 public string AverageVideoBitrate
\r
350 return this.q_avgBitrate;
\r
354 private string q_videoTargetSize;
\r
356 /// Returns a string with the video target size
\r
358 public string VideoTargetSize
\r
362 return this.q_videoTargetSize;
\r
366 private int q_videoQuality;
\r
368 /// Returns a int with the video quality value
\r
370 public int VideoQuality
\r
374 return this.q_videoQuality;
\r
378 private Boolean q_crf;
\r
380 /// Returns a boolean to indicate if CRF is on or off.
\r
390 private string q_audioBitrate;
\r
392 /// Returns a string with the audio bitrate
\r
394 public string AudioBitrate
\r
398 return this.q_audioBitrate;
\r
402 private string q_audioSamplerate;
\r
404 /// Returns a string with the audio sample rate
\r
406 public string AudioSampleBitrate
\r
410 return this.q_audioSamplerate;
\r
414 private string q_audioTrack1;
\r
416 /// Returns a string with the First selected Audio track
\r
418 public string AudioTrack1
\r
422 return this.q_audioTrack1;
\r
426 private string q_audioTrackMix;
\r
428 /// Returns a string with the First selected Audio track Mix
\r
430 public string AudioTrackMix
\r
434 return this.q_audioTrackMix;
\r
438 private string q_subtitles;
\r
440 /// Returns a string with the selected subtitle track
\r
442 public string Subtitles
\r
446 return this.q_subtitles;
\r
450 private string q_h264;
\r
452 /// Returns a string with the Advanced H264 query string
\r
454 public string H264Query
\r
458 return this.q_h264;
\r
461 private Boolean q_verbose;
\r
463 /// Returns a string with the Advanced H264 query string
\r
465 public Boolean Verbose
\r
469 return this.q_verbose;
\r
474 // Takes in a query which can be in any order and parses it. All varibles are then set so they can be used elsewhere.
\r
475 public static QueryParser Parse(String input)
\r
477 QueryParser thisQuery = new QueryParser();
\r
481 Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9:\\\s\.]+)(?:\"")");
\r
482 Match source = r1.Match(input.Replace('"', '\"'));
\r
483 Match title = Regex.Match(input, @"-t ([0-9]*)");
\r
484 Match chapters = Regex.Match(input, @"-c ([0-9-]*)");
\r
485 Match format = Regex.Match(input, @"-f ([a-z0-9a-z0-9a-z0-9]*)");
\r
489 Regex r2 = new Regex(@"(-o)(?:\s\"")([a-zA-Z0-9:\\\s\.]+)(?:\"")");
\r
490 Match destination = r2.Match(input.Replace('"', '\"'));
\r
491 Match width = Regex.Match(input, @"-w ([0-9]*)");
\r
492 Match height = Regex.Match(input, @"-l ([0-9]*)");
\r
493 Match videoEncoder = Regex.Match(input, @"-e ([a-zA-Z0-9]*)");
\r
494 Match audioEncoder = Regex.Match(input, @"-E ([a-zA-Z0-9]*)");
\r
496 //Picture Settings Tab
\r
497 Match deinterlace = Regex.Match(input, @"--deinterlace=([a-z]*)");
\r
498 Match denoise = Regex.Match(input, @"--denoise=([a-z]*)");
\r
499 Match deblock = Regex.Match(input, @"--deblock");
\r
500 Match detelecine = Regex.Match(input, @"--detelecine");
\r
501 Match anamorphic = Regex.Match(input, @"-p ");
\r
502 Match chapterMarkers = Regex.Match(input, @"-m");
\r
503 Match crop = Regex.Match(input, @"--crop ([0-9]):([0-9]):([0-9]):([0-9])");
\r
505 //Video Settings Tab
\r
506 Match videoFramerate = Regex.Match(input, @"-r ([0-9]*)");
\r
507 Match videoBitrate = Regex.Match(input, @"-b ([0-9]*)");
\r
508 Match videoQuality = Regex.Match(input, @"-q ([0-9.]*)");
\r
509 Match videoFilesize = Regex.Match(input, @"-S ([0-9.]*)");
\r
510 Match CRF = Regex.Match(input, @"-Q");
\r
511 Match twoPass = Regex.Match(input, @"-2");
\r
512 Match turboFirstPass = Regex.Match(input, @"-T");
\r
513 Match grayscale = Regex.Match(input, @"-g");
\r
514 Match largerMp4 = Regex.Match(input, @"-4");
\r
516 //Audio Settings Tab
\r
517 Match subtitles = Regex.Match(input, @"-s ([0-9]*)");
\r
518 Match audioBitrate = Regex.Match(input, @"-B ([0-9]*)");
\r
519 Match audioSampleRate = Regex.Match(input, @"-R ([0-9.]*)");
\r
520 Match audioChannelsMix = Regex.Match(input, @"-6 ([0-9a-z0-9]*)"); // 1 -6 dpl2 // Broken
\r
521 Match audioChannel = Regex.Match(input, @"-a ([0-9]*)");
\r
524 Match x264 = Regex.Match(input, @"-x ([a-zA-Z0-9=:-]*)");
\r
527 Match verbose = Regex.Match(input, @"-v");
\r
537 thisQuery.q_source = source.ToString().Replace("-i ", "").Replace("\"", "");
\r
538 if (title.Success != false)
\r
540 thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", ""));
\r
543 if (chapters.Success != false)
\r
545 string[] actTitles = new string[2];
\r
546 actTitles = chapters.ToString().Replace("-c ", "").Split('-');
\r
547 thisQuery.q_chaptersStart = int.Parse(actTitles[0]);
\r
548 thisQuery.q_chaptersFinish = int.Parse(actTitles[1]);
\r
551 if (format.Success != false)
\r
554 thisQuery.q_format = format.ToString().Replace("-f ", "");
\r
561 #region Destination
\r
562 thisQuery.q_destination = destination.ToString().Replace("-o ","").Replace("\"", "");
\r
564 string videoEncoderConvertion;
\r
565 string audioEncoderConvertion;
\r
567 videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", "");
\r
568 switch (videoEncoderConvertion)
\r
571 videoEncoderConvertion = "Mpeg 4";
\r
574 videoEncoderConvertion = "Xvid";
\r
577 videoEncoderConvertion = "H.264";
\r
580 videoEncoderConvertion = "H.264 Baseline 1.3";
\r
583 videoEncoderConvertion = "H.264 (iPod)";
\r
586 videoEncoderConvertion = "Mpeg 4";
\r
589 thisQuery.q_videoEncoder = videoEncoderConvertion;
\r
591 audioEncoderConvertion = audioEncoder.ToString().Replace("-E ", "");
\r
592 switch (audioEncoderConvertion)
\r
595 audioEncoderConvertion = "AAC";
\r
598 audioEncoderConvertion = "MP3";
\r
601 audioEncoderConvertion = "Vorbis";
\r
604 audioEncoderConvertion = "AC3";
\r
607 audioEncoderConvertion = "AAC";
\r
610 thisQuery.q_audioEncoder =audioEncoderConvertion;
\r
613 if (width.Success != false)
\r
615 thisQuery.q_videoWidth = int.Parse(width.ToString().Replace("-w ", ""));
\r
617 if (height.Success != false)
\r
619 thisQuery.q_videoHeight = int.Parse(height.ToString().Replace("-l ", ""));
\r
624 //Picture Settings Tab
\r
626 #region Picture Tab
\r
627 if (crop.Success != false)
\r
629 thisQuery.q_cropValues = crop.ToString().Replace("--crop ", "");
\r
630 string[] actCropValues = new string[3];
\r
631 actCropValues = thisQuery.q_cropValues.Split(':');
\r
632 thisQuery.q_croptop = actCropValues[0];
\r
633 thisQuery.q_cropbottom = actCropValues[1];
\r
634 thisQuery.q_cropLeft = actCropValues[2];
\r
635 thisQuery.q_cropRight = actCropValues[3];
\r
638 thisQuery.q_detelecine = detelecine.Success;
\r
639 thisQuery.q_deBlock = deblock.Success;
\r
641 thisQuery.q_deinterlace = "None";
\r
642 if (deinterlace.Success != false)
\r
644 switch (deinterlace.ToString().Replace("--deinterlace=", ""))
\r
647 thisQuery.q_deinterlace = "Original (Fast)";
\r
650 thisQuery.q_deinterlace = "yadif (Slow)";
\r
653 thisQuery.q_deinterlace = "yadif + mcdeint (Slower)";
\r
656 thisQuery.q_deinterlace = "yadif + mcdeint (Slowest)";
\r
659 thisQuery.q_deinterlace = "None";
\r
664 thisQuery.q_denoise = "None";
\r
665 if (denoise.Success != false)
\r
667 switch (denoise.ToString().Replace("--denoise=", ""))
\r
670 thisQuery.q_denoise = "Weak";
\r
673 thisQuery.q_denoise = "Medium";
\r
676 thisQuery.q_denoise = "Strong";
\r
679 thisQuery.q_denoise = "None";
\r
684 thisQuery.q_anamorphic = anamorphic.Success;
\r
685 thisQuery.q_chapterMarkers = chapterMarkers.Success;
\r
689 //Video Settings Tab
\r
692 thisQuery.q_grayscale = grayscale.Success;
\r
693 thisQuery.q_twoPass = twoPass.Success;
\r
694 thisQuery.q_turboFirst = turboFirstPass.Success;
\r
695 thisQuery.q_largeMp4 = largerMp4.Success;
\r
696 if (videoFramerate.Success != false)
\r
698 thisQuery.q_videoFramerate = videoFramerate.ToString().Replace("-r ", "");
\r
700 if (videoBitrate.Success != false)
\r
702 thisQuery.q_avgBitrate = videoBitrate.ToString().Replace("-b ", "");
\r
704 if (videoFilesize.Success != false)
\r
706 thisQuery.q_videoTargetSize = videoFilesize.ToString().Replace("-S ", "");
\r
709 double qConvert = 0;
\r
710 if (videoQuality.Success != false)
\r
712 qConvert = double.Parse(videoQuality.ToString().Replace("-q ", "")) * 100;
\r
713 qConvert = System.Math.Ceiling(qConvert);
\r
714 thisQuery.q_videoQuality = int.Parse(qConvert.ToString());
\r
716 thisQuery.q_crf = CRF.Success;
\r
720 //Audio Settings Tab
\r
723 if (audioBitrate.Success != false)
\r
725 thisQuery.q_audioBitrate = audioBitrate.ToString().Replace("-B ", "");
\r
727 if (audioSampleRate.Success != false)
\r
729 thisQuery.q_audioSamplerate = audioSampleRate.ToString().Replace("-R ", "");
\r
731 if (audioChannel.Success != false)
\r
733 thisQuery.q_audioTrack1 = audioChannel.ToString().Replace("-a ", "");
\r
737 thisQuery.q_audioTrack1 = "Automatic";
\r
740 thisQuery.q_audioTrackMix = "Automatic";
\r
741 if (audioChannelsMix.Success != false)
\r
743 switch (audioChannelsMix.ToString().Replace("-6 ", "").Replace(" ",""))
\r
746 thisQuery.q_audioTrackMix = "Mono";
\r
749 thisQuery.q_audioTrackMix = "Stereo";
\r
752 thisQuery.q_audioTrackMix = "Dolby Surround";
\r
755 thisQuery.q_audioTrackMix = "Dolby Pro Logic II";
\r
758 thisQuery.q_audioTrackMix = "6 Channel Discrete";
\r
761 thisQuery.q_audioTrackMix = "Automatic";
\r
766 if (subtitles.Success != false)
\r
768 thisQuery.q_subtitles = subtitles.ToString().Replace("-s ", "");
\r
772 thisQuery.q_subtitles = "None";
\r
777 //H264 tab and other
\r
779 #region h264 and other
\r
783 if (x264.Success != false)
\r
785 thisQuery.q_h264 = x264.ToString().Replace("-x ", "");
\r
791 thisQuery.q_verbose = verbose.Success;
\r
794 catch (Exception exc)
\r
796 MessageBox.Show("An error has occured in the Query Parser. Please report this error on the forum in the 'Windows' support section. \n\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r