audiofilterffmpegfadingcross-fade

Crossfading between two audio files with ffmpeg?


I have two mp3 files and want to concatenate them to one new file. However, I want only a part of each file, and I would like to create a cross fade between the two.

So for example I want the first 3 minutes of a.mp3, and then during 5 seconds a crossfade to b.mp3 starting at the 1:20 minute mark (within b.mp3).

Here's a timeline illustration of what I want:

timeline

So the total length of the resulting file would be the 3:05 minutes plus the length of b.mp3 minus 1:25 minutes, which comes down to the length of b.mp3 plus 1:40 minutes.

I am too inexperienced with ffmpeg's source selections, mappings, and filter syntax to get the result I want. For example I can apply a fade in or out to one mp3 file, but I wouldn't know how to make these two overlap, resulting in a crossfade between two audio sources.

Just for clarity: I'm looking for a command line to do this, i.e. with the standalone version of ffmpeg, I'm not using ffmpeg as library within an application or anything.


Solution

  • Use

    ffmpeg -i a.mp3 -i b.mp3
     -filter_complex
          "[0]atrim=0:185.0[a]; [1]atrim=80.0[b];
           [a][b]acrossfade=d=5.0"
     out.mp3
    

    All times are in seconds.