1. Introduction

The Ogg format is a container for storing audio, video, and related metadata. It uses the Vorbis audio compression scheme specially designed for Ogg. Overall, Ogg Vorbis is a completely free, open, and unpatented audio compression format.

In this tutorial, we’ll learn how to convert audio from the Ogg to the MP3 format in Linux.

2. Environment Setup

Before we dive into the details, let’s ensure the necessary prerequisites are ready, including the mediainfo tool and a couple of sample audio files in the Ogg format.

2.1. Sample Audio

First, we create a new directory and download the Ogg files using wget:

$ mkdir audio && cd audio
$ wget -q -O file1.ogg https://freetestdata.com/wp-content/uploads/2021/09/Free_Test_Data_100KB_OGG.ogg
$ wget -q -O file2.ogg https://freetestdata.com/wp-content/uploads/2021/09/Free_Test_Data_500KB_OGG.ogg

The mkdir command creates an audio directory, while the cd command changes the current directory to the newly created audio directory.

The -q flag in the wget command suppresses the output, while -O specifies the output filename.

Thus, we have two Ogg files (file1.ogg and file2.ogg) inside the audio directory.

2.2. MediaInfo Installtion

MediaInfo is a command-line utility to extract and display media file metadata. This utility isn’t pre-installed on most Linux distributions.

So, let’s proceed with the installation:

$ sudo apt install mediainfo

Now, we can check the installed version of MediaInfo:

$ mediainfo --version
MediaInfo Command line, 
MediaInfoLib - v21.09

As we can see, the installed version of MediaInfo is v21.09.

Next, we can check the multimedia files and their metadata:

$ mediainfo file1.ogg
General
Complete name                            : file1.ogg
Format                                   : Ogg
File size                                : 101 KiB
Duration                                 : 4 s 949 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 167 kb/s

Audio
ID                                       : 14380 (0x382C)
Format                                   : Vorbis
Format settings, Floor                   : 1
Duration                                 : 4 s 949 ms
Bit rate mode                            : Variable
Bit rate                                 : 160 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 44.1 kHz
Compression mode                         : Lossy
Stream size                              : 96.7 KiB (96%)
Writing library                          : libVorbis (Omnipresent) (20120203 (Omnipresent))

The output of the mediainfo command is divided into two parts – General and Audio. If working with video files, a Video section shows the relevant data.

The file1.ogg file is in the Ogg container format, whereas the audio stored in the file has the Vorbis format. Generally, the format in all parts is the same for most other formats, i.e., MPEG Audio for MP3.

3. FFmpeg

FFmpeg is a powerful multimedia framework and toolset, famous for its command-line capabilities.

3.1. Installation

Let’s check whether we have FFmpeg installed on the system:

$ ffmpeg -version
ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
...

In case it’s not already available, we can usually install FFmpeg via a local package manager such as apt:

$ sudo apt install ffmpeg

This command installs the FFmpeg framework including tools like ffplay and ffprobe.

3.2. Format Conversion

The FFmpeg tool re-encodes any input media by default. Thus, the format conversion with FFmpeg is usually quite straightforward.

Let’s give it a try:

$ ffmpeg -i file1.ogg file1_ffmpeg.mp3

This command takes an input (-i) file, file1.ogg, and converts it to an MP3 file, file1_ffmpeg.mp3. Additionally, we can use the -y option to overwrite output files without any prompts.

3.3. Format Verification

Let’s verify the format of the resulting file:

$ mediainfo file1_ffmpeg.mp3

The output confirms the MPEG Audio format with the Layer 3 format profile, i.e., MP3.

Moreover, we can even play this output file using ffplay:

$ ffplay -nodisp -autoexit file1.ogg

This command plays the track without any graphical display (-nodisp) and exits automatically (-autoexit) once the track is finished.

4. SoX

SoX (Sound eXchange) is an open-source command line utility supporting various audio processing tasks.

4.1. Installation

SoX doesn’t provide libraries for encoding and decoding MP3 data due to patent restrictions. Thus, we may need to install the libraries supporting the encoding and decoding of MP3 separately.

So, let’s install SoX and an MP3 encoder:

$ sudo apt install -y sox libsox-fmt-mp3

This command installs SoX with mp3 support (libsox-fmt-mp3).

So, let’s verify the installation by running the sox command:

$ sox --version
sox:      SoX v14.4.2

Thus, we see that the version of sox currently installed on the system is v14.4.2.

4.2. Format Conversion

In its simplest form, the format conversion via SoX is similar to the cp command, where we can specify an input file followed by the output file:

$ sox file1.ogg file1_sox.mp3

This command takes the input file (file1.ogg), decodes the audio data from Ogg format, processes and encodes it into the MP3 format (file1_sox.mp3).

Moreover, we can set the verbosity level to 3 (-V3) to see details about the processing during the format conversion.

5. LAME

