Matthew Graybosch's Website

a full-stack thaumaturge's book of shadows

[UNIX] ~/bin/flacconv

For some reason I had gotten it into my head to rip my entire CD
collection to FLAC (Free Lossless Audio CODEC) so that I could have
maximum fidelity digital music. After all, I had disk space out the
wazoo and nothing better to do than swap CDs.

However, it's occurred to me that being a middle-aged metalhead I'm
just wasting disk space. There might be a quantifiable difference
between FLAC and Ogg Vorbis encoded at maximum quality, but it's not
one I can hear with a decent set of wired headphones.

There's no sense in ripping everything again, though. Not when it's
possible to transcode FLAC to Ogg Vorbis. However, I've got a *lot* of
files and I don't want to spend weeks transcoding tracks
piecemeal. Thus, I wrote a little script called "flacconv" that uses
find and xargs to parallelize the process.

#!/usr/bin/env bash

# flacconv: parallelized FLAC to Ogg Vorbis conversion
# © 2021 Matthew Graybosch 
# available under GPLv3


find ${HOME} -name '*.flac' -print0 | xargs -0 -n ${THREADS} -P ${THREADS} oggenc -q 9
find ${HOME} -name '*.flac' -print0 | xargs -0 -n ${THREADS} -P ${THREADS} rm

You run this by calling "flacconv 8" (or however many cores your CPU
has) and it will do the rest. Why do it this way? Because it's
*fast*. It's so fast that a well-crafted find/xargs sequence can
outperform Hadoop for many workloads¹.

¹ Adam Drake "Command-line Tools can be 235x Faster than your Hadoop Cluster"