Go to content
.

From time to time I need to convert audio files from some kind of audio format into a MP3 file with variable bitrate (VBR). The easiest way to convert audio files, without having to search and install a GUI application, is ffmpeg. Ffmpeg can do everything related to audio and video files, which is a blessing and a curse and I always end up having to search for the correct arguments.

This time I was smart enough to save the correct incantation as a Fish function:

function mp3convert
  for f in $argv
    command ffmpeg -i "$f" -codec:v copy -codec:a libmp3lame -q:a 2 (string replace -r '\.[a-zA-Z0-9]+$' ".mp3" "$f");
  end
end

mp3convert takes either a single file or a list of files and converts them into a variable bitrate MP3 in high quality and it replaces the extension from whatever the input format is to .mp3. Here are a couple of ways mp3convert can be run:

mp3convert my-file.wav
mp3convert my-file-1.wav my-file-2.m4a
mp3convert *.m4a