LAME, short for LAME Ain’t an MP3 Encoder, is a high-quality MP3 encoder.

5.1. Installation

We can install LAME using most native package managers:

$ sudo apt install lame

Let’s verify the installation:

$ lame --version
LAME 64bits version 3.100 (http://lame.sf.net)
...

In this case, the installed version is 3.100.

5.2. Format Conversion

Let’s quickly convert file1.ogg to an MP3 file:

$ lame file1.ogg file1_lame.mp3

This command converts the Ogg audio data to MP3 audio and writes it to the given output filename, i.e., file1_lame.mp3.

Additionally, we can set the quality of VBR (variable bit rate) with the -V option, where 0 represents the highest quality and 9 represents the lowest quality.

We can also mark an MP3 file as copyright-protected (-c) or non-original (-o).

6. SoundConverter

As the name suggests, SoundConverter is an audio file converter. It is specifically designed for the GNOME desktop.

6.1. Installation

First, let’s install soundconverter:

$ sudo apt install soundconverter

As usual, this command installs the soundconverter tool on the system.

Now, we can retrieve the version number by not providing any parameters:

$ soundconverter 
soundconverter 4.0.3

This command prints the version and opens the SoundConverter GUI (graphical user interface).

Additionally, we can also check the version from the GUI by clicking on the About button from the menu.

SoundConverter Version from GUI

Next, let’s perform a conversion.

6.2. Format Conversion

SoundConverter provides both the command-line and graphical user interfaces.

In this case, we focus on the command-line interface:

$ soundconverter -b file1.ogg -f "mp3" -o ./

This command uses batch mode with the command-line interface (-b) to convert the input Ogg file to the MP3 format.

The -f option specifies the output format, in this case, mp3. The output path is set using the -o (–output) option. By default, SoundConverter replaces the file extension (suffix) of the input file with the new extension specified for the output file.

6.3. Multiple File Processing

Additionally, we can convert multiple files at the same time with the batch mode (-b):

$ soundconverter -b ./*ogg -f "mp3" -o ./

This command converts all Ogg files from the current directory to MP3 files.

Additionally, we can set soundconverter to overwrite files with the -e overwrite option.

7. ogg2mp3

ogg2mp3 is a Bash shell script developed specifically to convert the Ogg files to MP3 format.

7.1. Installation

Let’s fetch the ogg2mp3 shell script from its Google Code Archive:

$ wget -q https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/ogg2mp3/ogg2mp3
$ chmod +x ogg2mp3

Thus, we download the shell script and modify it to be executable.

Then, we can move the executable ogg2mp3 file to the bin directory, i.e., /usr/local/bin/, for easier access:

$ sudo mv ogg2mp3 /usr/local/bin/

Now, we should be able to use the ogg2mp3 command from anywhere on the system.

We can retrieve the system version of ogg2mp3 by printing the –help message:

$ ogg2mp3 --help
ogg2mp3 version 0.4 
Bulk transcoding of OGG Vorbis to MP3.
...

In this case, the installed version of ogg2mp3 is 0.4.

7.2. Format Conversion

ogg2mp3 takes a list of input files (Ogg), decodes the audio with the oggdec library, processes it, and encodes the MP3 audio with LAME.

Let’s convert both Ogg files to MP3:

$ ogg2mp3 ./file1.ogg file2.ogg

This command converts both the input files to the MP3 format, resulting in file1.mp3 and file2.mp3.

We can increase the verbosity of the operation via the –verbose flag. Additionally, we can also change the stereo mode using the –mode (-m) option.

7.3. Verification

Let’s check the format of one of the output files with mediainfo:

$ mediainfo file2.mp3
General
Complete name                            : file2.mp3
Format                                   : MPEG Audio
File size                                : 521 KiB
Duration                                 : 26 s 122 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 163 kb/s
Writing library                          : LAME3.100

Audio
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 3
Format settings                          : Joint stereo / MS Stereo
Duration                                 : 26 s 122 ms
Bit rate mode                            : Variable
Bit rate                                 : 160 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 44.1 kHz
Frame rate                               : 38.281 FPS (1152 SPF)
Compression mode                         : Lossy
Stream size                              : 520 KiB (100%)
Writing library                          : LAME3.100
Encoding settings                        : -m j -V 4 -q 3 -lowpass 17.5 --abr 160

Notably,  the writing library is LAME3.100.

8. Conclusion

In this article, we learned how to convert audio from Ogg to the MP3 format in Linux.

First, we installed and tested MediaInfo to verify the format for both the sample and output files. Then, we used FFmpeg to convert the audio from Ogg to MP3. We also used SoX and LAME to convert the same files.

Then, we discussed the command-line usage of SoundConverter for performing a similar conversion in batch mode. Finally, we used ogg2mp3 to convert multiple audio files from Ogg to the MP3 format in a single command.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments