Skip to content

Instantly share code, notes, and snippets.

@kaleksandrov
Created May 5, 2016 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaleksandrov/58eed0d9676db0f7fec74c56a3b26631 to your computer and use it in GitHub Desktop.
Save kaleksandrov/58eed0d9676db0f7fec74c56a3b26631 to your computer and use it in GitHub Desktop.
Converts the given video file to an audio one.
#!/bin/sh
case $# in
1)
FROM="$1"
TO="$1"
;;
2)
FROM="$1"
TO="$2"
;;
*)
echo "Usage: $0 <from-folder-or-file> <optional:to-folder-or-file>"
exit 1
;;
esac
IFS=''
if ! [ -e "$FROM" ]
then
echo "The source path is invalid: $FROM"
exit 2
elif [ -d "$FROM" ]
then
FROM=$FROM/*.*
if ! [ -d "$TO" ]
then
echo "The destination file does not exists: $TO"
exit 3
fi
elif [ -f "$FROM" ]
then
FROM=$FROM
if [ -e "$TO" -a -d "$TO" ]
then
TO="$TO$(basename $FROM)"
fi
fi
for FILE in $FROM
do
SIMPLE_FILE="$(basename $FILE)"
EXTENSION="${SIMPLE_FILE##*.}"
FILENAME="${SIMPLE_FILE%.*}"
echo '------------'
ffmpeg -i "$FILE" -vn -acodec libmp3lame -ac 2 -ab 320k -ar 48000 "$TO/$FILENAME.mp3"
echo '------------'
done
unset IFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment