lyncd

One-liner to recursively convert flac to mp3

Here’s what I do, it uses FFmpeg, doesn’t require a for loop and should work on any POSIX-compliant system. Take note that it will delete your original files! The idea is to make a copy of your music folder first, and then run this command on the copy.

find -name "*.flac" -exec sh -c 'ffmpeg -i "$1" -acodec libmp3lame -aq 4 "${1%.flac}.mp3" && rm -f "$1"' _ {} \;

And that’s it!

Notes

If you have a COW filesystem like btrfs, you can use the reflink copy option to make a duplicate of your entire Music folder (to run this command on) almost instantaneously, i.e. cp -pr --reflink Music Music-mp3

-aq option
This is the VBR quality option for libmp3lame. Choose whatever MP3 quality option you prefer.
other file types
The same basic command works on any media file that FFmpeg supports, so you can convert your .m4a Apple lossless, or .wav files, or whatever the same way, just change the file extensions.
Deletes original files
You will notice the rm command, which will delete all your flac originals. This is on purpose because we want to start with a directory tree of *.flac and convert everything to *.mp3. If you don’t want this, then remove the rm command.

Other formats

For Apple Lossless, it’s:

find -name "*.flac" -exec sh -c 'ffmpeg -i "$1" -acodec alac "${1%.flac}.m4a" && rm -f "$1"' _ {} \;

Filed under: Code.  Tagged: , , , .

No comments »

No comments yet.

Add a comment

You can also log in (or register) for easier commenting on lyncd.

Lyncd is an evolving group blog-in-progress. We’ll be designing the site, adding users and content, and developing a hifalutin site focus as we go. For now, just think of our site mantra as “minimalism.” :)