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)
44 - to quickly visualy check if all files were recoded:
45 ls -R1 . | sort | less
51 tsign
() { echo -ne "[$$]\t"; echo "$@"; }
55 echo -ne "\n[$$] Terminated. Deleting incomplete file:\n\t"
61 trap cleanup SIGINT SIGTERM SIGHUP SIGPIPE SIGQUIT SIGKILL
;
66 outdir
="${outdir}${quality}"
67 [[ -d "$outdir" ]] ||
{
68 echo "==> Creating directory: $(pwd)/$outdir";
71 infile
="${infile##*/}";
72 outfile
="$outdir/${infile##*/}";
74 [ "$outfile" -nt "$infile" ] && {
75 tsign
"Output file is newer than input file: $(pwd)/$outfile";
79 echo "$(pwd)/$outfile" > "$temp"
80 tsign
"Encoding: '$infile'";
81 lame
--preset "$quality" "$infile" "$outfile" >"$lamelog" 2>&1
82 tsign
" Done: '$infile'; retval=$?";
85 echo "==> I will use $cpus CPU cores";
86 export -f encode
; export quality outdir lamelog
87 find -regextype posix-egrep
-iregex '.*'"$filetypes" |
grep -v /"$outdir" |
tr '\r\n' '\0\0' |
xargs -0 -n 1 -P "$cpus" bash
-c 'encode "$@"' --
90 ==> All files were processed.
91 ==> But you should rather check them before deleting the originals...
92 ==> Thank you for using lame-recursive by Harvie ( http://blog.harvie.cz/ )'