Skip to content

Instantly share code, notes, and snippets.

@romanlv
Last active February 17, 2016 09:50
Show Gist options
  • Save romanlv/2495704 to your computer and use it in GitHub Desktop.
Save romanlv/2495704 to your computer and use it in GitHub Desktop.
extract audio from mp4 files and convert it to mp3 format
#!/bin/bash
#
# extracts audio from all videos in current folder and saves in mp3
# based on http://ubuntuforums.org/showthread.php?t=1411144
#
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for i in `find . -type f -iname "*.avi" -print`; do
echo $i
NAME=`echo $i | sed -e 's/\.\///' -e 's/\.avi//g' `
echo "doing '$NAME'"
vout=mp3s/${NAME}.mp3
if [ ! -f $vout ]; then
echo 'converting to mp3'
mencoder -of rawaudio -ovc copy -oac mp3lame -o "${vout}" "${NAME}".avi
fi
done
IFS=$SAVEIFS
#extracts audio from mp4 files
#assumes that audio is in acc (m4a) format and converts it to mp3
#mp4 audio format can be checked with ffmpeg -i fss1.mp4
mkdir -p mp3s
mkdir -p m4a
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for i in `find . -type f -iname "*.mp4" -print`; do
echo $i
NAME=`echo $i | sed -e 's/\.\///' -e 's/\.mp4//g' `
echo "doing '$NAME'"
if [ ! -f m4a/${NAME}.m4a ]; then
ffmpeg -i $i -vn -acodec copy m4a/${NAME}.m4a
fi
if [ ! -f mp3s/${NAME}.mp3 ]; then
echo 'converting to mp3'
faad --stdio m4a/${NAME}.m4a | lame --preset standard - "mp3s/${NAME}.mp3"
fi
done
IFS=$SAVEIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment