Skip to content

Instantly share code, notes, and snippets.

@jmpinit
Created August 19, 2017 23:58
Show Gist options
  • Select an option

  • Save jmpinit/07c91f91139a49bf65b433cd38aface7 to your computer and use it in GitHub Desktop.

Select an option

Save jmpinit/07c91f91139a49bf65b433cd38aface7 to your computer and use it in GitHub Desktop.
Bash script to find and convert WAV files to MP3s to reduce space.
#!/bin/bash
# Converts every WAV file found to MP3 and deletes the original WAV file
set -o errexit
SAMPLE_RATE=44100
BITRATE=192k
WAVS=$(find . -name "*.wav")
IFS=$'\n'
for wavFile in $WAVS; do
DIRECTORY=$(dirname "$wavFile")
SONG_NAME=$(basename "$wavFile" .wav)
MP3_FILE="$DIRECTORY/$SONG_NAME".mp3
if [ ! -f "$MP3_FILE" ]; then
# -vn excludes any video content
# -ac sets number of audio channels
ffmpeg -i "$wavFile" -vn -ar "$SAMPLE_RATE" -ac 2 -ab "$BITRATE" -f mp3 "$MP3_FILE"
else
echo "$MP3_FILE already exists. Only deleting WAV source."
fi
rm "$wavFile"
done
unset IFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment