Skip to content

Instantly share code, notes, and snippets.

@alecjacobson
Last active January 7, 2018 19:09
Show Gist options
  • Save alecjacobson/b4e8f59bbd251ed81df4c5fe8441f630 to your computer and use it in GitHub Desktop.
Save alecjacobson/b4e8f59bbd251ed81df4c5fe8441f630 to your computer and use it in GitHub Desktop.
Concatenate mp3s in a directory and subdirectories into a .m4b file
# https://gist.github.com/alecjacobson/b4e8f59bbd251ed81df4c5fe8441f630
#
# brew install ffmpeg --with-fdk-aac
OLDPWD=$( pwd )
cd "$1"
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 libfdk_aac -b:a 128k -f mp4 "$2"
cd "$OLDPWD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment