Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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
5  
Please, move your edit to an answer and accept it :) –  Loïc Wolff Feb 24 '11 at 9:11
1  
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
add comment

2 Answers

up vote 19 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

#!/bin/bash

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"
done

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 {} \;
share|improve this answer
2  
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
2  
${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
1  
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
show 3 more comments

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
add comment

Your Answer

 
discard

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.