Skip to content

Instantly share code, notes, and snippets.

@MrDOS
Last active December 13, 2015 20:48
Show Gist options
  • Save MrDOS/4972735 to your computer and use it in GitHub Desktop.
Save MrDOS/4972735 to your computer and use it in GitHub Desktop.
Transcode FLAC files to AAC. Grabs all FLAC files in the given directory, transcodes to AAC, then makes some attempt to copy tags and, if folder.jpg is found, to embed album art.
#! /bin/sh
# Transcode FLAC files to AAC. Grabs all FLAC files in the given directory,
# transcodes to AAC, then makes some attempt to copy tags and, if folder.jpg is
# found, to embed album art.
AAC_FLAGS="-q 0.5"
FLAC_TAGS="TITLE ARTIST ALBUM GENRE TRACKNUMBER DATE"
AAC_TAGS="title artist album genre track year"
TAGCOUNT=`echo "$FLAC_TAGS" | grep -o ' ' | wc -l`
TAGCOUNT=`expr $TAGCOUNT + 1`
if [ $# -lt 2 ]
then
echo "Usage: $0 infolder outfolder" 1>&2
exit 1
fi
if [ ! -d "$1" -o ! -r "$1" ]
then
echo "$1 does not exist or is not readable." 1>&2
exit 2
fi
if [ ! -d "$2" -o ! -w "$2" ]
then
echo "$2 does not exist or is not writable." 1>&2
exit 3
fi
for file in "$1"/*.flac
do
if ! file "$file" | grep -q "FLAC audio bitstream data"
then
echo "$file is not valid FLAC audio." 1>&2
continue
fi
outfile="$2"/`echo "$file" | sed -e 's/.*\/\(.*\).flac/\1/'`.m4a
flac -dc "$file" | \
neroAacEnc $AAC_FLAGS -if - -of "$outfile" 2>/dev/null
for i in `seq 1 $TAGCOUNT`
do
flac_tag=`echo "$FLAC_TAGS" | cut -d ' ' -f $i`
aac_tag=`echo "$AAC_TAGS" | cut -d ' ' -f $i`
val=`metaflac --show-tag=$flac_tag "$file" | sed -e 's/.*=//'`
neroAacTag "$outfile" -meta:"$aac_tag"="$val" 2>/dev/null
done
if [ -r "$1"/folder.jpg ]
then
neroAacTag "$outfile" -add-cover:front:"$1"/folder.jpg 2>/dev/null
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment