FFMPEG - Merge two audio file with defined overlapping time

  1. Use ffprobe to get duration of 1st mp3 file.

  2. Run ffmpeg using adelay to delay the audio and amix to mix the two audio streams into one:

    ffmpeg -i 1.mp3 -i 2.mp3 -filter_complex "[1]adelay=Ns|Ns[a1];[0:a][a1]amix=inputs=2[a]" -map "[a]" output.mp3
    
    • Ns = 1.mp3 duration - overlap duration. For example, if 1.mp3 is 30 seconds long, and you want a 10 second overlay, then use 20s|20s.

    • This assumes 2.mp3 is stereo.

    • If you ffmpeg is older than version 4.2 then use milliseconds instead of seconds in adelay, as in 20000|20000.

    • -map "[a]" tells ffmpeg to use the output from amix which is arbitrarily labeled [a]. Otherwise, the default stream selection behavior will be used. If you are fine with that and understand the implications then feel free to omit the label and -map (such as ...amix=inputs=2" output.mp3). Also see -map documentation.