mlame 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #!/bin/sh
  2. ############################################################################
  3. #
  4. # Run the LAME encoder on multiple files, with option to delete .wav files
  5. # after encoding. "mlame -?" will give instructions.
  6. #
  7. # Robert Hegemann
  8. # modified on request: Frank Klemm <pfk@uni-jena.de>
  9. #
  10. ############################################################################
  11. # encoder path to use
  12. mp3coder="lame"
  13. mp3analyzer="mlame_corr"
  14. # default options to use
  15. options_low="-h -d -mj -b 128"
  16. options_high="-h -d -mj -V 1 -b 112 -B 320"
  17. options=$options_high
  18. # remove source?
  19. removesource=false
  20. # force overwrite of destination
  21. testoverwrite=true
  22. # waiting after error report n seconds
  23. errordelay=1
  24. helptext="\n\
  25. This script runs the LAME mp3 encoder on multiple files: \n\n\
  26. $0 [options] <file 1> ... <file n>\n\
  27. \n\
  28. options:\n\
  29. -? this help text\n\
  30. -r remove files after encoding\n\
  31. -f force overwrite of destination if exists\n\
  32. -l low quality settings\n\
  33. -h high quality settings\n\
  34. -o \"<lame options>\" overrides script default options
  35. \n\
  36. example:\n\
  37. $0 -r -f -o \"-v -V 0 -b 112\" a*.wav z*.aif g*.mp?\n\
  38. \n\
  39. "
  40. # process command-line options
  41. # this could be extended to fake the
  42. # commandline interface of the mp3encoder
  43. while getopts ":o:r:h:l:f" optn; do
  44. case $optn in
  45. o ) options=$OPTARG # replace default options
  46. echo New lame options are \'$options\'
  47. ;;
  48. r ) removesource=true
  49. echo Removing source files after successfully converting
  50. ;;
  51. f ) testoverwrite=false
  52. echo Force overwriting existing destination files
  53. ;;
  54. h ) options=$options_high
  55. ;;
  56. l ) options=$options_low
  57. ;;
  58. \? ) printf "$helptext"
  59. sleep $errordelay
  60. exit 1
  61. ;;
  62. esac
  63. done
  64. shift $(($OPTIND - 1))
  65. # no files remaining?
  66. if [ "$1" = "" ]; then
  67. printf "$helptext"
  68. sleep $errordelay
  69. exit 1
  70. fi
  71. # process input-files
  72. for src in "$@"; do
  73. case $src in
  74. *[.][wW][aA][vV] )
  75. dst=${src%[.][wW][aA][vV]}.mp3
  76. if [ -f "$src" ]; then
  77. if [ $testoverwrite = true -a -f "$dst" ]; then
  78. echo \'$dst\' already exists, skipping
  79. sleep $errordelay
  80. elif $mp3coder $options `$mp3analyzer "$src"` "$src" "$dst"; then
  81. if [ $removesource = true ]; then
  82. rm -f "$src"
  83. fi
  84. else
  85. echo converting of \'$src\' to \'$dst\' failed
  86. sleep $errordelay
  87. fi
  88. else
  89. echo No source file \'$src\' found.
  90. sleep $errordelay
  91. fi
  92. ;;
  93. *[.][aA][iI][fF] )
  94. dst=${src%[.][aA][iI][fF]}.mp3
  95. if [ -f "$src" ]; then
  96. if [ $testoverwrite = true -a -f "$dst" ]; then
  97. echo \'$dst\' already exists, skipping
  98. sleep $errordelay
  99. elif $mp3coder $options "$src" "$dst"; then
  100. if [ $removesource = true ]; then
  101. rm -f "$src"
  102. fi
  103. else
  104. echo converting of \'$src\' to \'$dst\' failed
  105. sleep $errordelay
  106. fi
  107. else
  108. echo No source file \'$src\' found.
  109. sleep $errordelay
  110. fi
  111. ;;
  112. *[.][aA][iI][fF][fF] )
  113. dst=${src%[.][aA][iI][fF][fF]}.mp3
  114. if [ -f "$src" ]; then
  115. if [ $testoverwrite = true -a -f "$dst" ]; then
  116. echo \'$dst\' already exists, skipping
  117. sleep $errordelay
  118. elif $mp3coder $options "$src" "$dst"; then
  119. if [ $removesource = true ]; then
  120. rm -f "$src"
  121. fi
  122. else
  123. echo converting of \'$src\' to \'$dst\' failed
  124. sleep $errordelay
  125. fi
  126. else
  127. echo No source file \'$src\' found.
  128. sleep $errordelay
  129. fi
  130. ;;
  131. *[.][mM][pP][gG12] )
  132. dst=${src%[.][mM][pP][gG12]}.mp3
  133. if [ -f "$src" ]; then
  134. if [ $testoverwrite = true -a -f "$dst" ]; then
  135. echo \'$dst\' already exists, skipping
  136. sleep $errordelay
  137. elif $mp3coder $options "$src" "$dst"; then
  138. if [ $removesource = true ]; then
  139. rm -f "$src"
  140. fi
  141. else
  142. echo converting of \'$src\' to \'$dst\' failed
  143. sleep $errordelay
  144. fi
  145. else
  146. echo No source file \'$src\' found.
  147. sleep $errordelay
  148. fi
  149. ;;
  150. *[.][mM][pP]3 )
  151. dst=${src%[.][mM][pP]3}-new-converted-file.${src##*.}
  152. if [ -f "$src" ]; then
  153. if [ $testoverwrite = true -a -f "$dst" ]; then
  154. echo \'$dst\' already exists, skipping
  155. sleep $errordelay
  156. elif $mp3coder $options "$src" "$dst"; then
  157. if [ $removesource = true ]; then
  158. mv -f "$dst" "$src"
  159. fi
  160. else
  161. echo converting of \'$src\' to \'$dst\' failed
  162. sleep $errordelay
  163. fi
  164. else
  165. echo No source file \'$src\' found.
  166. sleep $errordelay
  167. fi
  168. ;;
  169. * ) # the rest
  170. echo warning: File extention \'.${src##*.}\' not supported
  171. sleep $errordelay
  172. ;;
  173. esac
  174. done