2 # manincure.rb version 0.66
4 # This file is part of the HandBrake source code.
5 # Homepage: <http://handbrake.m0k.org/>.
6 # It may be used under the terms of the GNU General Public License.
8 # This script parses HandBrake's Mac presets into hashes, which can
9 # be displayed in various formats for use by the CLI and its wrappers.
11 # For handling command line arguments to the script
15 # CLI options: (code based on http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/index.html )
18 # --[no-]cli-raw, -r gives raw CLI for wiki
19 # --cli-parse, -p gives CLI strings for wrappers
20 # --api, -a gives preset code for test.c
21 # --api-list, -A gives CLI strings for --preset-list display
22 # --[no-]header, -h turns off banner display
23 options = OpenStruct.new
24 options.cliraw = false
25 options.cliparse = false
27 options.apilist = false
28 options.header = false
30 opts = OptionParser.new do |opts|
31 opts.banner = "Usage: manicure.rb [options]"
34 opts.separator "Options:"
36 opts.on("-r", "--cli-raw", "Gives example strings for the HB wiki") do |raw|
41 opts.on("-p", "--cli-parse", "Gives presets as wrapper-parseable CLI", " option strings") do |par|
42 options.cliparse = par
45 opts.on("-a", "--api", "Gives preset code for test.c") do |api|
49 opts.on("-A", "--api-list", "Gives code for test.c's --preset-list", " options") do |alist|
50 options.apilist = alist
53 opts.on("-H", "--Header", "Display a banner before each preset") do |head|
57 opts.on_tail("-h", "--help", "Show this message") do
67 # These arrays contain all the other presets and hashes that are going to be used.
68 # Yeah, they're global variables. In an object-oriented scripting language.
71 # This class parses the user's presets .plist into an array of hashes
74 attr_reader :hashMasterList
76 # Running initialization runs everything.
77 # Calling it will also call the parser
81 # Grab input from the user's presets .plist
82 rawPresets = readPresetPlist
84 # Store all the presets in here
87 # Each item in the array is one line from the .plist
88 presetStew = rawPresets.split("\n")
90 # Now get rid of white space
91 presetStew = cleanStew(presetStew)
93 # This stores the offsets between presets.
94 presetBreaks = findPresetBreaks(presetStew)
96 # Now it's time to use that info to store each
97 # preset individually, in the master list.
98 @presetMasterList = []
100 while i <= presetBreaks.size
101 if i == 0 #first preset
102 # Grab the stew, up to the 1st offset.
103 @presetMasterList[i] = presetStew.slice(0..presetBreaks[i].to_i)
104 elsif i < presetBreaks.size #middle presets
105 # Grab the stew from the last offset to the current..
106 @presetMasterList[i] = presetStew.slice(presetBreaks[i-1].to_i..presetBreaks[i].to_i)
108 # Grab the stew, starting at the last offset, all the way to the end.
109 @presetMasterList[i] = presetStew.slice(presetBreaks[i-1].to_i..presetStew.length)
114 # Parse the presets into hashes
121 def readPresetPlist # Grab the .plist and store it in presets
123 # Grab the user's home path
124 homeLocation = `echo $HOME`.chomp
126 # Use that to build a path to the presets .plist
127 inputFile = homeLocation+'/Library/Application\ Support/HandBrake/UserPresets.plist'
129 # Builds a command that inputs the .plist, but not before stripping all the XML gobbledygook.
130 parseCommand = 'cat '+inputFile+' | sed -e \'s/<[a-z]*>//\' -e \'s/<\/[a-z]*>//\' -e \'/<[?!]/d\' '
134 # Run the command, return the raw presets
135 rawPresets = `#{parseCommand}`
138 def cleanStew(presetStew) #remove tabbed white space
139 presetStew.each do |oneline|
144 def findPresetBreaks(presetStew) #figure out where each preset starts and ends
148 presetStew.each do |presetLine|
149 if presetLine =~ /Audio1Bitrate/ # This is the first line of a new preset.
150 presetBreaks[j] = i-1 # So mark down how long the last one was.
158 def buildPresetHash #fill up @hashMasterList with hashes of all key/value pairs
161 # Iterate through all presets, treating each in turn as singleServing
162 @presetMasterList.each do |singleServing|
164 # Initialize the hash for preset j (aka singleServing)
165 @hashMasterList[j] = Hash.new
167 # Each key and value are on sequential lines.
168 # Iterating through by twos, use that to build a hash.
169 # Each key, on line i, paired with its value, on line i+1
171 while i < singleServing.length
172 @hashMasterList[j].store( singleServing[i], singleServing[i+1] )
182 # This class displays the presets to stdout in various formats.
186 def initialize(hashMasterList, options)
188 @hashMasterList = hashMasterList
191 # A width of 40 gives nice, compact output.
195 displayCommandStrings
199 def displayCommandStrings # prints everything to screen
201 # Iterate through the hashes.
202 @hashMasterList.each do |hash|
204 # Check to make there are valid contents
205 if hash.key?("PresetName")
207 if @options.header == true
208 # First throw up a header to make each preset distinct
212 if @options.cliraw == true
213 # Show the preset's full CLI string equivalent
214 generateCLIString(hash)
217 if @options.cliparse == true
218 generateCLIParse(hash)
221 if @options.api == true
222 # Show the preset as code for test/test.c, HandBrakeCLI
223 generateAPIcalls(hash)
226 if @options.apilist == true
227 # Show the preset as print statements, for CLI wrappers to parse.
228 generateAPIList(hash)
234 def displayHeader(hash) # A distinct banner to separate each preset
236 # Print a line of asterisks
237 puts "*" * @columnWidth
239 # Print the name, centered
240 puts '* '+hash["PresetName"].to_s.center(@columnWidth-4)+' *'
242 # Print a line of dashes
243 puts '~' * @columnWidth
245 # Print the description, centered and word-wrapped
246 puts hash["PresetDescription"].to_s.center(@columnWidth).gsub(/\n/," ").scan(/\S.{0,#{@columnWidth-2}}\S(?=\s|$)|\S+/)
248 # Print another line of dashes
249 puts '~' * @columnWidth
251 # Print the formats the preset uses
252 puts "#{hash["FileCodecs"]}".center(@columnWidth)
254 # Note if the preset isn't built-in
255 if hash["Type"].to_i == 1
256 puts "Custom Preset".center(@columnWidth)
259 # Note if the preset is marked as default.
260 if hash["Default"].to_i == 1
261 puts "This is your default preset.".center(@columnWidth)
264 # End with a line of tildes.
265 puts "~" * @columnWidth
269 def generateCLIString(hash) # Makes a full CLI equivalent of a preset
271 commandString << './HandBrakeCLI -i DVD -o ~/Movies/movie.'
274 case hash["FileFormat"]
276 commandString << "mp4 "
278 commandString << "avi "
280 commandString << "ogm "
282 commandString << "mkv "
286 if hash["VideoEncoder"] != "MPEG-4 (FFmpeg)"
287 commandString << " -e "
288 case hash["VideoEncoder"]
290 commandString << "x264"
292 commandString << "xvid"
297 case hash["VideoQualityType"].to_i
299 commandString << " -S " << hash["VideoTargetSize"]
301 commandString << " -b " << hash["VideoAvgBitrate"]
303 commandString << " -q " << hash["VideoQualitySlider"]
307 if hash["VideoFramerate"] != "Same as source"
308 if hash["VideoFramerate"] == "23.976 (NTSC Film)"
309 commandString << " -r " << "23.976"
310 elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
311 commandString << " -r " << "29.97"
313 commandString << " -r " << hash["VideoFramerate"]
318 commandString << " -a "
319 commandString << hash["Audio1Track"]
320 if hash["Audio2Track"]
321 commandString << "," << hash["Audio2Track"]
323 if hash["Audio3Track"]
324 commandString << "," << hash["Audio3Track"]
326 if hash["Audio4Track"]
327 commandString << "," << hash["Audio4Track"]
331 commandString << " -E "
332 case hash["Audio1Encoder"]
334 commandString << "ac3"
336 commandString << "faac"
338 commandString << "vorbis"
340 commandString << "lame"
342 case hash["Audio2Encoder"]
344 commandString << ",ac3"
346 commandString << ",faac"
348 commandString << ",vorbis"
350 commandString << ",lame"
352 case hash["Audio3Encoder"]
354 commandString << ",ac3"
356 commandString << ",faac"
358 commandString << ",vorbis"
360 commandString << ",lame"
362 case hash["Audio4Encoder"]
364 commandString << ",ac3"
366 commandString << ",faac"
368 commandString << ",vorbis"
370 commandString << ",lame"
374 commandString << " -B "
375 commandString << hash["Audio1Bitrate"]
376 if hash["Audio2Bitrate"]
377 if hash["Audio2Encoder"] != "AC3 Passthru"
378 commandString << "," << hash["Audio2Bitrate"]
380 commandString << "," << "auto"
383 if hash["Audio3Bitrate"]
384 if hash["Audio3Encoder"] != "AC3 Passthru"
385 commandString << "," << hash["Audio3Bitrate"]
387 commandString << "," << "auto"
390 if hash["Audio4Bitrate"]
391 if hash["Audio4Encoder"] != "AC3 Passthru"
392 commandString << "," << hash["Audio4Bitrate"]
394 commandString << "," << "auto"
399 commandString << " -R "
400 commandString << hash["Audio1Samplerate"]
401 if hash["Audio2Samplerate"]
402 commandString << "," << hash["Audio2Samplerate"]
404 if hash["Audio3Samplerate"]
405 commandString << "," << hash["Audio3Samplerate"]
407 if hash["Audio4Samplerate"]
408 commandString << "," << hash["Audio4Samplerate"]
412 commandString << " -6 "
413 case hash["Audio1Mixdown"]
415 commandString << "mono"
417 commandString << "stereo"
418 when /Dolby Surround/
419 commandString << "dpl1"
420 when /Dolby Pro Logic II/
421 commandString << "dpl2"
423 commandString << "6ch"
425 commandString << "auto"
428 if hash["Audio2Mixdown"]
429 case hash["Audio2Mixdown"]
431 commandString << ",mono"
433 commandString << ",stereo"
434 when /Dolby Surround/
435 commandString << ",dpl1"
436 when /Dolby Pro Logic II/
437 commandString << ",dpl2"
439 commandString << ",6ch"
441 commandString << ",auto"
445 if hash["Audio3Mixdown"]
446 case hash["Audio3Mixdown"]
448 commandString << ",mono"
450 commandString << ",stereo"
451 when /Dolby Surround/
452 commandString << ",dpl1"
453 when /Dolby Pro Logic II/
454 commandString << ",dpl2"
456 commandString << ",6ch"
458 commandString << ",auto"
462 if hash["Audio4Mixdown"]
463 case hash["Audio4Mixdown"]
465 commandString << ",mono"
467 commandString << ",stereo"
468 when /Dolby Surround/
469 commandString << ",dpl1"
470 when /Dolby Pro Logic II/
471 commandString << ",dpl2"
473 commandString << ",6ch"
475 commandString << ",auto"
480 commandString << " -f "
481 case hash["FileFormat"]
483 commandString << "mp4"
485 commandString << "avi"
487 commandString << "ogm"
489 commandString << "mkv"
493 if hash["Mp4iPodCompatible"].to_i == 1
494 commandString << " -I"
498 if hash["Mp4LargeFile"].to_i == 1
499 commandString << " -4"
503 if !hash["PictureAutoCrop"].to_i
504 commandString << " --crop "
505 commandString << hash["PictureTopCrop"]
507 commandString << hash["PictureBottomCrop"]
509 commandString << hash["PictureLeftCrop"]
511 commandString << hash["PictureRightCrop"]
515 if hash["PictureWidth"].to_i != 0
516 commandString << " -w "
517 commandString << hash["PictureWidth"]
519 if hash["PictureHeight"].to_i != 0
520 commandString << " -l "
521 commandString << hash["PictureHeight"]
525 if hash["Subtitles"] != "None"
526 commandString << " -s "
527 commandString << hash["Subtitles"]
531 if hash["UsesPictureFilters"].to_i == 1
533 case hash["PictureDeinterlace"].to_i
535 commandString << " --deinterlace=\"fast\""
537 commandString << " --deinterlace=\slow\""
539 commandString << " --deinterlace=\"slower\""
541 commandString << " --deinterlace=\"slowest\""
544 case hash["PictureDenoise"].to_i
546 commandString << " --denoise=\"weak\""
548 commandString << " --denoise=\"medium\""
550 commandString << " --denoise=\"strong\""
553 if hash["PictureDetelecine"].to_i == 1 then commandString << " --detelecine" end
554 if hash["PictureDeblock"].to_i == 1 then commandString << " --deblock" end
555 if hash["VFR"].to_i == 1 then commandString << " --vfr" end
559 if hash["ChapterMarkers"].to_i == 1 then commandString << " -m" end
560 if hash["PicturePAR"].to_i == 1 then commandString << " -p" end
561 if hash["VideoGrayScale"].to_i == 1 then commandString << " -g" end
562 if hash["VideoTwoPass"].to_i == 1 then commandString << " -2" end
563 if hash["VideoTurboTwoPass"].to_i == 1 then commandString << " -T" end
566 if hash["x264Option"] != ""
567 commandString << " -x "
568 commandString << hash["x264Option"]
571 # That's it, print to screen now
574 #puts "*" * @columnWidth
579 def generateCLIParse(hash) # Makes a CLI equivalent of all user presets, for wrappers to parse
581 commandString << '+ ' << hash["PresetName"] << ":"
584 if hash["VideoEncoder"] != "MPEG-4 (FFmpeg)"
585 commandString << " -e "
586 case hash["VideoEncoder"]
588 commandString << "x264"
590 commandString << "xvid"
595 case hash["VideoQualityType"].to_i
597 commandString << " -S " << hash["VideoTargetSize"]
599 commandString << " -b " << hash["VideoAvgBitrate"]
601 commandString << " -q " << hash["VideoQualitySlider"]
605 if hash["VideoFramerate"] != "Same as source"
606 if hash["VideoFramerate"] == "23.976 (NTSC Film)"
607 commandString << " -r " << "23.976"
608 elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
609 commandString << " -r " << "29.97"
611 commandString << " -r " << hash["VideoFramerate"]
616 commandString << " -a "
617 commandString << hash["Audio1Track"]
618 if hash["Audio2Track"]
619 commandString << "," << hash["Audio2Track"]
621 if hash["Audio3Track"]
622 commandString << "," << hash["Audio3Track"]
624 if hash["Audio4Track"]
625 commandString << "," << hash["Audio4Track"]
629 commandString << " -E "
630 case hash["Audio1Encoder"]
632 commandString << "ac3"
634 commandString << "faac"
636 commandString << "vorbis"
638 commandString << "lame"
640 case hash["Audio2Encoder"]
642 commandString << ",ac3"
644 commandString << ",faac"
646 commandString << ",vorbis"
648 commandString << ",lame"
650 case hash["Audio3Encoder"]
652 commandString << ",ac3"
654 commandString << ",faac"
656 commandString << ",vorbis"
658 commandString << ",lame"
660 case hash["Audio4Encoder"]
662 commandString << ",ac3"
664 commandString << ",faac"
666 commandString << ",vorbis"
668 commandString << ",lame"
672 commandString << " -B "
673 commandString << hash["Audio1Bitrate"]
674 if hash["Audio2Bitrate"]
675 if hash["Audio2Encoder"] != "AC3 Passthru"
676 commandString << "," << hash["Audio2Bitrate"]
678 commandString << "," << "auto"
681 if hash["Audio3Bitrate"]
682 if hash["Audio3Encoder"] != "AC3 Passthru"
683 commandString << "," << hash["Audio3Bitrate"]
685 commandString << "," << "auto"
688 if hash["Audio4Bitrate"]
689 if hash["Audio4Encoder"] != "AC3 Passthru"
690 commandString << "," << hash["Audio4Bitrate"]
692 commandString << "," << "auto"
697 commandString << " -R "
698 commandString << hash["Audio1Samplerate"]
699 if hash["Audio2Samplerate"]
700 commandString << "," << hash["Audio2Samplerate"]
702 if hash["Audio3Samplerate"]
703 commandString << "," << hash["Audio3Samplerate"]
705 if hash["Audio4Samplerate"]
706 commandString << "," << hash["Audio4Samplerate"]
710 commandString << " -6 "
711 case hash["Audio1Mixdown"]
713 commandString << "mono"
715 commandString << "stereo"
716 when /Dolby Surround/
717 commandString << "dpl1"
718 when /Dolby Pro Logic II/
719 commandString << "dpl2"
721 commandString << "6ch"
723 commandString << "auto"
726 if hash["Audio2Mixdown"]
727 case hash["Audio2Mixdown"]
729 commandString << ",mono"
731 commandString << ",stereo"
732 when /Dolby Surround/
733 commandString << ",dpl1"
734 when /Dolby Pro Logic II/
735 commandString << ",dpl2"
737 commandString << ",6ch"
739 commandString << ",auto"
743 if hash["Audio3Mixdown"]
744 case hash["Audio3Mixdown"]
746 commandString << ",mono"
748 commandString << ",stereo"
749 when /Dolby Surround/
750 commandString << ",dpl1"
751 when /Dolby Pro Logic II/
752 commandString << ",dpl2"
754 commandString << ",6ch"
756 commandString << ",auto"
760 if hash["Audio4Mixdown"]
761 case hash["Audio4Mixdown"]
763 commandString << ",mono"
765 commandString << ",stereo"
766 when /Dolby Surround/
767 commandString << ",dpl1"
768 when /Dolby Pro Logic II/
769 commandString << ",dpl2"
771 commandString << ",6ch"
773 commandString << ",auto"
779 commandString << " -f "
780 case hash["FileFormat"]
782 commandString << "mp4"
784 commandString << "avi"
786 commandString << "ogm"
788 commandString << "mkv"
792 if hash["Mp4iPodCompatible"].to_i == 1
793 commandString << " -I"
797 if hash["Mp4LargeFile"].to_i == 1
798 commandString << " -4"
802 if !hash["PictureAutoCrop"].to_i
803 commandString << " --crop "
804 commandString << hash["PictureTopCrop"]
806 commandString << hash["PictureBottomCrop"]
808 commandString << hash["PictureLeftCrop"]
810 commandString << hash["PictureRightCrop"]
814 if hash["PictureWidth"].to_i != 0
815 commandString << " -w "
816 commandString << hash["PictureWidth"]
818 if hash["PictureHeight"].to_i != 0
819 commandString << " -l "
820 commandString << hash["PictureHeight"]
824 if hash["Subtitles"] != "None"
825 commandString << " -s "
826 commandString << hash["Subtitles"]
830 if hash["UsesPictureFilters"].to_i == 1
832 case hash["PictureDeinterlace"].to_i
834 commandString << " --deinterlace=\"fast\""
836 commandString << " --deinterlace=\slow\""
838 commandString << " --deinterlace=\"slower\""
840 commandString << " --deinterlace=\"slowest\""
843 case hash["PictureDenoise"].to_i
845 commandString << " --denoise=\"weak\""
847 commandString << " --denoise=\"medium\""
849 commandString << " --denoise=\"strong\""
852 if hash["PictureDetelecine"].to_i == 1 then commandString << " --detelecine" end
853 if hash["PictureDeblock"].to_i == 1 then commandString << " --deblock" end
854 if hash["VFR"].to_i == 1 then commandString << " --vfr" end
858 if hash["ChapterMarkers"].to_i == 1 then commandString << " -m" end
859 if hash["PicturePAR"].to_i == 1 then commandString << " -p" end
860 if hash["VideoGrayScale"].to_i == 1 then commandString << " -g" end
861 if hash["VideoTwoPass"].to_i == 1 then commandString << " -2" end
862 if hash["VideoTurboTwoPass"].to_i == 1 then commandString << " -T" end
865 if hash["x264Option"] != ""
866 commandString << " -x "
867 commandString << hash["x264Option"]
870 # That's it, print to screen now
873 #puts "*" * @columnWidth
878 def generateAPIcalls(hash) # Makes a C version of the preset ready for coding into the CLI
880 commandString = "if (!strcmp(preset_name, \"" << hash["PresetName"] << "\"))\n{\n "
883 case hash["FileFormat"]
885 commandString << "mux = " << "HB_MUX_MP4;\n "
887 commandString << "mux = " << "HB_MUX_AVI;\n "
889 commandString << "mux = " << "HB_MUX_OGM;\n "
891 commandString << "mux = " << "HB_MUX_MKV;\n "
895 if hash["Mp4iPodCompatible"].to_i == 1
896 commandString << "job->ipod_atom = 1;\n "
900 if hash["Mp4LargeFile"].to_i == 1
901 commandString << "job->largeFileSize = 1;\n"
905 if hash["VideoEncoder"] != "MPEG-4 (FFmpeg)"
906 commandString << "vcodec = "
907 case hash["VideoEncoder"]
909 commandString << "HB_VCODEC_X264;\n "
911 commandString << "HB_VCODEC_XVID;\n "
916 case hash["VideoQualityType"].to_i
918 commandString << "size = " << hash["VideoTargetSize"] << ";\n "
920 commandString << "job->vbitrate = " << hash["VideoAvgBitrate"] << ";\n "
922 commandString << "job->vquality = " << hash["VideoQualitySlider"] << ";\n "
923 commandString << "job->crf = 1;\n "
927 if hash["VideoFramerate"] != "Same as source"
928 if hash["VideoFramerate"] == "23.976 (NTSC Film)"
929 commandString << "job->vrate_base = " << "1126125;\n "
930 elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
931 commandString << "job->vrate_base = " << "900900;\n "
932 # Gotta add the rest of the framerates for completion's sake.
934 commandString << "job->cfr = 1;\n "
938 commandString << "atracks = \""
939 commandString << hash["Audio1Track"]
940 if hash["Audio2Track"]
941 commandString << "," << hash["Audio2Track"]
943 if hash["Audio3Track"]
944 commandString << "," << hash["Audio3Track"]
946 if hash["Audio4Track"]
947 commandString << "," << hash["Audio4Track"]
949 commandString << "\";\n "
952 commandString << "abitrates = \""
953 if hash["Audio1Encoder"] != "AC3 Passthru"
954 commandString << hash["Audio1Bitrate"]
956 commandString << "auto"
958 if hash["Audio2Bitrate"]
959 if hash["Audio2Encoder"] != "AC3 Passthru"
960 commandString << "," << hash["Audio2Bitrate"]
962 commandString << "," << "auto"
965 if hash["Audio3Bitrate"]
966 if hash["Audio3Encoder"] != "AC3 Passthru"
967 commandString << "," << hash["Audio3Bitrate"]
969 commandString << "," << "auto"
972 if hash["Audio4Bitrate"]
973 if hash["Audio4Encoder"] != "AC3 Passthru"
974 commandString << "," << hash["Audio4Bitrate"]
976 commandString << "," << "auto"
979 commandString << "\";\n "
982 commandString << "arates = \""
983 commandString << hash["Audio1Samplerate"]
984 if hash["Audio2Samplerate"]
985 commandString << "," << hash["Audio2Samplerate"]
987 if hash["Audio3Samplerate"]
988 commandString << "," << hash["Audio3Samplerate"]
990 if hash["Audio4Samplerate"]
991 commandString << "," << hash["Audio4Samplerate"]
993 commandString << "\";\n "
996 commandString << "acodecs = \""
997 case hash["Audio1Encoder"]
999 commandString << "ac3"
1001 commandString << "faac"
1003 commandString << "vorbis"
1005 commandString << "lame"
1007 case hash["Audio2Encoder"]
1009 commandString << ",ac3"
1011 commandString << ",faac"
1013 commandString << ",vorbis"
1015 commandString << ",lame"
1017 case hash["Audio3Encoder"]
1019 commandString << ",ac3"
1021 commandString << ",faac"
1023 commandString << ",vorbis"
1025 commandString << ",lame"
1027 case hash["Audio4Encoder"]
1029 commandString << ",ac3"
1031 commandString << ",faac"
1033 commandString << ",vorbis"
1035 commandString << ",lame"
1037 commandString << "\";\n "
1040 commandString << "mixdowns = \""
1041 case hash["Audio1Mixdown"]
1043 commandString << "mono"
1045 commandString << "stereo"
1046 when /Dolby Surround/
1047 commandString << "dpl1"
1048 when /Dolby Pro Logic II/
1049 commandString << "dpl2"
1051 commandString << "6ch"
1053 commandString << "auto"
1055 if hash["Audio2Mixdown"]
1056 case hash["Audio2Mixdown"]
1058 commandString << ",mono"
1060 commandString << ",stereo"
1061 when /Dolby Surround/
1062 commandString << ",dpl1"
1063 when /Dolby Pro Logic II/
1064 commandString << ",dpl2"
1066 commandString << ",6ch"
1068 commandString << ",auto"
1071 if hash["Audio3Mixdown"]
1072 case hash["Audio3Mixdown"]
1074 commandString << ",mono"
1076 commandString << ",stereo"
1077 when /Dolby Surround/
1078 commandString << ",dpl1"
1079 when /Dolby Pro Logic II/
1080 commandString << ",dpl2"
1082 commandString << ",6ch"
1084 commandString << ",auto"
1087 if hash["Audio4Mixdown"]
1088 case hash["Audio4Mixdown"]
1090 commandString << ",mono"
1092 commandString << ",stereo"
1093 when /Dolby Surround/
1094 commandString << ",dpl1"
1095 when /Dolby Pro Logic II/
1096 commandString << ",dpl2"
1098 commandString << ",6ch"
1100 commandString << ",auto"
1103 commandString << "\";\n "
1106 if !hash["PictureAutoCrop"].to_i
1107 commandString << "job->crop[0] = " << hash["PictureTopCrop"] << ";\n "
1108 commandString << "job->crop[1] = " << hash["PictureBottomCrop"] << ";\n "
1109 commandString << "job->crop[2] = " << hash["PictureLeftCrop"] << ";\n "
1110 commandString << "job->crop[4] - " << hash["PictureRightCrop"] << ";\n "
1114 if hash["PictureWidth"].to_i != 0
1115 commandString << "job->width = "
1116 commandString << hash["PictureWidth"] << ";\n "
1118 if hash["PictureHeight"].to_i != 0
1119 commandString << "job->height = "
1120 commandString << hash["PictureHeight"] << ";\n "
1124 if hash["Subtitles"] != "None"
1125 commandString << "job->subtitle = "
1126 commandString << ( hash["Subtitles"].to_i - 1).to_s << ";\n "
1130 if hash["x264Option"] != ""
1131 commandString << "x264opts = strdup(\""
1132 commandString << hash["x264Option"] << "\");\n "
1136 if hash["UsesPictureFilters"].to_i == 1
1138 case hash["PictureDeinterlace"].to_i
1140 commandString << "deinterlace = 1;\n "
1141 commandString << "deinterlace_opt = \"-1\";\n "
1143 commandString << "deinterlace = 1;\n "
1144 commandString << "deinterlace_opt = \"2\";\n "
1146 commandString << "deinterlace = 1;\n "
1147 commandString << "deinterlace_opt = \"0\";\n "
1149 commandString << "deinterlace = 1;\n "
1150 commandString << "deinterlace_opt = \"1:-1:1\";\n "
1153 case hash["PictureDenoise"].to_i
1155 commandString << "denoise = 1;\n "
1156 commandString << "denoise_opt = \"2:1:2:3\";\n "
1158 commandString << "denoise = 1;\n "
1159 commandString << "denoise_opt = \"3:2:2:3\";\n "
1161 commandString << "denoise = 1;\n "
1162 commandString << "denoise_opt = \"7:7:5:5\";\n "
1165 if hash["PictureDetelecine"].to_i == 1 then commandString << "detelecine = 1;\n " end
1166 if hash["PictureDeblock"].to_i == 1 then commandString << "deblock = 1;\n " end
1167 if hash["VFR"].to_i == 1 then commandString << "vfr = 1;\n " end
1171 if hash["ChapterMarkers"].to_i == 1 then commandString << "job->chapter_markers = 1;\n " end
1172 if hash["PicturePAR"].to_i == 1 then commandString << "pixelratio = 1;\n " end
1173 if hash["VideoGrayScale"].to_i == 1 then commandString << "job->grayscale = 1;\n " end
1174 if hash["VideoTwoPass"].to_i == 1 then commandString << "twoPass = 1;\n " end
1175 if hash["VideoTurboTwoPass"].to_i == 1 then commandString << "turbo_opts_enabled = 1;\n" end
1177 commandString << "}"
1179 # That's it, print to screen now
1181 #puts "*" * @columnWidth
1185 def generateAPIList(hash) # Makes a list of the CLI options a built-in CLI preset uses, for wrappers to parse
1187 commandString << " printf(\"\\n+ " << hash["PresetName"] << ": "
1190 if hash["VideoEncoder"] != "MPEG-4 (FFmpeg)"
1191 commandString << " -e "
1192 case hash["VideoEncoder"]
1194 commandString << "x264 "
1196 commandString << "xvid "
1201 case hash["VideoQualityType"].to_i
1203 commandString << " -S " << hash["VideoTargetSize"]
1205 commandString << " -b " << hash["VideoAvgBitrate"]
1207 commandString << " -q " << hash["VideoQualitySlider"]
1211 if hash["VideoFramerate"] != "Same as source"
1212 if hash["VideoFramerate"] == "23.976 (NTSC Film)"
1213 commandString << " -r " << "23.976"
1214 elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
1215 commandString << " -r " << "29.97"
1217 commandString << " -r " << hash["VideoFramerate"]
1222 commandString << " -a "
1223 commandString << hash["Audio1Track"]
1224 if hash["Audio2Track"]
1225 commandString << "," << hash["Audio2Track"]
1227 if hash["Audio3Track"]
1228 commandString << "," << hash["Audio3Track"]
1230 if hash["Audio4Track"]
1231 commandString << "," << hash["Audio4Track"]
1235 commandString << " -E "
1236 case hash["Audio1Encoder"]
1238 commandString << "ac3"
1240 commandString << "faac"
1242 commandString << "vorbis"
1244 commandString << "lame"
1246 case hash["Audio2Encoder"]
1248 commandString << ",ac3"
1250 commandString << ",faac"
1252 commandString << ",vorbis"
1254 commandString << ",lame"
1256 case hash["Audio3Encoder"]
1258 commandString << ",ac3"
1260 commandString << ",faac"
1262 commandString << ",vorbis"
1264 commandString << ",lame"
1266 case hash["Audio4Encoder"]
1268 commandString << ",ac3"
1270 commandString << ",faac"
1272 commandString << ",vorbis"
1274 commandString << ",lame"
1278 commandString << " -B "
1279 commandString << hash["Audio1Bitrate"]
1280 if hash["Audio2Bitrate"]
1281 if hash["Audio2Encoder"] != "AC3 Passthru"
1282 commandString << "," << hash["Audio2Bitrate"]
1284 commandString << "," << "auto"
1287 if hash["Audio3Bitrate"]
1288 if hash["Audio3Encoder"] != "AC3 Passthru"
1289 commandString << "," << hash["Audio3Bitrate"]
1291 commandString << "," << "auto"
1294 if hash["Audio4Bitrate"]
1295 if hash["Audio4Encoder"] != "AC3 Passthru"
1296 commandString << "," << hash["Audio4Bitrate"]
1298 commandString << "," << "auto"
1303 commandString << " -R "
1304 commandString << hash["Audio1Samplerate"]
1305 if hash["Audio2Samplerate"]
1306 commandString << "," << hash["Audio2Samplerate"]
1308 if hash["Audio3Samplerate"]
1309 commandString << "," << hash["Audio3Samplerate"]
1311 if hash["Audio4Samplerate"]
1312 commandString << "," << hash["Audio4Samplerate"]
1316 commandString << " -6 "
1317 case hash["Audio1Mixdown"]
1319 commandString << "mono"
1321 commandString << "stereo"
1322 when /Dolby Surround/
1323 commandString << "dpl1"
1324 when /Dolby Pro Logic II/
1325 commandString << "dpl2"
1327 commandString << "6ch"
1329 commandString << "auto"
1332 if hash["Audio2Mixdown"]
1333 case hash["Audio2Mixdown"]
1335 commandString << ",mono"
1337 commandString << ",stereo"
1338 when /Dolby Surround/
1339 commandString << ",dpl1"
1340 when /Dolby Pro Logic II/
1341 commandString << ",dpl2"
1343 commandString << ",6ch"
1345 commandString << ",auto"
1349 if hash["Audio3Mixdown"]
1350 case hash["Audio3Mixdown"]
1352 commandString << ",mono"
1354 commandString << ",stereo"
1355 when /Dolby Surround/
1356 commandString << ",dpl1"
1357 when /Dolby Pro Logic II/
1358 commandString << ",dpl2"
1360 commandString << ",6ch"
1362 commandString << ",auto"
1366 if hash["Audio4Mixdown"]
1367 case hash["Audio4Mixdown"]
1369 commandString << ",mono"
1371 commandString << ",stereo"
1372 when /Dolby Surround/
1373 commandString << ",dpl1"
1374 when /Dolby Pro Logic II/
1375 commandString << ",dpl2"
1377 commandString << ",6ch"
1379 commandString << ",auto"
1384 commandString << " -f "
1385 case hash["FileFormat"]
1387 commandString << "mp4"
1389 commandString << "avi"
1391 commandString << "ogm"
1393 commandString << "mkv"
1397 if hash["Mp4iPodCompatible"].to_i == 1
1398 commandString << " -I"
1402 if hash["Mp4LargeFile"].to_i == 1
1403 commandString << " -4"
1407 if !hash["PictureAutoCrop"].to_i
1408 commandString << " --crop "
1409 commandString << hash["PictureTopCrop"]
1410 commandString << ":"
1411 commandString << hash["PictureBottomCrop"]
1412 commandString << ":"
1413 commandString << hash["PictureLeftCrop"]
1414 commandString << ":"
1415 commandString << hash["PictureRightCrop"]
1419 if hash["PictureWidth"].to_i != 0
1420 commandString << " -w "
1421 commandString << hash["PictureWidth"]
1423 if hash["PictureHeight"].to_i != 0
1424 commandString << " -l "
1425 commandString << hash["PictureHeight"]
1429 if hash["Subtitles"] != "None"
1430 commandString << " -s "
1431 commandString << hash["Subtitles"]
1435 if hash["UsesPictureFilters"].to_i == 1
1437 case hash["PictureDeinterlace"].to_i
1439 commandString << " --deinterlace=\\\"fast\\\""
1441 commandString << " --deinterlace=\\\slow\\\""
1443 commandString << " --deinterlace=\\\"slower\\\""
1445 commandString << " --deinterlace=\\\"slowest\\\""
1448 case hash["PictureDenoise"].to_i
1450 commandString << " --denoise=\\\"weak\\\""
1452 commandString << " --denoise=\\\"medium\\\""
1454 commandString << " --denoise=\\\"strong\\\""
1457 if hash["PictureDetelecine"].to_i == 1 then commandString << " --detelecine" end
1458 if hash["PictureDeblock"].to_i == 1 then commandString << " --deblock" end
1459 if hash["VFR"].to_i == 1 then commandString << " --vfr" end
1463 if hash["ChapterMarkers"].to_i == 1 then commandString << " -m" end
1464 if hash["PicturePAR"].to_i == 1 then commandString << " -p" end
1465 if hash["VideoGrayScale"].to_i == 1 then commandString << " -g" end
1466 if hash["VideoTwoPass"].to_i == 1 then commandString << " -2" end
1467 if hash["VideoTurboTwoPass"].to_i == 1 then commandString << " -T" end
1470 if hash["x264Option"] != ""
1471 commandString << " -x "
1472 commandString << hash["x264Option"]
1475 commandString << "\\n\");"
1477 # That's it, print to screen now
1484 # First grab the specified CLI options
1485 options = readOptions
1487 # Only run if one of the useful CLI flags have been passed
1488 if options.cliraw == true || options.cliparse == true || options.api == true || options.apilist == true
1489 # This line is the ignition -- generates hashes of
1490 # presets and then displays them to the screen
1491 # with the options the user selects on the CLI.
1492 Display.new( Presets.new.hashMasterList, options )
1494 # Direct the user to the help
1495 puts "\n\tUsage: manicure.rb [options]"
1496 puts "\tSee help with -h or --help"