Skip to content

Instantly share code, notes, and snippets.

@rhietala
Created June 26, 2017 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhietala/8dcb33058fa30d9f37a9903e52df097b to your computer and use it in GitHub Desktop.
Save rhietala/8dcb33058fa30d9f37a9903e52df097b to your computer and use it in GitHub Desktop.
Convert flac to aac (m4a)
#!/bin/bash
#
# Convert all .flac music files to .m4a (aac) for itunes/ios use
#
# Install ffmpeg with fdk_aac (uninstall first if built without it):
# $ brew install ffmpeg --with-fdk-aac
#
# The script assumes the following directory structure:
# ./musiikkia/
# ./musiikkia/whatever/song.flac
# ./aac/
# ./aac/whatever/song.m4a
#
# and the script must be run from .
#
# Change occurrences of 'musiikkia' and 'aac' to suit your needs.
find "./musiikkia" -type d -print0 | while IFS= read -r -d '' flacdir
do
aacdir=`echo "$directory" | sed -e 's/musiikkia\//aac\//'`
[ -d "$aacdir" ] && continue # skip if aac-directory exists
mkdir -p "$aacdir"
done
find "./musiikkia" -name *.flac -print0 | while IFS= read -r -d '' input
do
output=`echo "$input" | sed -e 's/musiikkia\//aac\//' | sed -e 's/flac$/m4a/'`
[ -f "$output" ] && continue # skip if file exists
echo ""
echo "$input"
echo "$output"
echo ""
ffmpeg -i "${input}" -c:a libfdk_aac -vbr 3 -vn -n "${output}" < /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment