Convert FLAC library to ALAC for easy iTunes syncing

I have a good size FLAC library that I mainly play using Subsonic or Kodi. In the car, however, I use an iPod Classic that interfaces with the stereo. It’s kind of a pain to manually go through and convert everything by hand and make the artwork match. I made a bash script to run on my NAS running Ubuntu to take care of this for me.

You only need a few packages, so bust out our favorite package manager:

sudo apt-get install libav-tools atomicparsley

libav-tools will give us the tool avconv and we will use AtomicParsley to reinsert our cover art into the ALAC output. Here’s the bash script you’ll need:

#!/bin/bash
shopt -s globstar
cd /data/Music

find . -type d -exec mkdir -p -- /data/ALAC/{} \;

for f in /data/Music/**/*.{m4a,mp3}; do
    oldpath='/data/Music'
    newpath='/data/ALAC'
    newfile="${f/$oldpath/$newpath}"
    cp "$f" "${newfile}"
done

for f in /data/Music/**/*.flac; do
    oldpath='/data/Music'
    newpath='/data/ALAC'
    newfile="${f/$oldpath/$newpath}"
    avconv -i "$f" -c:a alac "${newfile%.*}.m4a" cover.jpg
    AtomicParsley "${newfile%.*}.m4a" --artwork cover.jpg --overWrite
done

Obviously you’ll have to change some of the names of the directories to your own to fit your needs. Note that this will basically duplicate all of your music into a new folder, so I recommend you check to see if you have the required hard drive space before running this.

One thought on “Convert FLAC library to ALAC for easy iTunes syncing”

  1. I use iDealshare VideoGo to convert FLAC to ALAC with no loss of audio quality.

    It also can convert FLAC to AIFF, WAV, MP3, AAC, WMA, MKA, Opus, AC3, MP2, M4A, RA, AU, DTS, etc

    It even can edit FLAC like merge, split, adjust audio channel, volume, bitrates, files size etc

Leave a Reply

Your email address will not be published. Required fields are marked *