FFmpeg Tutorial: Batch Convert MP3 to OGG Audio Format

OGG is an open-source, patent-free audio format that typically offers better sound quality at the same compression rate compared to MP3. This article will show you how to quickly convert MP3 files to OGG format using FFmpeg.

This guide is brought to you by filethings.net — let's dive in.

Basic Conversion Command

The most basic conversion command is as follows:

ffmpeg -i input.mp3 -c:a libvorbis output.ogg

This command reads the input.mp3 file, converts it to OGG format using the libvorbis encoder, and saves it as output.ogg.

Optimized Conversion Parameters

For more precise control, you can add the following parameters:

ffmpeg -i input.mp3 -ar 48000 -q:a 5 -vn -c:a libvorbis output.ogg

Parameter explanations:

Batch Converting Multiple Files

If you need to convert multiple MP3 files, you can use a shell script for batch processing:

for file in *.mp3; do
  ffmpeg -i "$file" -c:a libvorbis "${file%.mp3}.ogg"
done

Common Issues

  1. Sample Rate Errors: If you encounter sample rate mismatch errors during conversion, adding the -vn parameter usually resolves the issue.

  2. Quality Adjustment: OGG quality is controlled by the -q:a parameter, ranging from 0 (worst) to 10 (best). For most purposes, values between 5-7 provide a good balance between quality and file size.

  3. File Size: OGG files are typically 10-15% smaller than MP3 files of comparable quality, though actual size depends on source file quality and conversion parameters.


References: