Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is my first question, so please go easy on me. 'Tis a pleasure to be here. Hopefully somebody can help me out.

For a long time I've been using a relative clunky technique which involves Audacity with a LAME plugin. This is fine I guess, but the appeal of the Terminal approach is I can be a little finer grained with my [options] and perhaps use more up-to-date binaries.

Furthermore, my MacBook is ageing a little now and if I can get rid of an unnecessary GUI, all the better.

Thanks in advance.

share|improve this question
Please, move your edit to an answer and accept it :) – Loïc Wolff Feb 24 '11 at 9:11
you will actually get points for doing that ;) – Mortimer Feb 24 '11 at 14:35
Haha... I've answered the question but it's saying I can't confirm my answer for two days. Sorry. Still figuring out how things work around here. Awesome site. :D – boehj Feb 24 '11 at 15:15
up vote 25 down vote accepted

Converting a single file without preserving tags

brew install lame
flac --decode --stdout test.flac | lame --preset extreme - test.mp3
  • --decode --stdout = -dc
  • lame - $outfile = input from STDIN
  • --preset extreme = ~245 kbit/s VBR

A shell script that preserves some ID3 tags


for f in "$@"; do
    [[ "$f" != *.flac ]] && continue
    album="$(metaflac --show-tag=album "$f" | sed 's/[^=]*=//')"
    artist="$(metaflac --show-tag=artist "$f" | sed 's/[^=]*=//')"
    date="$(metaflac --show-tag=date "$f" | sed 's/[^=]*=//')"
    title="$(metaflac --show-tag=title "$f" | sed 's/[^=]*=//')"
    year="$(metaflac --show-tag=date "$f" | sed 's/[^=]*=//')"
    genre="$(metaflac --show-tag=genre "$f" | sed 's/[^=]*=//')"
    tracknumber="$(metaflac --show-tag=tracknumber "$f" | sed 's/[^=]*=//')"

    flac --decode --stdout "$f" | lame --preset extreme --add-id3v2 --tt "$title" --ta "$artist" --tl "$album" --ty "$year" --tn "$tracknumber" --tg "$genre" - "${f%.flac}.mp3"

To use the script, just save it somewhere like ~/bin/flac2mp3 and make it executable with chmod +x ~/bin/flac2mp3.

This would convert all flac files in your Music folder:

find ~/Music/ -name '*.flac' -exec ~/bin/flac2mp3 {} \;

Or slightly faster, since it only calls flac2mp3 once:

find ~/Music/ -name '*.flac' -print0 | xargs -0 ~/bin/flac2mp3
share|improve this answer
You should post the answer here, not a reference to the text in the question. IMHO, you should edit both question and answer and move here the conclusion. – lpacheco Feb 24 '11 at 12:19
OK, will do. Sorry. – boehj Feb 24 '11 at 15:20
${file%.flac}.mp3 is awesome! Previously I was using ${x:: ${#x}-3}m4a in order to change the filename of the song from .wav to .m4a. Awesome to see a way that looks quite a bit easier. – Jason Salaz Mar 28 '11 at 18:03
Looks like there is a bug in a Option 3. Possibly because of lame version, but current code don't tell to lame it should use input stream as input file, and also output file is not specified, since stream is used, it is necessary. For me final code is : !/bin/sh file="$1" outfile=${file%.flac}.mp3 eval $(metaflac --export-tags-to - "$file" | sed "s/=\(.*\)/='\1'/") flac -cd "$file" | lame --preset standard \ --add-id3v2 --tt "$TITLE" --ta "$ARTIST" --tl "$ALBUM" \ --ty "$DATE" --tn "$TRACKNUMBER" --tg "$GENRE" \ - "$outfile" – Mehal Feb 28 '12 at 23:17
Also it's nice to create a script which does this 'find' stuff ... – Mehal Feb 28 '12 at 23:21

ffmpeg would preserve tags (but not cover art) by default.

for f in *.flac; do ffmpeg -i "$f" -aq 1 "${f%flac}mp3"; done

-aq 1 corresponds to -V 1 in lame. -acodec libfaac would convert the files to AAC:

for f in *.flac; do ffmpeg -i "$f" -acodec libfaac -aq 200 "${f%flac}m4a"; done
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.