Skip to content

Instantly share code, notes, and snippets.

@deoren
Created January 22, 2018 03:46
Show Gist options
  • Select an option

  • Save deoren/21baaa9e7b208b7fe144ef698765cfdc to your computer and use it in GitHub Desktop.

Select an option

Save deoren/21baaa9e7b208b7fe144ef698765cfdc to your computer and use it in GitHub Desktop.
Convert video files to MP3, OGG format
# Bash script that uses mplayer and oggenc to rip and encode the audio from
# various movie formats to Ogg Vorbis and MP3. I assume I wrote it based
# off of the poor quality. ;)
# Remove movie file after rip/encode (1=YES, 0=NO)
REMOVE_MOVIE="0"
# Remove wav file after encode (1=YES, 0=NO)
REMOVE_WAV="1"
# Specify quality between 0 (low) and 10 (high) or leave blank for default
OGG_OUTPUT_QUALITY="1"
# Specify quality between 0 (high) and 9 (low) or leave blank for default
MP3_OUTPUT_QUALITY="9"
# (1=YES, 0=NO)
CREATE_OGG_FILE="1"
# (1=YES, 0=NO)
CREATE_MP3_FILE="1"
for i in `find . | grep -i ".wmv\|.rm\|.ram\|.avi"`
do
PREFIX=`echo $i | sed 's#./##' | tr 'A-Z' 'a-z' | cut -f 1 -d "."`
# Dump to .wav file
mplayer -ao pcm $i -ao pcm:file=${PREFIX}.wav -vc dummy -vo null
if [ ${CREATE_OGG_FILE} = "1" ]
then
# Create .ogg file
if [ ! ${OGG_OUTPUT_QUALITY} ]
then
oggenc ${PREFIX}.wav -o ${PREFIX}.ogg
else
oggenc ${PREFIX}.wav -q ${OGG_OUTPUT_QUALITY} -o ${PREFIX}.ogg
fi
fi
if [ ${CREATE_MP3_FILE} = "1" ]
then
# Create .ogg file
if [ ! ${MP3_OUTPUT_QUALITY} ]
then
# Create .mp3 file
lame ${PREFIX}.wav ${PREFIX}.mp3
else
lame -V ${MP3_OUTPUT_QUALITY} ${PREFIX}.wav ${PREFIX}.mp3
fi
fi
if [ ${REMOVE_WAV} = "1" ] && [ $? = 0 ]
then
rm -f ${PREFIX}.wav
fi
if [ ${REMOVE_MOVIE} = "1" ] && [ $? = 0 ]
then
rm -f $i
fi
done
@deoren
Copy link
Author

deoren commented Jan 23, 2018

As of the time this Gist entry was created, GitHub does not support notifications for comments for mentions to Gist entries (see isaacs/github#21 for details). Please contact me via Twitter or file an issue in the deoren/leave-feedback repo (created for that very purpose) if you wish to receive a response for your feedback. Thank you in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment