https://wiki.archlinux.org/api.php?action=feedcontributions&user=Diamondice00085&feedformat=atomArchWiki - User contributions [en]2024-03-29T11:13:26ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Convert_FLAC_to_MP3&diff=76860Convert FLAC to MP32009-10-01T14:24:05Z<p>Diamondice00085: </p>
<hr />
<div>[[Category:Audio/Video (English)]]<br />
[[Category:Scripts (English)]]<br />
[[Category:HOWTOs (English)]]<br />
=Introduction=<br />
Here is a script that will convert FLAC to MP3 via the commandline. <br />
<br />
Essentially, the .flac files within a directory will be decompressed to .wav and then the resulting .wav files will be encoded to .mp3 using the latest LAME switches for encodings (''-V 0 --vbr-new''). The ID3 tags of the original .flac files will be passed to the resulting .mp3 files.<br />
<br />
The original .flac files will not be harmed and the resulting .mp3s will be in the same directory. All other files in the directory (.nfo, images, .sfv, etc) will be ignored and unharmed. <br />
<br />
For more information on LAME switches/settings such as V0, visit [http://wiki.hydrogenaudio.org/index.php?title=LAME Hydrogenaudio LAME Wiki]. V0 is roughly equivalent to ''--preset extreme'' which results in a variable bitrate usually between 220-260. The audio of a V0 is transparent, meaning one cannot tell the difference between the lossy file and the original source (compact disc/lossless), but yet the file size is a quite reasonable. <br />
<br />
More information on flac: [http://wiki.hydrogenaudio.org/index.php?title=Flac FLAC]<br />
<br />
==Installation==<br />
<br />
First you need to install the following packages: flac, lame, and id3<br />
<br />
<pre><br />
pacman -S flac lame id3<br />
</pre><br />
<br />
Once those are installed, copy the following script into your preferred editor:<br />
<br />
<pre><br />
for a in *.flac<br />
<br />
do<br />
OUTF=`echo "$a" | sed s/\.flac$/.mp3/g`<br />
<br />
ARTIST=`metaflac "$a" --show-tag=ARTIST | sed s/.*=//g`<br />
TITLE=`metaflac "$a" --show-tag=TITLE | sed s/.*=//g`<br />
ALBUM=`metaflac "$a" --show-tag=ALBUM | sed s/.*=//g`<br />
GENRE=`metaflac "$a" --show-tag=GENRE | sed s/.*=//g`<br />
TRACKNUMBER=`metaflac "$a" --show-tag=TRACKNUMBER | sed s/.*=//g`<br />
DATE=`metaflac "$a" --show-tag=DATE | sed s/.*=//g`<br />
<br />
flac -c -d "$a" | lame -m j -q 0 --vbr-new -V 0 -s 44.1 - "$OUTF"<br />
id3 -t "$TITLE" -T "${TRACKNUMBER:-0}" -a "$ARTIST" -A "$ALBUM" -y "$DATE" -g "${GENRE:-12}" "$OUTF"<br />
<br />
done<br />
</pre><br />
<br />
Alternatively, below is a script that will search for all FLAC audio files beyond where the script resides on your filesystem and convert them to MP3; including those pesky filenames with spaces.<br />
<br />
<pre><br />
find -name *.flac -print0 | while read -d $'\0' a<br />
<br />
<br />
do<br />
OUTF=`echo "$a" | sed s/\.flac$/.mp3/g`<br />
<br />
ARTIST=`metaflac "$a" --show-tag=ARTIST | sed s/.*=//g`<br />
TITLE=`metaflac "$a" --show-tag=TITLE | sed s/.*=//g`<br />
ALBUM=`metaflac "$a" --show-tag=ALBUM | sed s/.*=//g`<br />
GENRE=`metaflac "$a" --show-tag=GENRE | sed s/.*=//g`<br />
TRACKNUMBER=`metaflac "$a" --show-tag=TRACKNUMBER | sed s/.*=//g`<br />
DATE=`metaflac "$a" --show-tag=DATE | sed s/.*=//g`<br />
<br />
flac -c -d "$a" | lame -m j -q 0 --vbr-new -V 0 -s 44.1 - "$OUTF"<br />
id3 -t "$TITLE" -T "${TRACKNUMBER:-0}" -a "$ARTIST" -A "$ALBUM" -y "$DATE" -g "${GENRE:-12}" "$OUTF"<br />
<br />
done<br />
<br />
</pre><br />
<br />
Save the script as ''flac2mp3'' and make the script executable:<br />
<br />
<pre><br />
chmod a+x flac2mp3<br />
</pre><br />
<br />
As root, copy the script to /usr/local/bin (or anywhere else that is in your $PATH).<br />
<br />
<pre><br />
cp flac2mp3 /usr/local/bin<br />
</pre><br />
<br />
To make /usr/local/bin in your $PATH, do (as normal user):<br />
<br />
<pre><br />
PATH=$PATH:/usr/local/bin/<br />
</pre><br />
<br />
and then (as normal user):<br />
<pre><br />
nano .bashrc<br />
</pre><br />
<br />
and add ''export PATH=$PATH:/usr/local/bin/''<br />
<br />
===Usage===<br />
<br />
Open up a terminal and cd to the directory of .flac files that you wish to convert and enter ''flac2mp3''<br />
<br />
You'll see the verbose decoding/encoding process in the terminal which may take a few moments. <br />
<br />
Done.</div>Diamondice00085