Convert FLAC to MP3 with FFmpeg Bash Loop

Converting a batch of FLAC audio files to MP3 format on Linux can be efficiently automated using a simple Bash for loop combined with FFmpeg. This method allows you to process an entire folder of music quickly, preserving metadata like titles and artists while optimizing the files for broader device compatibility. By utilizing the terminal, you avoid the need for heavy graphical software and gain precise control over the output audio quality.

Before running the command, you need to ensure you have FFmpeg installed on your Linux system. You can verify this or install it using your distribution’s package manager, such as sudo apt install ffmpeg on Debian/Ubuntu-based systems or sudo dnf install ffmpeg on Fedora.

The Core Bash Command

To convert all FLAC files in your current working directory to high-quality MP3s, open your terminal and run the following single-line command:

for file in *.flac; do ffmpeg -i "$file" -qscale:a 0 "${file%.flac}.mp3"; done

Breaking Down the Loop

Understanding how this command works makes it easier to customize for your specific needs:

Alternative: Using Constant Bitrate (CBR)

If you prefer a constant bitrate over a variable one—for instance, a standard 320 kbps encode—you can modify the audio codec flags slightly:

for file in *.flac; do ffmpeg -i "$file" -b:a 320k "${file%.flac}.mp3"; done

In this variation, -b:a 320k explicitly tells FFmpeg to force a constant audio bitrate of 320 kilobits per second for the output MP3 files.