Converting between music file formats with ffmpeg
ffmpeg is a much venerated tool for doing most anything in the world of fiddling around with audio and video files on one’s computer. To let it describe itself:
FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation.
It also works on Linux, Windows, MacOS and a few other platforms you probably aren’t using. There are slightly less official ways to use it on iOS (e.g. via a-Shell) and Android (e.g. via Termux)
So far my main use-case has been to convert between music file formats. For future referenece, this is how one can convert a song from flac format to, in this case, MP3 V0. Sure you in theory lose some quality converting lossless to lossy, but the way I listen to music it really isn’t very noticable and it dramtaically saves diskspace. One example file I used went from 42mb to 8mb.
It’s simple. First install ffmpeg. On Linux that’s:
sudo apt install ffmpeg
Then you can convert a flac to a variable bit rate (VBR) MP3 (amongst a massive variety of other formats) in the following way:
ffmpeg -i your_music_file.flac -c:a libmp3lame -q:a 0 your_music_file.mp3
The -c parameter is the encoder you want to use, in this case one for MP3s.
-q refers to the audio quality. The 0 setting is the highest quality for a (VBR) MP3 but slowest to run. But it took virtually no time at all for me.
If you prefer a fixed rate MP3, e.g. 320kps, you can use the -b parameter instead of -c like:
ffmpeg -i your_music_file.flac -c:a libmp3lame -b:a 320k your_music_file.mp3
If you want to convert all flacs in a folder to MP3s at once then you can use standard Linux CLI stuff, e.g. the below for the VBR option.
for f in *.flac; do ffmpeg -i "$f" -c:a libmp3lame -q:a 0 "${f%.flac}.mp3"; done
There are innumerable other parameters for different file formats or different options. The official documentation is one place to go to learn about them all.