Requirement
I'd like to concat two audio files with predefined overlapping time.
For instance, if 10 sec overlapping is defined, then the ending 10sec of first audio and the starting 10sec of second audio are overlapped in the output.
|<---- 1st mp3 file --------------------> |
| <-----------2nd mp3 file ------------->|
result:
|<-----------------------(overlap 10 sec )--------------------->|
Answer
Use
ffprobe
to get duration of 1st mp3 file.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, if1.mp3
is 30 seconds long, and you want a 10 second overlay, then use20s|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 in20000|20000
.-map "[a]"
tellsffmpeg
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.
Comments
Post a Comment