1. Overview
FLAC (Free Lossless Audio Codec) is a lossless compression format used to store high-quality audio files. It preserves the full fidelity of the original audio recording. Therefore, the FLAC format is ideal for professionals and audiophiles. However, as it retains all original sound data, the FLAC files are generally quite large in size.
On the other hand, MP3 (MPEG Audio Layer III) is a widespread audio file format compatible with most devices and audio systems. Unlike FLAC, it’s a lossy compression format and removes some data from the original audio to reduce the size of audio files. Due to the small file size and compatibility, MP3 is the preferred audio file for online streaming platforms.
In this tutorial, we’ll discuss two command-line methods to convert a FLAC file to MP3 format in Linux.
2. Using FFmpeg
We can use the FFmpeg tool in Linux to convert audio files into different formats based on our requirements. Furthermore, it can process multiple files simultaneously and provides the option of adjusting many parameters of the output file.
In addition to this, the FFmpeg tool supports diverse applications with different types of multimedia files:
- screen capturing
- video editing
- encoding and decoding of multimedia files
- creating GIFs
- extracting frames from multimedia files
Now, let’s install the FFmpeg tool locally. We can use the apt command from the Linux terminal to install it in Debian-based systems:
$ sudo apt-get install ffmpeg
Now, let’s check the installation status of FFmpeg:
$ fmpeg -version
ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
Thus, we’ve successfully installed the FFmpeg tool in the system.
Before proceeding further and starting the conversion process, we navigate to the directory where we store the FLAC file. We utilize the cd command to go to the correct directory:
$ cd /home/sam/Music/Test/
Now, we use the FFmpeg tool to convert the FLAC file to an MP3 file:
$ ffmpeg -i sample1.flac -q:a 0 -map a output1.mp3
nput #0, flac, from 'sample1.flac':
Metadata:
TITLE : The Happy Meeting
DATE : 2020
ALBUM : Samples files
ARTIST : Samples Files
track : 2
GENRE : Ambient
Duration: 00:02:00.15, start: 0.000000, bitrate: 585 kb/s
Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
Stream mapping:
Stream #0:0 -> #0:0 (flac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'output.mp3':
Metadata:
TIT2 : The Happy Meeting
TDRC : 2020
TALB : Samples files
TPE1 : Samples Files
TRCK : 2
TCON : Ambient
TSSE : Lavf58.76.100
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p
Metadata:
encoder : Lavc58.134.100 libmp3lame
size= 3590kB time=00:02:00.13 bitrate= 244.8kbits/s speed=63.6x
video:0kB audio:3590kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.010337%
In the command above, sample1.flac is the name of the FLAC file we want to convert. The option -q:a 0 indicates the highest possible audio quality for the output format. Furthermore, using the -map a option, we map the input audio stream to the output audio file. Finally, we specify the name of the output MP3 file.
The output text generated by the FFmpeg tool during the audio file conversion process provides crucial information. First, the tool analyzes the input file and furnishes metadata such as title, date, album, genre, and duration. Furthermore, it gives information on the stream mapping, output file, audio stream, and multiplexing process.
3. Using lame
lame is another command-line tool in Linux that we can use to convert FLAC audio files to MP3.
The lame tool efficiently generates high-quality MP3 audio files from any other audio format. Additionally, it enables us to set output quality and compression ratio. Furthermore, as the lame tool supports batch processing and faster conversions, it’s used in various streaming applications.
In the Debian-based systems, we can use the apt command to install the lame tool from the terminal:
$ sudo apt-get install lame
After completing the installation, let’s check the status of the tool:
$ lame --version
LAME 64bits version 3.100 (http://lame.sf.net)
Copyright (c) 1999-2011 by The LAME Project
Copyright (c) 1999,2000,2001 by Mark Taylor
Copyright (c) 1998 by Michael Cheng
Copyright (c) 1995,1996,1997 by Michael Hipp: mpglib
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
...output truncated...
Now, similar to the first approach, we navigate to the directory where we store the FLAC file:
$ cd /home/sam/Music/Test/
Finally, we can use lame to convert the FLAC file to an MP3 file:
$ lame --preset extreme sample1.flac output2.mp3
LAME 3.100 64bits (http://lame.sf.net)
polyphase lowpass filter disabled
Encoding sample1.flac to output.mp3
Encoding as 44.1 kHz j-stereo MPEG-1 Layer III VBR(q=0)
Frame | CPU time/estim | REAL time/estim | play/CPU | ETA
4601/4601 (100%)| 0:02/ 0:02| 0:02/ 0:02| 58.903x| 0:00
32 [ 0]
40 [ 0]
48 [ 0]
56 [ 0]
64 [ 0]
80 [ 0]
96 [ 0]
112 [ 0]
128 [ 0]
160 [ 0]
192 [ 73] %**
224 [1884] %%%%%%%%%%%%%%%%%%%%*********************************
256 [2427] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%***********************
320 [ 217] %%%****
-------------------------------------------------------------------------------
kbps LR MS % long switch short %
244.9 51.1 48.9 97.8 1.3 0.9
Writing LAME Tag...done
ReplayGain: +2.6dB
In this scenario, we provide sample1.flac file as input and get output2.mp3 file as output. Furthermore, we use the –preset extreme option to ensure high-quality audio output in MP3 format.
In addition to this, the output text shows various crucial information:
- version of the lame tool
- encoding information such as bit rate and sample rate
- conversion progress details
- estimation of CPU time
- bitrate distribution data
- volume normalization
Finally, after the conversion is completed, we can remove the FLAC file using the rm command to free up space. Importantly, we won’t be able to restore the original FLAC from the MP3 due to the losses.
Therefore, we successfully converted the FLAC audio file to MP3. If the original file isn’t required, we can remove it to save space in the system.
4. Conclusion
In this article, we explored two command-line methods to convert a FLAC file to MP3 format in Linux.
FFmpeg and LAME are efficient tools for converting FLAC files to MP3 format. However, FFmpeg is a comprehensive multimedia processing tool that can handle audio, video, images, and other multimedia files.
On the other hand, the lame tool is specifically developed for audio compression. Therefore, the conversion speed of the lame tool is usually higher compared to the FFmpeg tool. Also, there are often easier ways to customize the output.