Join Multiple FLAC Files for Gapless Playback via Command Line on OSX

I am working on post that includes a segment of live music embedded via SoundCloud. The segment consists of 5 songs that transition into each other seamlessly. The source I had was split into separate flac files and I wanted to join them into a single file for gapless playback. I also wanted to do this via the cli because why the hell not?

First Attempt

A quick Google search led me to a solution that kind of blew my mind:

  cat *.flac > joined.flac

This “works” in the sense that it joins all flac files in the directory & the end result is gapless. However, it clobbers metadata from all but the first track. The file played fine to completion in VLC, but appeared as 26 minutes instead of the 60+ I was expecting. When the file was uploaded to SoundCloud only those first 26 minutes were playable.

This command also works with mp3s, but didn’t result in a gapless file in my case.

Second Attempt

Time to dig deeper. The final solution has a few dependencies that you can install via Homebrew.

  brew install flac
  brew install shntool

shntool depends on flac to work with FLAC files. It comes with a join command that does exactly what we want:

  shntool join -n -o flac *.flac

The -n flag ensures no padding is added between tracks. The -o flag specifies what format we are working with. This gives us a new file called joined.flac with recalculated metadata. When played in VLC we see the correct running length. When uploaded to SoundCloud we can now play the entire file, complete with smooth transitions between tracks.

With that I declare this yak successfully shaved.