Skip to content

Instantly share code, notes, and snippets.

@jpillora
Created October 16, 2016 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpillora/a64d27d01764d2d3dbbbc4948fbb2110 to your computer and use it in GitHub Desktop.
Save jpillora/a64d27d01764d2d3dbbbc4948fbb2110 to your computer and use it in GitHub Desktop.
Concatenate multiple MP3s into a single MP3
#!/bin/bash
# concat multiple mp3 files into a single mp3
# installation:
# chmod +x tomp3 and save to /usr/local/bin/tomp3
# usage: tomp3 <DIR> [NAME]
# finds all mp3 files in DIR, writes a single mp3 to NAME.mp3
# set NAME to --preview to list mp3s in the order they will
# be concatenated.
# requires: ffmpeg
SRC=$1
MP3S=$(find "$SRC/" -name "*.mp3" | sort -V)
if [[ "$2" == "--preview" ]]; then
echo "$MP3S"
echo -n "==> previewed "
echo "$MP3S" | wc -l
exit 0
fi
OUTRELA="$2"
if [[ "$OUTRELA" = "" && "$1" != "" ]]; then
OUTRELA="$1"
fi
OUT=$(readlink -f "$OUTRELA")
LIST=$(echo "$MP3S" | perl -pe 'chomp if eof' | tr '\n' '|')
CMD="ffmpeg -i \"concat:$LIST\" -vn -acodec copy \"$OUT.mp3\""
#debug
#echo "running:"
#echo "$CMD"
echo "$CMD" | bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment