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