Convert audio files with ffmpeg

Here is a quick primer how to convert all files within a directory form one audio format to another one

1 Min. Lesezeit

The Problem

I have downloaded a youtube play list and wanted to listen to all the files on my mobile phone. Unfortunately my phone is not capable to play *.opus files. So i had to convert them.

The Solution

It is fairly easy to convert the files with ffmpeg.If you have only a few files then you can do this one by one at the commandline with the following statement:

$ ffmpeg -i myDownloadedFile.opus -f mp3 targetfilename.mp3

It converts the myDownloadedFile.opus into targetfilename.mp3.

So far so good - but i had multiple (200+) files within the same directory. So converting each one by hand would be a tedious job. I came up with the following solution:

$ for i in *.opus; do ffmpeg -i "$i" -f mp3 "${i%}.mp3"; done

This statement searches within the current directory for all *.opus files and converts them to mp3 files. The name is the same as the opus filename, but with the postfix .mp3 appended.

Happy coding