Monday, August 18, 2014

Converting mp4 to mp3 in Linux

Link.


To convert Upd_Sanity.mp4 to Upd_Sanity.mp3

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

$ ffmpeg -i Upd_Sanity.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 Upd_Sanity.mp3
OR (as ffmpeg is deprecated)
$ avconv -i Upd_Sanity.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 Upd_Sanity.mp3

Description

   -i        input file name
   -vn       disable video recording
   -acodec   force audio codec to libmp3lame
   -ac       set the number of audio channels
   -ar       set the audio sampling frequency

If you need to use it frequently,

STEP 1 : Create a bash function that performs conversion
## utilities.sh
convertMP4toMP3(){
echo -n "Enter source mp4 file : "
read sourceFile

echo -n "Enter destination mp3 file : "
read destFile

avconv -i $sourceFile -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 $destFile
}
STEP 2 : source that bash file
 $ source utilities.sh
STEP 3 : start conversion calling above function convertMP4toMP3
 $ convertMP4toMP3
 Enter source mp4 file : Upd_Sanity.mp4
 Enter destination mp3 file : UPd_sanity.mp3

No comments:

Post a Comment