Bash ffmpeg flac wav mp3 conversion

Converting FLAC (WAV) Files to MP3 Using ffmpeg in Bash

This article introduces how to convert flac(wav) files to mp3 using ffmpeg from the command line in Bash on Linux computers and servers.

Shou Arisaka
2 min read
Nov 23, 2025

This article introduces how to convert flac(wav) files to mp3 using ffmpeg from the command line in Bash on Linux computers and servers.

Recently, when I go out, I’ve been streaming music from my owncloud server, but whether it’s because the Rakuten Mobile SIM provider isn’t good, or something else, when it’s flac, it frequently cuts out even with high-speed communication. So I thought if I reduce the data size, I can at least listen.

It feels a bit counterproductive since I’m using a player that can play hi-res, but since it’s outside with noise, no amp, and Bluetooth anyway, I thought there’s probably no difference between flac and mp3.

Actually, listening to music in flac consumes quite a bit of data. About 200mb in 20 minutes or so, which is fatal for me with a monthly limit of 2gb. It’s a huge difference from soundcloud.

Image

flactomp3(){
  : copy all of flac or other highres audio on current dir as mp3

  for i in *.+(flac|wav|wave); do ffmpeg -i "$i" -b:a ${1:-320k} -acodec libmp3lame "$(basename "${i/.flac}").mp3" ; done

}

If you write the above in .bashrc,

flactomp3 128k

By specifying the bitrate as an argument and executing, it expands as:

for i in *.+(flac|wav|wave); do ffmpeg -i "$i" -b:a 128k -acodec libmp3lame "$(basename "${i/.flac}").mp3" ; done

The ffmpeg options are:

-i : input file
-b:a : bitrate
-acodec : audio codec

Audio codecs include:

libmp3lame : mp3
libvorbis : ogg
libfdk_aac : aac

You can check audio codecs with:

ffmpeg -codecs

Also,

ffmpeg -i input.flac -acodec libmp3lame -aq 2 output.mp3

Using the -aq option like this, you can specify quality without specifying bitrate.

Quality ranges from 0 (highest) to 9 (lowest).

That’s all.

Share this article

Shou Arisaka Nov 23, 2025

🔗 Copy Links