tl;dr: Loop through the files in bash, sox
them to FLAC
Success!
I’ve been combining fileserver contents recently, and I came across a little archive of Teamspeak 3 recordings:
$ du -sh .
483G /home/robert/storage/media/ts_recordings/
Eep.
I wrote a quick-and-dirty script to convert the files:
#!/bin/bash
n=0
total=$(ls *.wav|wc)
ls *.wav | while read file; do
sox -q ${file} ${file%.*}.flac
if [ -e ${file%.*}.flac ]; then
if ! [ -s {file%.*}.flac ]; then
rm ${file}
else
echo "${file%.*}.flac is zero-length!"
fi
else
echo "Failed on ${file}"
fi
((n++))
if ! ((n % 10 )); then
echo "${n} of ${total}"
fi
done
The script checks that the FLACs replacing the WAVs exist and are not zero-length before removing the original.
This was fine, but after finishing, I was still left with a bunch of uncompressed files in RF64 format, which unfortunately errored.
It turns out sox 14.4.2
added RF64 read support, so I grabbed that on my Arch machine, and converted the few remaining files (substituting wav ? rf64 twice in the script above.
The final result?
$ du -sh .
64G /home/robert/storage/raid6/media/ts_recordings/
400 gigs less space and still lossless? Ahh, much better.