Conversion mp4 to mp3 in linux
A simple script to convert mp4 to mp3 on Linux. There are two official ways of installing FFmpeg on Ubuntu: from the Ubuntu repo (v7.x) and from the snap (v4.x). Depending on your needs, you should choose the most appropriate method for you. Requirements install: sudo apt update sudo apt-get install ffmpeg Let us verify

A simple script to convert mp4 to mp3 on Linux.
There are two official ways of installing FFmpeg
on Ubuntu: from the Ubuntu
repo (v7.x) and from the snap (v4.x). Depending on your needs, you should choose the most appropriate method for you.
Requirements install:
sudo apt update sudo apt-get install ffmpeg
Let us verify whether the installation was successful. First, test the FFmpeg
version via the following command:
ffmpeg -v
Do not forget to check the available encoders and decoders. Do so by entering the following command:
ffmpeg -encoders
ffmpeg -decoders
The script that converts * .mp4
files to mp3
might look like this:
ffmpeg -i video.mp4 -f mp3 -ab 192000 -vn music.mp3
script version that converts all files from the directory:
#!/bin/bash for i in *.mp4;
do ffmpeg -i "$i" -vn -acodec libmp3lame -ac 2 -qscale:a 4 -ar 48000 "basename "$i" .mp4
.mp3";
done;
For ffmpeg
with Constant Bitrate Encoding (CBR):
ffmpeg -i video.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 audio.mp3
Variable Bitrate Encoding (VBR)
Example to encode VBR
mp3
audio with ffmpeg using the libmp3lame library:
ffmpeg -i input.wav -codec:a libmp3lame -qscale:a 2 output.mp3 ffmpeg -i video.mp4 -vn -acodec libmp3lame -ac 2 -qscale:a 4 -ar 48000 audio.mp3
Sources and links
- https://trac.ffmpeg.org/wiki/Encode/MP3
- http://wiki.hydrogenaud.io/index.php?title=LAME#Recommended_encoder_settings
- https://trac.ffmpeg.org/wiki/Encode/MP3 how to use the external libmp3lame encoding library within ffmpeg to create MP3 audio files