Created
August 19, 2017 23:58
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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