Skip to content

Instantly share code, notes, and snippets.

@starkers
Last active August 29, 2015 14:01
Show Gist options
  • Save starkers/a65841022490cbab7846 to your computer and use it in GitHub Desktop.
Save starkers/a65841022490cbab7846 to your computer and use it in GitHub Desktop.
Convert any flv/mp4 and pretty much anything into .mp3
#!/usr/bin/env bash
# any2mp3
# Converts to mp3 anything mplayer can play
# requires: mplayer and lame
# Also ensure you have space to dump the .wav
TMP=audiodump-`date +%s`.wav
[ "$1" ] || { echo "Usage: $0 file1.wma file2.mp4"; exit 1; }
for i in "$@"
do
[ -f "$i" ] || { echo "File $i not found!"; exit 1; }
done
[ -f "$TMP" ] && {
echo "file "$TMP" already exists"
exit 1
}
for i in "$@"
do
ext=`echo "$i" | sed 's/[^.]*\.\([a-zA-Z0-9]\+\)/\1/g'`
j=`basename "$i" ".$ext"`
j="$j.mp3"
echo
echo -n "Extracting $TMP from $i... "
mplayer -vo null -vc null -af resample=44100 -ao pcm:waveheader:fast:file="$TMP" \
"$i" >/dev/null 2>/dev/null || {
echo "Problem extracting file $i"
exit 1
}
echo "done!"
echo -n "Encoding to mp3... "
lame -v -m s "$TMP" -o "$j" && rm "$i"
echo "done!"
echo "File written: $j"
done
# delete temporary dump file
rm -f "$TMP"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment