Convert mp4 to mp3 in Linux Terminal

· · 221 words · 2 minute read

First things first, install the required software packages. Most Linux distros ship with FFmpeg pre-installed but to ensure the required packages are installed, run this command anyway.

sudo apt install ffmpeg && sudo apt install libavcodec-extra-53

After installation, let’s use it to convert mp4 video file into mp3 audio file.

For FFmpeg with Constant Bitrate Encoding (CBR), use this command.

ffmpeg -i video.mp4 -vn \
       -acodec libmp3lame -ac 2 -ab 160k -ar 48000 \
        audio.mp3

If you want to use Variable Bitrate Encoding (VBR), use this command.

ffmpeg -i video.mp4 -vn \
       -acodec libmp3lame -ac 2 -qscale:a 4 -ar 48000 \
        audio.mp3

If it says ffmpeg is depricated or ffmpeg: command not found which is the case in old Ubuntu distros, so, use this command instead.

avconv -i video.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 audio.mp3

The meaning of arguments

argvmeaning
-iinput file name
-vndisable video recording
-acodecforce audio codec to libmp3lame
-acset the number of audio channels
-arset the audio sampling frequency

I hope this post helps you. If you know a person who can benefit from this information, send them a link of this post. If you want to get notified about new posts, follow me on YouTube , Twitter (x) , LinkedIn , Facebook , Telegram and GitHub .

Share: