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
17 # CLI options: (code based on http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/index.html )
20 # --[no-]cli-raw, -r gives raw CLI for wiki
21 # --cli-parse, -p gives CLI strings for wrappers
22 # --api, -a gives preset code for test.c
23 # --api-list, -A gives CLI strings for --preset-list display
24 # --[no-]header, -h turns off banner display
25 options = OpenStruct.new
26 options.cliraw = false
27 options.cliparse = false
29 options.apilist = false
30 options.header = false
32 opts = OptionParser.new do |opts|
33 opts.banner = "Usage: manicure.rb [options]"
36 opts.separator "Options:"
38 opts.on("-r", "--cli-raw", "Gives example strings for the HB wiki") do |raw|
43 opts.on("-p", "--cli-parse", "Gives presets as wrapper-parseable CLI", " option strings") do |par|
44 options.cliparse = par
47 opts.on("-a", "--api", "Gives preset code for test.c") do |api|
51 opts.on("-A", "--api-list", "Gives code for test.c's --preset-list", " options") do |alist|
52 options.apilist = alist
55 opts.on("-H", "--Header", "Display a banner before each preset") do |head|
59 opts.on_tail("-h", "--help", "Show this message") do
69 # These arrays contain all the other presets and hashes that are going to be used.
70 # Yeah, they're global variables. In an object-oriented scripting language.
73 # This class parses the user's presets .plist into an array of hashes
76 attr_reader :hashMasterList
78 # Running initialization runs everything.
79 # Calling it will also call the parser
83 # Grab the user's home path
84 homeLocation = `echo $HOME`.chomp
86 # Use that to build a path to the presets .plist
87 inputFile = homeLocation+'/Library/Application Support/HandBrake/UserPresets.plist'
89 # Parse the presets into hashes
90 @hashMasterList = Plist::parse_xml( inputFile )
96 # This class displays the presets to stdout in various formats.
99 def initialize(hashMasterList, options)
101 @hashMasterList = hashMasterList
104 # A width of 40 gives nice, compact output.
108 displayCommandStrings
112 def displayCommandStrings # prints everything to screen
114 # Iterate through the hashes.
115 @hashMasterList.each do |hash|
117 # Check to see whether we've got a preset or afolder
119 # It's a top-level preset
120 displayIndividualPreset(hash, 0)
123 displayFolder( hash, 0 )
124 hash["ChildrenArray"].each do |subhash|
125 # Drill down to see its contents
126 if !subhash["Folder"]
128 displayIndividualPreset(subhash, 1)
131 displayFolder( subhash, 1 )
132 subhash["ChildrenArray"].each do |subsubhash|
133 # At this point we're far enough down we won't try to drill further
134 if !subsubhash["Folder"]
135 displayIndividualPreset(subsubhash, 2)
138 displayFolderCloser( 1 )
141 displayFolderCloser( 0 )
146 def displayIndividualPreset(hash, depth)
147 if @options.header == true
148 # First throw up a header to make each preset distinct
152 if @options.cliraw == true
153 # Show the preset's full CLI string equivalent
154 generateCLIString(hash, depth)
157 if @options.cliparse == true
158 generateCLIParse(hash, depth)
161 if @options.api == true
162 # Show the preset as code for test/test.c, HandBrakeCLI
163 generateAPIcalls(hash)
166 if @options.apilist == true
167 # Show the preset as print statements, for CLI wrappers to parse.
168 generateAPIList(hash, depth)
172 def displayHeader(hash) # A distinct banner to separate each preset
174 # Print a line of asterisks
175 puts "*" * @columnWidth
177 # Print the name, centered
178 puts '* '+hash["PresetName"].to_s.center(@columnWidth-4)+' *'
180 # Print a line of dashes
181 puts '~' * @columnWidth
183 # Print the description, centered and word-wrapped
184 puts hash["PresetDescription"].to_s.center(@columnWidth).gsub(/\n/," ").scan(/\S.{0,#{@columnWidth-2}}\S(?=\s|$)|\S+/)
186 # Print another line of dashes
187 puts '~' * @columnWidth
189 # Print the formats the preset uses
190 puts "#{hash["FileCodecs"]}".center(@columnWidth)
192 # Note if the preset isn't built-in
194 puts "Custom Preset".center(@columnWidth)
197 # Note if the preset is marked as default.
198 if hash["Default"] == 1
199 puts "This is your default preset.".center(@columnWidth)
202 # End with a line of tildes.
203 puts "~" * @columnWidth
207 def displayFolder( hash, depth )
209 if @options.cliraw == true
210 # Show the folder's full in a format that matches the CLI equivalents
211 generateCLIFolderString(hash, depth)
214 if @options.cliparse == true
215 # Show the folder in a format that matches the CLI wrapper equivalents
216 generateCLIFolderParse(hash, depth)
219 if @options.apilist == true
220 # Show the folder as print statements, for CLI wrappers to parse.
221 generateAPIFolderList(hash, depth)
226 def displayFolderCloser( depth )
227 if @options.cliraw == true
228 # Show the folder's full in a format that matches the CLI equivalents
229 generateCLIFolderCloserString( depth )
232 if @options.cliparse == true
233 # Show the folder in a format that matches the CLI wrapper equivalents
234 generateCLIFolderCloserParse( depth )
237 if @options.apilist == true
238 # Show the folder as print statements, for CLI wrappers to parse.
239 generateAPIFolderCloserList( depth )
243 def generateCLIFolderString( hash, depth ) # Shows the folder for the CLI equivalents
251 commandString << " " << hash["PresetName"] << "\n\n"
255 def generateCLIFolderCloserString( depth )
263 commandString << "\n\n"
267 def generateCLIString(hash, depth) # Makes a full CLI equivalent of a preset
272 commandString << './HandBrakeCLI -i DVD -o ~/Movies/movie.'
275 case hash["FileFormat"]
277 commandString << "mp4 "
279 commandString << "avi "
281 commandString << "ogm "
283 commandString << "mkv "
287 if hash["VideoEncoder"] != "MPEG-4 (FFmpeg)"
288 commandString << " -e "
289 case hash["VideoEncoder"]
291 commandString << "x264"
293 commandString << "xvid"
298 case hash["VideoQualityType"]
300 commandString << " -S " << hash["VideoTargetSize"]
302 commandString << " -b " << hash["VideoAvgBitrate"]
304 commandString << " -q " << hash["VideoQualitySlider"].to_s
308 if hash["VideoFramerate"] != "Same as source"
309 if hash["VideoFramerate"] == "23.976 (NTSC Film)"
310 commandString << " -r " << "23.976"
311 elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
312 commandString << " -r " << "29.97"
314 commandString << " -r " << hash["VideoFramerate"]
319 commandString << " -a "
320 commandString << hash["Audio1Track"].to_s
321 if hash["Audio2Track"]
322 commandString << "," << hash["Audio2Track"].to_s
324 if hash["Audio3Track"]
325 commandString << "," << hash["Audio3Track"].to_s
327 if hash["Audio4Track"]
328 commandString << "," << hash["Audio4Track"].to_s
332 commandString << " -E "
333 case hash["Audio1Encoder"]
335 commandString << "ac3"
337 commandString << "faac"
339 commandString << "vorbis"
341 commandString << "lame"
343 case hash["Audio2Encoder"]
345 commandString << ",ac3"
347 commandString << ",faac"
349 commandString << ",vorbis"
351 commandString << ",lame"
353 case hash["Audio3Encoder"]
355 commandString << ",ac3"
357 commandString << ",faac"
359 commandString << ",vorbis"
361 commandString << ",lame"
363 case hash["Audio4Encoder"]
365 commandString << ",ac3"
367 commandString << ",faac"
369 commandString << ",vorbis"
371 commandString << ",lame"
375 commandString << " -B "
376 commandString << hash["Audio1Bitrate"]
377 if hash["Audio2Bitrate"]
378 if hash["Audio2Encoder"] != "AC3 Passthru"
379 commandString << "," << hash["Audio2Bitrate"]
381 commandString << "," << "auto"
384 if hash["Audio3Bitrate"]
385 if hash["Audio3Encoder"] != "AC3 Passthru"
386 commandString << "," << hash["Audio3Bitrate"]
388 commandString << "," << "auto"
391 if hash["Audio4Bitrate"]
392 if hash["Audio4Encoder"] != "AC3 Passthru"
393 commandString << "," << hash["Audio4Bitrate"]
395 commandString << "," << "auto"
400 commandString << " -R "
401 commandString << hash["Audio1Samplerate"]
402 if hash["Audio2Samplerate"]
403 commandString << "," << hash["Audio2Samplerate"]
405 if hash["Audio3Samplerate"]
406 commandString << "," << hash["Audio3Samplerate"]
408 if hash["Audio4Samplerate"]
409 commandString << "," << hash["Audio4Samplerate"]
413 commandString << " -6 "
414 case hash["Audio1Mixdown"]
416 commandString << "mono"
418 commandString << "stereo"
419 when /Dolby Surround/
420 commandString << "dpl1"
421 when /Dolby Pro Logic II/
422 commandString << "dpl2"
424 commandString << "6ch"
426 commandString << "auto"
429 if hash["Audio2Mixdown"]
430 case hash["Audio2Mixdown"]
432 commandString << ",mono"
434 commandString << ",stereo"
435 when /Dolby Surround/
436 commandString << ",dpl1"
437 when /Dolby Pro Logic II/
438 commandString << ",dpl2"
440 commandString << ",6ch"
442 commandString << ",auto"
446 if hash["Audio3Mixdown"]
447 case hash["Audio3Mixdown"]
449 commandString << ",mono"
451 commandString << ",stereo"
452 when /Dolby Surround/
453 commandString << ",dpl1"
454 when /Dolby Pro Logic II/
455 commandString << ",dpl2"
457 commandString << ",6ch"
459 commandString << ",auto"
463 if hash["Audio4Mixdown"]
464 case hash["Audio4Mixdown"]
466 commandString << ",mono"
468 commandString << ",stereo"
469 when /Dolby Surround/
470 commandString << ",dpl1"
471 when /Dolby Pro Logic II/
472 commandString << ",dpl2"
474 commandString << ",6ch"
476 commandString << ",auto"
481 commandString << " -f "
482 case hash["FileFormat"]
484 commandString << "mp4"
486 commandString << "avi"
488 commandString << "ogm"
490 commandString << "mkv"
494 if hash["Mp4iPodCompatible"].to_i == 1
495 commandString << " -I"
499 if hash["Mp4LargeFile"] == 1
500 commandString << " -4"
504 if hash["PictureAutoCrop"] == 0
505 commandString << " --crop "
506 commandString << hash["PictureTopCrop"].to_s
508 commandString << hash["PictureBottomCrop"].to_s
510 commandString << hash["PictureLeftCrop"].to_s
512 commandString << hash["PictureRightCrop"].to_s
516 if hash["PictureWidth"] != 0
517 commandString << " -X "
518 commandString << hash["PictureWidth"].to_s
520 if hash["PictureHeight"] != 0
521 commandString << " -Y "
522 commandString << hash["PictureHeight"].to_s
526 if hash["Subtitles"] != "None"
527 commandString << " -s "
528 commandString << hash["Subtitles"]
532 if hash["UsesPictureFilters"] == 1
534 case hash["PictureDeinterlace"]
536 commandString << " --deinterlace=\"fast\""
538 commandString << " --deinterlace=\slow\""
540 commandString << " --deinterlace=\"slower\""
542 commandString << " --deinterlace=\"slowest\""
545 case hash["PictureDenoise"]
547 commandString << " --denoise=\"weak\""
549 commandString << " --denoise=\"medium\""
551 commandString << " --denoise=\"strong\""
554 if hash["PictureDetelecine"] == 1 then commandString << " --detelecine" end
555 if hash["PictureDeblock"] == 1 then commandString << " --deblock" end
556 if hash["VFR"].to_i == 1 then commandString << " --vfr" end
557 if hash["PictureDecomb"] == 1 then commandString << " --decomb" end
562 if hash["PicturePAR"] == 1
563 commandString << " -p"
564 elsif hash["PicturePAR"] == 2
565 commandString << " -P"
569 if hash["ChapterMarkers"] == 1 then commandString << " -m" end
570 if hash["VideoGrayScale"] == 1 then commandString << " -g" end
571 if hash["VideoTwoPass"] == 1 then commandString << " -2" end
572 if hash["VideoTurboTwoPass"] == 1 then commandString << " -T" end
575 if hash["x264Option"] != ""
576 commandString << " -x "
577 commandString << hash["x264Option"]
580 # That's it, print to screen now
583 #puts "*" * @columnWidth
588 def generateCLIFolderParse( hash, depth ) # Shows the folder for wrappers to parse
596 commandString << " " << hash["PresetName"] << "\n\n"
600 def generateCLIFolderCloserParse( depth )
608 commandString << "\n\n"
612 def generateCLIParse(hash, depth) # Makes a CLI equivalent of all user presets, for wrappers to parse
617 commandString << '+ ' << hash["PresetName"] << ":"
620 if hash["VideoEncoder"] != "MPEG-4 (FFmpeg)"
621 commandString << " -e "
622 case hash["VideoEncoder"]
624 commandString << "x264"
626 commandString << "xvid"
631 case hash["VideoQualityType"]
633 commandString << " -S " << hash["VideoTargetSize"]
635 commandString << " -b " << hash["VideoAvgBitrate"]
637 commandString << " -q " << hash["VideoQualitySlider"].to_s
641 if hash["VideoFramerate"] != "Same as source"
642 if hash["VideoFramerate"] == "23.976 (NTSC Film)"
643 commandString << " -r " << "23.976"
644 elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
645 commandString << " -r " << "29.97"
647 commandString << " -r " << hash["VideoFramerate"]
652 commandString << " -a "
653 commandString << hash["Audio1Track"].to_s
654 if hash["Audio2Track"]
655 commandString << "," << hash["Audio2Track"].to_s
657 if hash["Audio3Track"]
658 commandString << "," << hash["Audio3Track"].to_s
660 if hash["Audio4Track"]
661 commandString << "," << hash["Audio4Track"].to_s
665 commandString << " -E "
666 case hash["Audio1Encoder"]
668 commandString << "ac3"
670 commandString << "faac"
672 commandString << "vorbis"
674 commandString << "lame"
676 case hash["Audio2Encoder"]
678 commandString << ",ac3"
680 commandString << ",faac"
682 commandString << ",vorbis"
684 commandString << ",lame"
686 case hash["Audio3Encoder"]
688 commandString << ",ac3"
690 commandString << ",faac"
692 commandString << ",vorbis"
694 commandString << ",lame"
696 case hash["Audio4Encoder"]
698 commandString << ",ac3"
700 commandString << ",faac"
702 commandString << ",vorbis"
704 commandString << ",lame"
708 commandString << " -B "
709 commandString << hash["Audio1Bitrate"]
710 if hash["Audio2Bitrate"]
711 if hash["Audio2Encoder"] != "AC3 Passthru"
712 commandString << "," << hash["Audio2Bitrate"]
714 commandString << "," << "auto"
717 if hash["Audio3Bitrate"]
718 if hash["Audio3Encoder"] != "AC3 Passthru"
719 commandString << "," << hash["Audio3Bitrate"]
721 commandString << "," << "auto"
724 if hash["Audio4Bitrate"]
725 if hash["Audio4Encoder"] != "AC3 Passthru"
726 commandString << "," << hash["Audio4Bitrate"]
728 commandString << "," << "auto"
733 commandString << " -R "
734 commandString << hash["Audio1Samplerate"]
735 if hash["Audio2Samplerate"]
736 commandString << "," << hash["Audio2Samplerate"]
738 if hash["Audio3Samplerate"]
739 commandString << "," << hash["Audio3Samplerate"]
741 if hash["Audio4Samplerate"]
742 commandString << "," << hash["Audio4Samplerate"]
746 commandString << " -6 "
747 case hash["Audio1Mixdown"]
749 commandString << "mono"
751 commandString << "stereo"
752 when /Dolby Surround/
753 commandString << "dpl1"
754 when /Dolby Pro Logic II/
755 commandString << "dpl2"
757 commandString << "6ch"
759 commandString << "auto"
762 if hash["Audio2Mixdown"]
763 case hash["Audio2Mixdown"]
765 commandString << ",mono"
767 commandString << ",stereo"
768 when /Dolby Surround/
769 commandString << ",dpl1"
770 when /Dolby Pro Logic II/
771 commandString << ",dpl2"
773 commandString << ",6ch"
775 commandString << ",auto"
779 if hash["Audio3Mixdown"]
780 case hash["Audio3Mixdown"]
782 commandString << ",mono"
784 commandString << ",stereo"
785 when /Dolby Surround/
786 commandString << ",dpl1"
787 when /Dolby Pro Logic II/
788 commandString << ",dpl2"
790 commandString << ",6ch"
792 commandString << ",auto"
796 if hash["Audio4Mixdown"]
797 case hash["Audio4Mixdown"]
799 commandString << ",mono"
801 commandString << ",stereo"
802 when /Dolby Surround/
803 commandString << ",dpl1"
804 when /Dolby Pro Logic II/
805 commandString << ",dpl2"
807 commandString << ",6ch"
809 commandString << ",auto"
815 commandString << " -f "
816 case hash["FileFormat"]
818 commandString << "mp4"
820 commandString << "avi"
822 commandString << "ogm"
824 commandString << "mkv"
828 if hash["Mp4iPodCompatible"].to_i == 1
829 commandString << " -I"
833 if hash["Mp4LargeFile"] == 1
834 commandString << " -4"
838 if hash["PictureAutoCrop"] == 0
839 commandString << " --crop "
840 commandString << hash["PictureTopCrop"].to_s
842 commandString << hash["PictureBottomCrop"].to_s
844 commandString << hash["PictureLeftCrop"].to_s
846 commandString << hash["PictureRightCrop"].to_s
850 if hash["PictureWidth"] != 0
851 commandString << " -X "
852 commandString << hash["PictureWidth"].to_s
854 if hash["PictureHeight"] != 0
855 commandString << " -Y "
856 commandString << hash["PictureHeight"].to_s
860 if hash["Subtitles"] != "None"
861 commandString << " -s "
862 commandString << hash["Subtitles"]
866 if hash["UsesPictureFilters"] == 1
868 case hash["PictureDeinterlace"]
870 commandString << " --deinterlace=\"fast\""
872 commandString << " --deinterlace=\slow\""
874 commandString << " --deinterlace=\"slower\""
876 commandString << " --deinterlace=\"slowest\""
879 case hash["PictureDenoise"]
881 commandString << " --denoise=\"weak\""
883 commandString << " --denoise=\"medium\""
885 commandString << " --denoise=\"strong\""
888 if hash["PictureDetelecine"] == 1 then commandString << " --detelecine" end
889 if hash["PictureDeblock"] == 1 then commandString << " --deblock" end
890 if hash["VFR"].to_i == 1 then commandString << " --vfr" end
891 if hash["PictureDecomb"] == 1 then commandString << " --decomb" end
895 if hash["PicturePAR"] == 1
896 commandString << " -p"
897 elsif hash["PicturePAR"] == 2
898 commandString << " -P"
902 if hash["ChapterMarkers"] == 1 then commandString << " -m" end
903 if hash["VideoGrayScale"] == 1 then commandString << " -g" end
904 if hash["VideoTwoPass"] == 1 then commandString << " -2" end
905 if hash["VideoTurboTwoPass"] == 1 then commandString << " -T" end
908 if hash["x264Option"] != ""
909 commandString << " -x "
910 commandString << hash["x264Option"]
913 # That's it, print to screen now
916 #puts "*" * @columnWidth
921 def generateAPIcalls(hash) # Makes a C version of the preset ready for coding into the CLI
923 commandString = "if (!strcmp(preset_name, \"" << hash["PresetName"] << "\"))\n{\n "
926 case hash["FileFormat"]
928 commandString << "mux = " << "HB_MUX_MP4;\n "
930 commandString << "mux = " << "HB_MUX_AVI;\n "
932 commandString << "mux = " << "HB_MUX_OGM;\n "
934 commandString << "mux = " << "HB_MUX_MKV;\n "
938 if hash["Mp4iPodCompatible"].to_i == 1
939 commandString << "job->ipod_atom = 1;\n "
943 if hash["Mp4LargeFile"] == 1
944 commandString << "job->largeFileSize = 1;\n "
948 if hash["VideoEncoder"] != "MPEG-4 (FFmpeg)"
949 commandString << "vcodec = "
950 case hash["VideoEncoder"]
952 commandString << "HB_VCODEC_X264;\n "
954 commandString << "HB_VCODEC_XVID;\n "
959 case hash["VideoQualityType"]
961 commandString << "size = " << hash["VideoTargetSize"] << ";\n "
963 commandString << "job->vbitrate = " << hash["VideoAvgBitrate"] << ";\n "
965 commandString << "job->vquality = " << hash["VideoQualitySlider"].to_s << ";\n "
966 commandString << "job->crf = 1;\n "
970 if hash["VideoFramerate"] != "Same as source"
971 if hash["VideoFramerate"] == "23.976 (NTSC Film)"
972 commandString << "job->vrate_base = " << "1126125;\n "
973 elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
974 commandString << "job->vrate_base = " << "900900;\n "
975 # Gotta add the rest of the framerates for completion's sake.
977 commandString << "job->cfr = 1;\n "
981 commandString << "atracks = strdup(\""
982 commandString << hash["Audio1Track"].to_s
983 if hash["Audio2Track"]
984 commandString << "," << hash["Audio2Track"].to_s
986 if hash["Audio3Track"]
987 commandString << "," << hash["Audio3Track"].to_s
989 if hash["Audio4Track"]
990 commandString << "," << hash["Audio4Track"].to_s
992 commandString << "\");\n "
995 commandString << "abitrates = strdup(\""
996 if hash["Audio1Encoder"] != "AC3 Passthru"
997 commandString << hash["Audio1Bitrate"]
999 commandString << "auto"
1001 if hash["Audio2Bitrate"]
1002 if hash["Audio2Encoder"] != "AC3 Passthru"
1003 commandString << "," << hash["Audio2Bitrate"]
1005 commandString << "," << "auto"
1008 if hash["Audio3Bitrate"]
1009 if hash["Audio3Encoder"] != "AC3 Passthru"
1010 commandString << "," << hash["Audio3Bitrate"]
1012 commandString << "," << "auto"
1015 if hash["Audio4Bitrate"]
1016 if hash["Audio4Encoder"] != "AC3 Passthru"
1017 commandString << "," << hash["Audio4Bitrate"]
1019 commandString << "," << "auto"
1022 commandString << "\");\n "
1025 commandString << "arates = strdup(\""
1026 commandString << hash["Audio1Samplerate"]
1027 if hash["Audio2Samplerate"]
1028 commandString << "," << hash["Audio2Samplerate"]
1030 if hash["Audio3Samplerate"]
1031 commandString << "," << hash["Audio3Samplerate"]
1033 if hash["Audio4Samplerate"]
1034 commandString << "," << hash["Audio4Samplerate"]
1036 commandString << "\");\n "
1039 commandString << "acodecs = strdup(\""
1040 case hash["Audio1Encoder"]
1042 commandString << "ac3"
1044 commandString << "faac"
1046 commandString << "vorbis"
1048 commandString << "lame"
1050 case hash["Audio2Encoder"]
1052 commandString << ",ac3"
1054 commandString << ",faac"
1056 commandString << ",vorbis"
1058 commandString << ",lame"
1060 case hash["Audio3Encoder"]
1062 commandString << ",ac3"
1064 commandString << ",faac"
1066 commandString << ",vorbis"
1068 commandString << ",lame"
1070 case hash["Audio4Encoder"]
1072 commandString << ",ac3"
1074 commandString << ",faac"
1076 commandString << ",vorbis"
1078 commandString << ",lame"
1080 commandString << "\");\n "
1083 commandString << "mixdowns = strdup(\""
1084 case hash["Audio1Mixdown"]
1086 commandString << "mono"
1088 commandString << "stereo"
1089 when /Dolby Surround/
1090 commandString << "dpl1"
1091 when /Dolby Pro Logic II/
1092 commandString << "dpl2"
1094 commandString << "6ch"
1096 commandString << "auto"
1098 if hash["Audio2Mixdown"]
1099 case hash["Audio2Mixdown"]
1101 commandString << ",mono"
1103 commandString << ",stereo"
1104 when /Dolby Surround/
1105 commandString << ",dpl1"
1106 when /Dolby Pro Logic II/
1107 commandString << ",dpl2"
1109 commandString << ",6ch"
1111 commandString << ",auto"
1114 if hash["Audio3Mixdown"]
1115 case hash["Audio3Mixdown"]
1117 commandString << ",mono"
1119 commandString << ",stereo"
1120 when /Dolby Surround/
1121 commandString << ",dpl1"
1122 when /Dolby Pro Logic II/
1123 commandString << ",dpl2"
1125 commandString << ",6ch"
1127 commandString << ",auto"
1130 if hash["Audio4Mixdown"]
1131 case hash["Audio4Mixdown"]
1133 commandString << ",mono"
1135 commandString << ",stereo"
1136 when /Dolby Surround/
1137 commandString << ",dpl1"
1138 when /Dolby Pro Logic II/
1139 commandString << ",dpl2"
1141 commandString << ",6ch"
1143 commandString << ",auto"
1146 commandString << "\");\n "
1149 if hash["PictureAutoCrop"] == 0
1150 commandString << "job->crop[0] = " << hash["PictureTopCrop"].to_s << ";\n "
1151 commandString << "job->crop[1] = " << hash["PictureBottomCrop"].to_s << ";\n "
1152 commandString << "job->crop[2] = " << hash["PictureLeftCrop"].to_s << ";\n "
1153 commandString << "job->crop[4] - " << hash["PictureRightCrop"].to_s << ";\n "
1157 if hash["PictureWidth"] != 0
1158 commandString << "maxWidth = "
1159 commandString << hash["PictureWidth"].to_s << ";\n "
1161 if hash["PictureHeight"] != 0
1162 commandString << "maxHeight = "
1163 commandString << hash["PictureHeight"].to_s << ";\n "
1167 if hash["Subtitles"] != "None"
1168 commandString << "job->subtitle = "
1169 commandString << ( hash["Subtitles"].to_i - 1).to_s << ";\n "
1173 if hash["x264Option"] != ""
1174 commandString << "x264opts = strdup(\""
1175 commandString << hash["x264Option"] << "\");\n "
1179 if hash["UsesPictureFilters"] == 1
1181 case hash["PictureDeinterlace"]
1183 commandString << "deinterlace = 1;\n "
1184 commandString << "deinterlace_opt = \"-1\";\n "
1186 commandString << "deinterlace = 1;\n "
1187 commandString << "deinterlace_opt = \"2\";\n "
1189 commandString << "deinterlace = 1;\n "
1190 commandString << "deinterlace_opt = \"0\";\n "
1192 commandString << "deinterlace = 1;\n "
1193 commandString << "deinterlace_opt = \"1:-1:1\";\n "
1196 case hash["PictureDenoise"]
1198 commandString << "denoise = 1;\n "
1199 commandString << "denoise_opt = \"2:1:2:3\";\n "
1201 commandString << "denoise = 1;\n "
1202 commandString << "denoise_opt = \"3:2:2:3\";\n "
1204 commandString << "denoise = 1;\n "
1205 commandString << "denoise_opt = \"7:7:5:5\";\n "
1208 if hash["PictureDetelecine"] == 1 then commandString << "detelecine = 1;\n " end
1209 if hash["PictureDeblock"] == 1 then commandString << "deblock = 1;\n " end
1210 if hash["VFR"].to_i == 1 then commandString << "vfr = 1;\n " end
1211 if hash["PictureDecomb"] == 1 then commandString << "decomb = 1;\n " end
1216 if hash["PicturePAR"] == 1
1217 commandString << "pixelratio = 1;\n "
1218 elsif hash["PicturePAR"] == 2
1219 commandString << "pixelratio = 2;\n "
1223 if hash["ChapterMarkers"] == 1 then commandString << "job->chapter_markers = 1;\n " end
1224 if hash["VideoGrayScale"] == 1 then commandString << "job->grayscale = 1;\n " end
1225 if hash["VideoTwoPass"] == 1 then commandString << "twoPass = 1;\n " end
1226 if hash["VideoTurboTwoPass"] == 1 then commandString << "turbo_opts_enabled = 1;\n" end
1228 commandString << "}"
1230 # That's it, print to screen now
1232 #puts "*" * @columnWidth
1236 def generateAPIFolderList( hash, depth )
1239 commandString << " printf(\"\\n"
1241 commandString << " "
1244 commandString << "<"
1246 commandString << " " << hash["PresetName"]
1247 commandString << "\\n\");\n\n"
1251 def generateAPIFolderCloserList( depth )
1254 commandString << " printf(\"\\n"
1256 commandString << " "
1259 commandString << ">"
1261 commandString << "\\n\");\n\n"
1265 def generateAPIList(hash, depth) # Makes a list of the CLI options a built-in CLI preset uses, for wrappers to parse
1267 commandString << " printf(\"\\n"
1269 commandString << " "
1272 commandString << "+ " << hash["PresetName"] << ": "
1275 if hash["VideoEncoder"] != "MPEG-4 (FFmpeg)"
1276 commandString << " -e "
1277 case hash["VideoEncoder"]
1279 commandString << "x264 "
1281 commandString << "xvid "
1286 case hash["VideoQualityType"]
1288 commandString << " -S " << hash["VideoTargetSize"]
1290 commandString << " -b " << hash["VideoAvgBitrate"]
1292 commandString << " -q " << hash["VideoQualitySlider"].to_s
1296 if hash["VideoFramerate"] != "Same as source"
1297 if hash["VideoFramerate"] == "23.976 (NTSC Film)"
1298 commandString << " -r " << "23.976"
1299 elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
1300 commandString << " -r " << "29.97"
1302 commandString << " -r " << hash["VideoFramerate"]
1307 commandString << " -a "
1308 commandString << hash["Audio1Track"].to_s
1309 if hash["Audio2Track"]
1310 commandString << "," << hash["Audio2Track"].to_s
1312 if hash["Audio3Track"]
1313 commandString << "," << hash["Audio3Track"].to_s
1315 if hash["Audio4Track"]
1316 commandString << "," << hash["Audio4Track"].to_s
1320 commandString << " -E "
1321 case hash["Audio1Encoder"]
1323 commandString << "ac3"
1325 commandString << "faac"
1327 commandString << "vorbis"
1329 commandString << "lame"
1331 case hash["Audio2Encoder"]
1333 commandString << ",ac3"
1335 commandString << ",faac"
1337 commandString << ",vorbis"
1339 commandString << ",lame"
1341 case hash["Audio3Encoder"]
1343 commandString << ",ac3"
1345 commandString << ",faac"
1347 commandString << ",vorbis"
1349 commandString << ",lame"
1351 case hash["Audio4Encoder"]
1353 commandString << ",ac3"
1355 commandString << ",faac"
1357 commandString << ",vorbis"
1359 commandString << ",lame"
1363 commandString << " -B "
1364 commandString << hash["Audio1Bitrate"]
1365 if hash["Audio2Bitrate"]
1366 if hash["Audio2Encoder"] != "AC3 Passthru"
1367 commandString << "," << hash["Audio2Bitrate"]
1369 commandString << "," << "auto"
1372 if hash["Audio3Bitrate"]
1373 if hash["Audio3Encoder"] != "AC3 Passthru"
1374 commandString << "," << hash["Audio3Bitrate"]
1376 commandString << "," << "auto"
1379 if hash["Audio4Bitrate"]
1380 if hash["Audio4Encoder"] != "AC3 Passthru"
1381 commandString << "," << hash["Audio4Bitrate"]
1383 commandString << "," << "auto"
1388 commandString << " -R "
1389 commandString << hash["Audio1Samplerate"]
1390 if hash["Audio2Samplerate"]
1391 commandString << "," << hash["Audio2Samplerate"]
1393 if hash["Audio3Samplerate"]
1394 commandString << "," << hash["Audio3Samplerate"]
1396 if hash["Audio4Samplerate"]
1397 commandString << "," << hash["Audio4Samplerate"]
1401 commandString << " -6 "
1402 case hash["Audio1Mixdown"]
1404 commandString << "mono"
1406 commandString << "stereo"
1407 when /Dolby Surround/
1408 commandString << "dpl1"
1409 when /Dolby Pro Logic II/
1410 commandString << "dpl2"
1412 commandString << "6ch"
1414 commandString << "auto"
1417 if hash["Audio2Mixdown"]
1418 case hash["Audio2Mixdown"]
1420 commandString << ",mono"
1422 commandString << ",stereo"
1423 when /Dolby Surround/
1424 commandString << ",dpl1"
1425 when /Dolby Pro Logic II/
1426 commandString << ",dpl2"
1428 commandString << ",6ch"
1430 commandString << ",auto"
1434 if hash["Audio3Mixdown"]
1435 case hash["Audio3Mixdown"]
1437 commandString << ",mono"
1439 commandString << ",stereo"
1440 when /Dolby Surround/
1441 commandString << ",dpl1"
1442 when /Dolby Pro Logic II/
1443 commandString << ",dpl2"
1445 commandString << ",6ch"
1447 commandString << ",auto"
1451 if hash["Audio4Mixdown"]
1452 case hash["Audio4Mixdown"]
1454 commandString << ",mono"
1456 commandString << ",stereo"
1457 when /Dolby Surround/
1458 commandString << ",dpl1"
1459 when /Dolby Pro Logic II/
1460 commandString << ",dpl2"
1462 commandString << ",6ch"
1464 commandString << ",auto"
1469 commandString << " -f "
1470 case hash["FileFormat"]
1472 commandString << "mp4"
1474 commandString << "avi"
1476 commandString << "ogm"
1478 commandString << "mkv"
1482 if hash["Mp4iPodCompatible"].to_i == 1
1483 commandString << " -I"
1487 if hash["Mp4LargeFile"] == 1
1488 commandString << " -4"
1492 if hash["PictureAutoCrop"] == 0
1493 commandString << " --crop "
1494 commandString << hash["PictureTopCrop"].to_s
1495 commandString << ":"
1496 commandString << hash["PictureBottomCrop"].to_s
1497 commandString << ":"
1498 commandString << hash["PictureLeftCrop"].to_s
1499 commandString << ":"
1500 commandString << hash["PictureRightCrop"].to_s
1504 if hash["PictureWidth"] != 0
1505 commandString << " -X "
1506 commandString << hash["PictureWidth"].to_s
1508 if hash["PictureHeight"] != 0
1509 commandString << " -Y "
1510 commandString << hash["PictureHeight"].to_s
1514 if hash["Subtitles"] != "None"
1515 commandString << " -s "
1516 commandString << hash["Subtitles"]
1520 if hash["UsesPictureFilters"] == 1
1522 case hash["PictureDeinterlace"]
1524 commandString << " --deinterlace=\\\"fast\\\""
1526 commandString << " --deinterlace=\\\slow\\\""
1528 commandString << " --deinterlace=\\\"slower\\\""
1530 commandString << " --deinterlace=\\\"slowest\\\""
1533 case hash["PictureDenoise"]
1535 commandString << " --denoise=\\\"weak\\\""
1537 commandString << " --denoise=\\\"medium\\\""
1539 commandString << " --denoise=\\\"strong\\\""
1542 if hash["PictureDetelecine"] == 1 then commandString << " --detelecine" end
1543 if hash["PictureDeblock"] == 1 then commandString << " --deblock" end
1544 if hash["VFR"].to_i == 1 then commandString << " --vfr" end
1545 if hash["PictureDecomb"] == 1 then commandString << " --decomb" end
1549 if hash["PicturePAR"] == 1
1550 commandString << " -p"
1551 elsif hash["PicturePAR"] == 2
1552 commandString << " -P"
1556 if hash["ChapterMarkers"] == 1 then commandString << " -m" end
1557 if hash["VideoGrayScale"] == 1 then commandString << " -g" end
1558 if hash["VideoTwoPass"] == 1 then commandString << " -2" end
1559 if hash["VideoTurboTwoPass"] == 1 then commandString << " -T" end
1562 if hash["x264Option"] != ""
1563 commandString << " -x "
1564 commandString << hash["x264Option"]
1567 commandString << "\\n\");"
1569 # That's it, print to screen now
1576 # First grab the specified CLI options
1577 options = readOptions
1579 # Only run if one of the useful CLI flags have been passed
1580 if options.cliraw == true || options.cliparse == true || options.api == true || options.apilist == true
1581 # This line is the ignition -- generates hashes of
1582 # presets and then displays them to the screen
1583 # with the options the user selects on the CLI.
1584 Display.new( Presets.new.hashMasterList, options )
1586 # Direct the user to the help
1587 puts "\n\tUsage: manicure.rb [options]"
1588 puts "\tSee help with -h or --help"