I am trying to minimize the typing needed to convert a mp4 to a mp3.

This is what I have been doing:

ffmpeg -i 'Borrowed Angel.mp4' -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 'Borrowed Angel.mp3'

This is what I have so far:

ffmpeg -i $1.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 $1.mp3

I think I need a macro.

But it needs an output file.

  • Write that into a file , make it executable via chmod +x , add the address of that into your $PATH environment variable (add it to the ~/.bashrc file) ,and execute it in terminal via the name you've given to that file. – Parsa Mousavi Jun 25 '20 at 20:59

You can set up a script or program to help you with this. You'll want to create a directory ~/.bin or ~/.scripts, and add it to your $PATH Environment Variable. You can do this by editing and saving the following line within ~/.bashrc, towards the end, but exact location isn't key here:

export PATH=$HOME/.bin:$PATH

Now any file within ~/.bin/ with +x (executable) access can be run after sourcing the new ~/.bashrc file (ie: in a new terminal).

touch ~/.bin/mov-dac
chmod +x ~/.bin/mov-dac

FILENAME=$(basename "${MOV// /_}" | sed 's/\(.*\)-.*/\1/').mp3
ffmpeg -i "${MOV}" -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 /tmp/"${FILENAME}"

Then, in new terminals, you can run mov-dac /path/to/My\ File.mp4 and you'll get /tmp/My_File.mp3

I prefer to keep the audio as-is, but strip it from the video file and save within that filetype/container. In additional, any track more than 15m (900s) long is added to the "Sets" album, instead of "Singles", for easier sorting. $OUTDIR is the final destination and has _Sets/ and _Singles/ within.


# @earthmeLon

MEDIAINFO=$(mediainfo "${MOV}" --Output=JSON)
FORMAT=$(echo $MEDIAINFO | jq '.[]| .track[] | select(."@type"=="Audio")| .Format' | tr '[:upper:]' '[:lower:]')
FORMAT=$(echo $FORMAT | tr -d '"')
if [ $FORMAT == "vorbis" ]; then
DURATION=$(echo $MEDIAINFO | jq '.[]| .track[] | select(."@type"=="Audio")| .Duration')
DURATION=$(echo $DURATION | tr -d '"')
if [ $DURATION -gt 900 ]; then

FILENAME=$(basename "${MOV// /_}" | sed 's/\(.*\)-.*/\1/').${FORMAT}
ffmpeg -y -i "$MOV" -vn -metadata album=$ALBUM -acodec copy /tmp/"${FILENAME}"
if [ -d ${OUTDIR}/_${ALBUM} ]; then
    cp /tmp/"${FILENAME}" ${OUTDIR}/_${ALBUM}/
    rm /tmp/"${FILENAME}"
  • Thanks. Works great. :-) – fixit7 Jun 26 '20 at 1:32
  • ~/bin is already listed in ~/.profile, so no need to edit ~/.bashrc or mess with $PATH. However, once ~/bin is created you'll either have to run source ~/.profile, or simply log out and log in for it to get recognized. – llogan Jul 10 '20 at 17:23

You can write it into a file , say mp423(mp4 to mp3 converter) and save it into a specific folder ( I personally use ~/.scripts) and then you have to add that path to the $PATH environment variable to be able to execute it directly in the terminal without mentioning the full path.So add this to your ~/.bashrc file :

export PATH=$PATH:/home/yourusername/.scripts/

And then you can run that this way :

mp423 "Borrowed Angel"

Don't forget to use the Double quotes if the name contains space because the bash will interpret that as two separate arguments.

Best regards :)

  • Package manager does not have mp423. @Parsa Mousavi – fixit7 Jun 25 '20 at 21:32
  • This is the name of your script.Could be anything else.That was just an example. Why is the repository supposed to have mp423? – Parsa Mousavi Jun 25 '20 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.