Linux Basics: How To Convert Mp4 To MP3
Why do we need to convert from MP4 to MP3?
It saves spaces in our devices, and some of the basic model devices are not supported with mp4 extension. In this example, we are going to use ffmpeg to convert MP4 to MP3.
FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec – the leading audio/video codec library.
Install ffmpeg On Ubuntu
sudo apt-get install ffmpeg libavcodec-extra-53
Converting MP4 to MP3
ffmpeg -i filename.mp4 filename.mp3
Find out the more options of this command with man page. (man ffmpeg)
ffmpeg -i filename.mp4 -b:a 192K -vn filename.mp3
A stream specifier can match several stream, the option is then applied to all of them. E.g. the stream specifier in “-b:a 128k” matches all audio streams.
The following script is going to convert all file with extension .mp4 in the folder Music to .mp3.
#!/bin/bash MP4FILE=$(ls ~/Music/ |grep .mp4) for filename in $MP4FILE do name=`echo "$filename" | sed -e "s/.mp4$//g"` ffmpeg -i ~/Music/$filename -b:a 192K -vn ~/Music/$name.mp3 done