Created
October 16, 2016 05:15
-
-
Save jpillora/a64d27d01764d2d3dbbbc4948fbb2110 to your computer and use it in GitHub Desktop.
Concatenate multiple MP3s into a single MP3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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