Skip to content

Instantly share code, notes, and snippets.

@alecjacobson
Created January 7, 2018 19:10
Show Gist options
  • Save alecjacobson/a5e02d076b3396c624d611538b6f7c0f to your computer and use it in GitHub Desktop.
Save alecjacobson/a5e02d076b3396c624d611538b6f7c0f to your computer and use it in GitHub Desktop.
Concatenate all mp3s in a directory and subdirectories into a single mp3
# https://gist.github.com/alecjacobson/b4e8f59bbd251ed81df4c5fe8441f630
#
# brew install ffmpeg --with-fdk-aac
OLDPWD=$( pwd )
cd "$1"
# Sort files so that ./Disc 10/1.mp3 is after ./Disc 9/1.mp3
paths=$( find . -name "*.mp3" | sed 's/\([0-9]\)/;\1/' | sort -n -t\; -k2,2 | tr -d ';')
echo "$paths"
concat_paths=$( echo "$paths" | tr '\n' '|' )
ffmpeg -i "concat:$concat_paths" -c:a copy -f mp3 "$2"
cd "$OLDPWD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment