2020-02-23 07:31:15 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
# Description: Extract audio from multimedia files and convert to mp3
|
|
|
|
#
|
2021-05-15 17:32:01 +00:00
|
|
|
# Dependencies: ffmpeg compiled with libmp3lame audio codec support
|
2020-02-23 07:31:15 +00:00
|
|
|
#
|
|
|
|
# Shell: POSIX compliant
|
|
|
|
# Author: Arun Prakash Jana
|
|
|
|
|
|
|
|
outdir=_mp3files
|
|
|
|
|
|
|
|
handle_multimedia() {
|
|
|
|
mime="${1}"
|
|
|
|
file="${2}"
|
|
|
|
|
|
|
|
case "${mime}" in
|
|
|
|
audio/* | video/*)
|
2020-02-23 09:53:39 +00:00
|
|
|
ffmpeg -i "${file}" -vn -codec:a libmp3lame -q:a 2 "${outdir}/${file%.*}.mp3"
|
2020-02-23 07:31:15 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2020-02-23 09:26:51 +00:00
|
|
|
printf "Process 'a'll in directory or 'c'urrent? "
|
|
|
|
read -r resp
|
|
|
|
|
|
|
|
if [ "$resp" = "a" ]; then
|
|
|
|
if ! [ -e "${outdir}" ]; then
|
|
|
|
mkdir "${outdir}"
|
2020-02-23 07:31:15 +00:00
|
|
|
fi
|
2020-02-23 09:26:51 +00:00
|
|
|
|
|
|
|
for f in *; do
|
|
|
|
if [ -f "${f}" ]; then
|
|
|
|
mimestr="$( file --dereference --brief --mime-type -- "${f}" )"
|
|
|
|
handle_multimedia "${mimestr}" "${f}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
elif [ "$resp" = "c" ] && [ -f "$1" ]; then
|
|
|
|
ffmpeg -i "${1}" -vn -codec:a libmp3lame -q:a 2 "${1%.*}.mp3"
|
|
|
|
fi
|