Skip to content

Instantly share code, notes, and snippets.

@austinhappel
Last active May 14, 2021 15:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save austinhappel/6169842 to your computer and use it in GitHub Desktop.
Save austinhappel/6169842 to your computer and use it in GitHub Desktop.
Converts wav, ogg, mp3 to al html5-friendly formats: wav, ogg, mp3. Requires ffmpeg to be installed globally and available via `ffmpeg`.

Audio converter

A simple wrapper for ffmpeg that will convert a folder of sound files to ogg, wav and mp3.

Requirements

ffmpeg: You can port/apt-get/brew install this.

usage

  $ cd /path/to/folder/of/files
  $ sh /path/to/convertAudio.sh

... follow the instructions

Strip off the file extension and add it in your $PATH so you can just run convertAudio from anywhere!

#!/bin/bash
printf "This baby converts your folder of .wav, .ogg, and .mp3 files into all the formats needed for HTML5 audio!\n\n"
printf "Usage: cd /folder/to/files && sh path/to/convertAudio.sh\n\n"
printf "Defaults to 128k bitrate.\n\n"
echo "Choose what format are your files in:"
echo "1) wav"
echo "2) ogg"
echo "3) mp3"
read selection
if [[ $selection != *[!1-3]* ]]; then
echo ""
else
echo "ERROR: Must choose an option (1-3)"
exit;
fi
case $selection in
1)
ext1='.wav'
ext2='.ogg'
customFlags2='-acodec libvorbis '
ext3='.mp3'
customFlags3=''
;;
2)
ext1='.ogg'
ext2='.mp3'
ext3='.wav'
;;
3)
ext1='.mp3'
ext2='.wav'
customFlags2=''
ext3='.ogg'
customFlags3='-acodec libvorbis '
;;
esac
ls | grep "$ext1" | sed s/\.[^\.]*$// | xargs -I {} ffmpeg -i {}"$ext1" -ab 128k $customFlags2 {}"$ext2"
ls | grep "$ext1" | sed s/\.[^\.]*$// | xargs -I {} ffmpeg -i {}"$ext1" -ab 128k $customFlags3 {}"$ext3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment