Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Minimize typing to convert mp4 to mp3

Writer Matthew Harrington

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.

1

2 Answers

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
#!/bin/bash
MOV="$*"
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.

#!/bin/bash
# @earthmeLon
MOV="$*"
OUTDIR="/mnt/DAC"
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 FORMAT="ogg"
fi
DURATION=$(echo $MEDIAINFO | jq '.[]| .track[] | select(."@type"=="Audio")| .Duration')
DURATION=$(echo $DURATION | tr -d '"')
DURATION=${DURATION%.*}
if [ $DURATION -gt 900 ]; then ALBUM="Sets"
else ALBUM="Singles"
fi
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}"
fi
2

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 :)

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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