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 int q_dvdTitle;
\r
43 /// Returns an Integer
\r
44 /// DVD Title number.
\r
50 return this.q_dvdTitle;
\r
54 private string q_dvdChapters;
\r
56 /// Returns an String
\r
57 /// DVD Chapter number or chapter range.
\r
59 public string DVDChapters
\r
63 return this.q_dvdChapters;
\r
67 private string q_videoEncoder;
\r
69 /// Returns an String
\r
70 /// The Video Encoder used.
\r
72 public string VideoEncoder
\r
76 return this.q_videoEncoder;
\r
80 private string q_audioEncoder;
\r
82 /// Returns an String
\r
83 /// The Audio Encoder used.
\r
85 public string AudioEncoder
\r
89 return this.q_audioEncoder;
\r
93 private int q_videoWidth;
\r
95 /// Returns an Integer
\r
96 /// The selected Width for the encoding.
\r
102 return this.q_videoWidth;
\r
106 private int q_videoHeight;
\r
108 /// Returns an Integer
\r
109 /// The selected Height for the encoding.
\r
115 return this.q_videoHeight;
\r
119 private string q_cropValues;
\r
121 /// Returns an String
\r
122 /// Cropping values.
\r
124 public string CropValues
\r
128 return this.q_cropValues;
\r
132 private Boolean q_detelecine;
\r
134 /// Returns a boolean to indicate wither DeTelecine is on or off
\r
136 public Boolean DeTelecine
\r
140 return this.q_detelecine;
\r
144 private Boolean q_deBlock;
\r
146 /// Returns a boolean to indicate wither DeBlock is on or off.
\r
148 public Boolean DeBlock
\r
152 return this.q_deBlock;
\r
156 private string q_deinterlace;
\r
158 /// Returns a string with the De-Interlace option used.
\r
160 public string DeInterlace
\r
164 return this.q_deinterlace;
\r
168 private string q_denoise;
\r
170 /// Returns a string with the DeNoise option used.
\r
172 public string DeNoise
\r
176 return this.q_denoise;
\r
180 private Boolean q_anamorphic;
\r
182 /// Returns a boolean to indicate wither Anamorphic is on or off.
\r
184 public Boolean Anamorphic
\r
188 return this.q_anamorphic;
\r
192 private Boolean q_chapterMarkers;
\r
194 /// Returns a boolean to indicate wither Chapter Markers is on or off.
\r
196 public Boolean ChapterMarkers
\r
200 return this.q_chapterMarkers;
\r
204 private Boolean q_grayscale;
\r
206 /// Returns a boolean to indicate wither Grayscale is on or off.
\r
208 public Boolean Grayscale
\r
212 return this.q_grayscale;
\r
216 private Boolean q_twoPass;
\r
218 /// Returns a boolean to indicate wither Two Pass Encoding is on or off.
\r
220 public Boolean TwoPass
\r
224 return this.q_twoPass;
\r
228 private Boolean q_turboFirst;
\r
230 /// Returns a boolean to indicate wither Chapter Markers is on or off.
\r
232 public Boolean TurboFirstPass
\r
236 return this.q_turboFirst;
\r
240 private Boolean q_largeMp4;
\r
242 /// Returns a boolean to indicate wither Larger MP4 files is on or off.
\r
244 public Boolean LargeMP4
\r
248 return this.q_largeMp4;
\r
252 private string q_videoFramerate;
\r
254 /// Returns a string with the video Framerate
\r
256 public string VideoFramerate
\r
260 return this.q_videoFramerate;
\r
264 private string q_avgBitrate;
\r
266 /// Returns a string with the average video bitrate
\r
268 public string AverageVideoBitrate
\r
272 return this.q_avgBitrate;
\r
276 private string q_videoTargetSize;
\r
278 /// Returns a string with the video target size
\r
280 public string VideoTargetSize
\r
284 return this.q_videoTargetSize;
\r
288 private int q_videoQuality;
\r
290 /// Returns a int with the video quality value
\r
292 public int VideoQuality
\r
296 return this.q_videoQuality;
\r
300 private Boolean q_crf;
\r
302 /// Returns a boolean to indicate if CRF is on or off.
\r
312 private string q_audioBitrate;
\r
314 /// Returns a string with the audio bitrate
\r
316 public string AudioBitrate
\r
320 return this.q_audioBitrate;
\r
324 private string q_audioSamplerate;
\r
326 /// Returns a string with the audio sample rate
\r
328 public string AudioSampleBitrate
\r
332 return this.q_audioSamplerate;
\r
336 private string q_audioTrack1;
\r
338 /// Returns a string with the First selected Audio track
\r
340 public string AudioTrack1
\r
344 return this.q_audioTrack1;
\r
348 private string q_audioTrackMix;
\r
350 /// Returns a string with the First selected Audio track Mix
\r
352 public string AudioTrackMix
\r
356 return this.q_audioTrackMix;
\r
360 private string q_subtitles;
\r
362 /// Returns a string with the selected subtitle track
\r
364 public string Subtitles
\r
368 return this.q_subtitles;
\r
372 private string q_h264;
\r
374 /// Returns a string with the Advanced H264 query string
\r
376 public string H264Query
\r
380 return this.q_h264;
\r
383 private Boolean q_verbose;
\r
385 /// Returns a string with the Advanced H264 query string
\r
387 public Boolean Verbose
\r
391 return this.q_verbose;
\r
396 // 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
397 public static QueryParser Parse(String input)
\r
399 QueryParser thisQuery = new QueryParser();
\r
402 // -i "C:\Documents and Settings\Scott\Desktop\Files\DVD\Test Image.iso"
\r
403 //-t 1 -c 3-5 -o "C:\test.mp4" -e x264 -E faac -w 720 -l 400 --crop 0:0:0:0
\r
404 //-s 1 --deinterlace="1:-1:1" -g -m -b 2500 -2 -r 25 -T -4 --deblock --detelecine
\r
405 //--denoise=7:7:5:5 -x bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:trellis=2 -B 160 -R 48 -a 1 -6 stereo -v
\r
406 //-q 0.45 -Q -S 2134
\r
410 Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9:\\\s\.]+)(?:\"")");
\r
411 Match source = r1.Match(input.Replace('"', '\"'));
\r
412 Match title = Regex.Match(input, @"-t ([0-9]*)");
\r
413 Match chapters = Regex.Match(input, @"-c ([0-9-]*)");
\r
416 Regex r2 = new Regex(@"(-o)(?:\s\"")([a-zA-Z0-9:\\\s\.]+)(?:\"")");
\r
417 Match destination = r2.Match(input.Replace('"', '\"'));
\r
418 Match width = Regex.Match(input, @"-w ([0-9]*)");
\r
419 Match height = Regex.Match(input, @"-l ([0-9]*)");
\r
420 Match videoEncoder = Regex.Match(input, @"-e ([a-zA-Z0-9]*)");
\r
421 Match audioEncoder = Regex.Match(input, @"-E ([a-zA-Z0-9]*)");
\r
423 //Picture Settings Tab
\r
424 Match deinterlace = Regex.Match(input, @"--deinterlace=([0-9:-]*)"); // DOES NOT WORK. Needs Fixed
\r
425 Match denoise = Regex.Match(input, @"--denoise=([0-9:]*)");
\r
426 Match deblock = Regex.Match(input, @"--deblock");
\r
427 Match detelecine = Regex.Match(input, @"--detelecine");
\r
428 Match anamorphic = Regex.Match(input, @"-p");
\r
429 Match chapterMarkers = Regex.Match(input, @"-m");
\r
430 Match crop = Regex.Match(input, @"--crop ([0-9]):([0-9]):([0-9]):([0-9])");
\r
432 //Video Settings Tab
\r
433 Match videoFramerate = Regex.Match(input, @"-r ([0-9]*)");
\r
434 Match videoBitrate = Regex.Match(input, @"-b ([0-9]*)");
\r
435 Match videoQuality = Regex.Match(input, @"-q ([0-9.]*)");
\r
436 Match videoFilesize = Regex.Match(input, @"-S ([0-9.]*)");
\r
437 Match CRF = Regex.Match(input, @"-Q");
\r
438 Match twoPass = Regex.Match(input, @"-2");
\r
439 Match turboFirstPass = Regex.Match(input, @"-T");
\r
440 Match grayscale = Regex.Match(input, @"-g");
\r
441 Match largerMp4 = Regex.Match(input, @"-4");
\r
443 //Audio Settings Tab
\r
444 Match subtitles = Regex.Match(input, @"-s ([0-9]*)");
\r
445 Match audioBitrate = Regex.Match(input, @"-B ([0-9]*)");
\r
446 Match audioSampleRate = Regex.Match(input, @"-R ([0-9.]*)");
\r
447 Match audioChannelsMix = Regex.Match(input, @"-6 ([a-zA-Z0-9]*)");
\r
448 Match audioChannel = Regex.Match(input, @"-a ([0-9]*)");
\r
451 Match x264 = Regex.Match(input, @"-x ([a-zA-Z0-9=:-]*)");
\r
454 Match verbose = Regex.Match(input, @"-v");
\r
458 // The following code needs alot of error handling added to it at some point.
\r
459 // May be an idea to add additional options such as CPU etc later.
\r
464 thisQuery.q_source = source.ToString();
\r
465 thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", ""));
\r
466 thisQuery.q_dvdChapters = chapters.ToString();
\r
469 thisQuery.q_destination = destination.ToString();
\r
470 thisQuery.q_videoEncoder = videoEncoder.ToString();
\r
471 thisQuery.q_audioEncoder = audioEncoder.ToString();
\r
472 thisQuery.q_videoWidth = int.Parse(width.ToString().Replace("-w ", ""));
\r
473 thisQuery.q_videoHeight = int.Parse(height.ToString().Replace("-l ", ""));
\r
475 //Picture Settings Tab
\r
476 thisQuery.q_cropValues = crop.ToString();
\r
477 thisQuery.q_detelecine = detelecine.Success;
\r
478 thisQuery.q_deBlock = deblock.Success;
\r
479 thisQuery.q_deinterlace = deinterlace.ToString();
\r
480 thisQuery.q_denoise = denoise.ToString();
\r
481 thisQuery.q_anamorphic = anamorphic.Success;
\r
482 thisQuery.q_chapterMarkers = chapterMarkers.Success;
\r
484 //Video Settings Tab
\r
485 thisQuery.q_grayscale = grayscale.Success;
\r
486 thisQuery.q_twoPass = twoPass.Success;
\r
487 thisQuery.q_turboFirst = turboFirstPass.Success;
\r
488 thisQuery.q_largeMp4 = largerMp4.Success;
\r
489 thisQuery.q_videoFramerate = videoFramerate.ToString();
\r
490 thisQuery.q_avgBitrate = videoBitrate.ToString();
\r
491 thisQuery.q_videoTargetSize = videoFilesize.ToString();
\r
492 thisQuery.q_videoQuality = int.Parse(videoQuality.ToString());
\r
493 thisQuery.q_crf = CRF.Success;
\r
495 //Audio Settings Tab
\r
496 thisQuery.q_audioBitrate = audioBitrate.ToString();
\r
497 thisQuery.q_audioSamplerate = audioSampleRate.ToString();
\r
498 thisQuery.q_audioTrack1 = audioChannel.ToString();
\r
499 thisQuery.q_audioTrackMix = audioChannelsMix.ToString();
\r
500 thisQuery.q_subtitles = subtitles.ToString();
\r
503 thisQuery.q_h264 = x264.ToString();
\r
506 thisQuery.q_verbose = verbose.Success;
\r
508 catch (Exception exc)
\r
510 MessageBox.Show(exc.ToString());
\r