Sometimes we need to convert mp3 files to ogg files. Ogg is an open format and produces fairly small size files. Here are the instructions to use ffmpeg on Mac to convert mp3 files to ogg format files.
Install ffmpeg on Mac
We’ll use brew to install ffmpeg on mac:
$ brew install ffmpeg
In case you get error with brew link lame
you may have to use the following:
$ brew link --overwrite lame
Convert mp3 to ogg
Use the following command to convert foo.mp3 to foo.ogg
$ ffmpeg -y -i foo.mp3 -strict -2 -acodec vorbis -ac 2 -aq 50 foo.ogg
Batch convert multiple mp3 files to ogg
In case you want to convert multiple mp3 files present in a directory, you can use the following bash script. Save the following code to file convert_m3_to_ogg.sh
#!/bin/bash for i in *.mp3; do j=$(echo -n $i | sed -e 's/.mp3/.ogg/g') echo "converting $i to $j" ffmpeg -y -i "$i" -strict -2 -acodec vorbis -ac 2 -aq 50 "$j" done
Now cd to the desired directory run the following:
$ chmod a+x ./convert_m3_to_ogg.sh $ ./convert_m3_to_ogg.sh
This will create one .ogg file for each .mp3 file in same directory. Make sure you take a backup of your directory before running the script to be on safer side.