How can I concat one single mp3 file many times (crossfades included) using ffmpeg?

265 views Asked by At

I try to make a bash file with (an) ffmpeg command(s) in which a single mp3 file (let's say of two minutes duration) will be extended to for example 8 hours duration. Since mp3 files always have these gaps of silence at the front and back in order to make it seamless loops I need to use crossfading. How can I do this without having an enormous large command like:

ffmpeg -i same.mp3 -i same.mp3 -i same.mp3 ....(hundreds of times) -filter_complex "[0][1]acrossfade=d=5:c1=exp:c2=exp[a01] ... etc (hundreds of times) output.mp3

1

There are 1 answers

3
Баяр Гончикжапов On

not tested with 8 hour:

#!/bin/bash
TOT=160
f="input 3.mp3"
INP=("-i" "$f")

FLC="[0:a]asplit=${TOT}"
for (( i=1; i<=$TOT; i++ )); do
  FLC+="[${i}a]"
done

PDC="[1a]"
for (( i=2; i<=$TOT; i++ )); do
  PDA="[${i}a]"
  FLC+=";${PDC}${PDA}acrossfade=d=5"
  PDC="[${i}xa]"
  FLC+="${PDC}"
done

echo $FLC
echo ""
ffmpeg "${INP[@]}" -filter_complex "$FLC" -map $PDC -c:a libmp3lame -b:a 320k /tmp/output.mp3 -y
mpv /tmp/output.mp3

variable TOT = 8hour div duration of input