Quickly convert flac audio to mp3 audio with Linux

First off, you need to have these 3 packages installed:

– FFMPEG (optional)
– FLAC
– LAME

FFMPEG is by far, the simpelest method. If you use it, it will automaticly convert the tags as well. Be sure that your installed version supports flac/mp3.

With FFMPEG SCRIPT:

#!/bin/bash


for f in *.flac; do
ffmpeg -i "$f" -qscale:a 0 "${f[@]/%flac/mp3}"
done

Without FFMPEG (Script author is on the ):

#!/bin/bash

for a in *.flac; do
# give output correct extension
OUTF="${a[@]/%flac/mp3}"

# get the tags
ARTIST=$(metaflac "$a" --show-tag=ARTIST | sed s/.*=//g)
TITLE=$(metaflac "$a" --show-tag=TITLE | sed s/.*=//g)
ALBUM=$(metaflac "$a" --show-tag=ALBUM | sed s/.*=//g)
GENRE=$(metaflac "$a" --show-tag=GENRE | sed s/.*=//g)
TRACKNUMBER=$(metaflac "$a" --show-tag=TRACKNUMBER | sed s/.*=//g)
DATE=$(metaflac "$a" --show-tag=DATE | sed s/.*=//g)

# stream flac into the lame encoder
flac -c -d "$a" | lame -V0 --add-id3v2 --pad-id3v2 --ignore-tag-errors
--ta "$ARTIST" --tt "$TITLE" --tl "$ALBUM" --tg "${GENRE:-12}"
--tn "${TRACKNUMBER:-0}" --ty "$DATE" - "$OUTF"
done