2 #Copylefted by: Harvie 2o1o
4 filetypes
='(mp3|wav|wma)$'; #regex
5 quality
="$1"; #passed to lame as --preset argument
6 outdir
="_lame-encoded-preset-"; #preset name will be attached - needs to be regex compatible string
8 #guess count of CPU cores
10 cpusguess
=$
(grep 'processor.:' /proc
/cpuinfo
2>/dev
/null |
wc -l);
11 [ "$cpusguess" -ge 1 ] 2>/dev
/null
&& cpus
="$cpusguess"
12 [ "$2" -ge 1 ] 2>/dev
/null
&& cpus
="$2"
15 [ "$cpus" -eq 1 ] && lamelog
='/dev/stdout'
18 echo -e "lame-recursive v$version (Harvie 2o1o)
20 (Re-)Encode all '$filetypes' files in current directory and (sub-directories)
21 - This will NOT touch the original files.
22 - This will only create new files in ${outdir}PRESET directory in each
23 sub-directory, where PRESET will be substitued by selected lame preset.
24 - Files in such directories will be ignored
25 - Once encoded file will be overwriten only if it's older than original file
26 - Requires working lame binary
27 - Supports multiple CPUs/cores
29 Usage: $0 [preset] [cpu-cores]
30 Example: cd ~/music; $0 standart
31 Example: cd ~/spoken; $0 voice
34 VBR: voice, medium, standart, extreme, insane (= 320kbps CBR)
35 ABR: 8, 16, 32, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320
36 For more info: lame --preset help
39 You probably have $cpusguess CPU cores, i will use this value by default
40 Anyway... You can try any value higher than 0
41 (does not affect sound quality, probably you don't need to change this)
47 tsign
() { echo -ne "[$$]\t"; echo "$@"; }
51 echo -ne "\n[$$] Terminated. Deleting incomplete file:\n\t"
57 trap cleanup SIGINT SIGTERM SIGHUP SIGPIPE SIGQUIT SIGKILL
;
62 outdir
="${outdir}${quality}"
63 [[ -d "$outdir" ]] ||
{
64 echo "==> Creating directory: $(pwd)/$outdir";
67 infile
="${infile##*/}";
68 outfile
="$outdir/${infile##*/}";
70 [ "$outfile" -nt "$infile" ] && {
71 tsign
"Output file is newer than input file: $(pwd)/$outfile";
75 echo "$(pwd)/$outfile" > "$temp"
76 tsign
"Encoding: '$infile'";
77 lame
--preset "$quality" "$infile" "$outfile" >"$lamelog" 2>&1
78 tsign
" Done: '$infile'; retval=$?";
81 echo "==> I will use $cpus CPU cores";
82 export -f encode
; export quality outdir lamelog
83 find -regextype posix-egrep
-iregex '.*'"$filetypes" |
grep -v /"$outdir" |
tr '\r\n' '\0\0' |
xargs -0 -n 1 -P "$cpus" bash
-c 'encode "$@"' --
86 ==> All files were processed.
87 ==> But you should rather check them before deleting the originals...
88 ==> Thank you for using lame-recursive by Harvie ( http://blog.harvie.cz/ )'