MPEG-4 video file format, commonly known as MP4, is one of the most common media formats used for video files. It’s a highly versatile video extension that supports audio, images, and subtitles all together in one file.
Once in a while, you might want to convert your MP4 video files to MP3 audio files. MP3, which stands for “MPEG Audio Layer-3,” is one of the most common audio formats used for music playback.
Why do we need to convert from MP4 to MP3?
One of the reasons one might need to convert MP4 to MP3 is because most audio software and digital audio players support the MP3 format. Thus, carrying a USB Drive containing MP3 audio files is much more flexible because you can easily find an audio player that supports it. Additionally, MP4 files can be quite large due to the images compared to the same MP3 version, so if you just want to listen while working, there is no need to play the video file.
What you will need:
In this post, we will look at both the command-line and graphical methods. Some of the tools we will use include:
- FFmpeg
- Lame
- Sound converter
Convert MP4 to MP3 with FFmpeg
FFmpeg is a free and open-source project loaded with various libraries and programs necessary to handle multiple media files and streams. It is one of the most popular multimedia frameworks used for decoding, encoding, mux, demux, filtering, and transcoding various multimedia file formats. Lame, on the other hand, it’s one of the best MP3 encoders available.
We will use FFmpeg and Lame together to perform the conversion. FFmpeg will extract the audio from the MP4 files, and Lame will encode it to the MP3 format. To get started, let’s first install these two packages in our system. Choose your Linux distribution below and execute the installation commands.
-
Ubuntu / Debian
sudo apt -y install ffmpeg lame
-
Arch Linux
sudo pacman -S lame ffmpeg
-
CentOS 7
sudo yum -y install epel-release sudo rpm -v --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm sudo yum install ffmpeg ffmpeg-devel lame
-
Fedora
sudo yum -y install epel-release sudo rpm -v --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm sudo yum install ffmpeg ffmpeg-devel lame
Convert MP4 to MP3
Once you have FFmpeg and Lame installed, you can now start converting your MP4 files. The general syntax that we will use is:
ffmpeg -i <input-file.mp4> -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 <output-file.mp3>
Now, let’s look at a practical example. We will convert the MP4 file – “Fosslinux-Video.mp4” on our Desktop to “Converted.mp3.” We will execute the command below on our Terminal.
ffmpeg -i Fosslinux-Video.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 Converted.mp3
Let’s look at some of the arguments present in the command above;
- -i: The input file name
- -vn: Disable video recording
- -acodec: This forces audio encoding to libmp3lame
- -ac: Sets the number of audio channels
- -ar: Sets the audio sampling frequency
We will execute the ls
command to see whether the conversion was successful. Please take a look at our post on 13 ways to use the ls command to list files on Linux, which will give you some of the advanced ways to use the ls command.
ls *.mp3 *.mp4
From the image above, we can see that we have successfully converted our MP4 file to MP3. I have tested it on the VLC media player, and it worked fine.
If you are a command-line / Terminal fan, then that’s one way you can use to convert your MP4 files to MP3. For those who don’t like the hustle of executing multiple commands on the Terminal, don’t worry; we have got you covered in our next section. Here we will convert our MP4 files to MP3 using graphical tools.
Convert MP4 to MP3 with Sound-Converter
Sound Converter is a popular graphical converter tool available for the GNOME Desktop. It supports many media formats including gg Vorbis, AAC, MP3, FLAC, WAV, AVI, MPEG, MOV, M4A, AC3, DTS, ALAC, MPC, Shorten, APE, SID, MOD, XM, S3M, etc…) and can also write WAV, FLAC, MP3, AAC, and Ogg Vorbis files.
Sound Converter is an open-source tool available for most Linux distribution from the Software Center or installs it with your distribution package manager.
For Ubuntu and Debian users, install the Sound Converter with the command below:
sudo apt install soundconverter
If the commands complete successfully, you should launch the sound converter from the applications menu.
It has a relatively simple window with only a few buttons and options at the top. Our primary interest will be the Convert button, the Add file button, and the Settings option, represented with a gear icon.
To get started with Sound-converter, we first need to add the MP4 files we need to convert. Click on the Add File button (next to the Convert option at the top-left). The file manager will open, and you can select the MP4 file to convert. Once you have chosen your file, you should see it listed as shown below.
Now we need to select the output format. In our case, it’s MP3. Click on the Gear icon to open the Settings window. You can use many more options, but we will only set the MP3 format for this tutorial.
Once you have selected the output format, close the Settings window and click the Conver button to convert your MP4 file to MP3. You can check the progress at the bottom of the window, and you also have an option to PAUSE or CANCEL the process.
Sound-converter uses a multi-threaded design to convert the files, and it’s therefore fast and efficient. The video selected above is about 5.7MB but only took 4 seconds to convert.
Conclusion
That’s a complete guide on how you can convert your MP4 files to MP3 on a Linux system. Which another way/tool do you use to convert your files? Please feel free to share with our readers below. If you come across any errors executing any of the commands above, let us know in the comment section.
With the FFmpeg tool, if you have many files to convert, you can write a bash script to automate the whole process. Our complete Beginners guide to Bash scripting will help you in getting started with Bash. Check it out.
1 comment
That is great. To convert MP4 to MP3 on Mac and Windows, Avdshare Audio Converter also works.