Skip to content

Instantly share code, notes, and snippets.

@dmgig
Last active July 23, 2018 00:19
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 dmgig/a783542741f8569c841f75fd7c4dd37b to your computer and use it in GitHub Desktop.
Save dmgig/a783542741f8569c841f75fd7c4dd37b to your computer and use it in GitHub Desktop.
Append overlapping intro and outro audio to another audio file with sox and ffmpeg
#!/bin/bash
IFS=$'\n'
IntroLen=9
OutroLen=12
OverlapLen=8
IntroSilenceLen=3
OutroSilenceLen=10
sox -n -r 44100 -c 1 IntroSilence.wav trim 0.0 $IntroSilenceLen
sox -n -r 44100 -c 1 OutroSilence.wav trim 0.0 $OutroSilenceLen
for FILE in *.mp3;
do
echo $FILE
ffmpeg -y -i $FILE -f ffmetadata metadata.txt
FILEWAV=x${FILE%.mp3}.wav
ffmpeg -y -i $FILE ${FILEWAV}
CurrentAudioLength=`ffprobe -i $FILEWAV -show_entries format=duration -v quiet -of csv="p=0"`
echo "Current audio is $CurrentAudioLength seconds"
SilenceTrackLen="$((${CurrentAudioLength%.*} - ${OverlapLen%.*}))"
echo "Silence Track of $SilenceTrackLen seconds"
sox -n -r 44100 -c 1 SilenceTrack.wav trim 0.0 $SilenceTrackLen
echo 'Making Tracks'
sox IntroSilence.wav $FILEWAV OutroSilence.wav TrackA.wav
sox intro.wav SilenceTrack.wav outro.wav TrackB.wav
echo 'Merging'
ffmpeg -y -i TrackA.wav -i TrackB.wav -f ffmetadata -i metadata.txt -c copy -map_metadata 2 -filter_complex amerge -ac 1 -c:a libmp3lame -q:a 2 _${FILE}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment