Create longer music tracks by appending same track with crossfade

A common thing I usually do with my video files is background music, sometimes I find a track that I like but its too short usually under two minutes, so what I wind up having to do is exented the track by composiiting the track onto itself but doing in such a was as to make it appear seemless, there’s a ton of ways to do this but the easiest for me is to simply attach the first tract to the second one ( same track) and cross-fade the two tracks… This can be easily done using a command line tool like ffmpeg.

first download ffmpeg for your system, Windows, Mac or Linux .. and install it, this is a command line tool so you will need a little experience with the command line..

Next refer to the command line example below.

ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex "[0:a]afade=t=out:st=$(bc -l <<< $(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input1.mp3)-5)[a];[1:a]afade=t=in:st=0[fadein];[a][fadein]acrossfade=d=5[aout]" -map "[aout]" output.mp3

This ffmpeg command does the following:

  1. Inputs two audio files (input1.mp3 and input2.mp3).
  2. Applies a fade-out effect on the first input (afade=t=out:st=duration-5), where the fade-out starts 5 seconds before the end of the first input.
  3. Applies a fade-in effect on the second input (afade=t=in:st=0), starting from the beginning of the second input.
  4. Uses the acrossfade filter to perform the crossfade with a duration of 5 seconds.
  5. Maps the output of the crossfade to the output file (output.mp3).

Make sure to replace input1.mp3 and input2.mp3 with the actual file names of your input MP3 files and adjust the output file name (output.mp3) as needed.

Leave a Reply