Mix Multiple Audio Tracks with Delay in FFmpeg

This article explains how to mix multiple audio files at specific start times using FFmpeg. While the amix filter combines multiple audio streams into a single output, it starts all inputs simultaneously by default. To introduce custom start times, you must combine amix with the adelay filter. Below, you will find the exact command-line syntax, filter explanations, and configuration options to achieve this.

The Core Concept: Combining adelay and amix

To start different audio tracks at different times, you cannot rely on amix alone. You must first apply the adelay filter to individual input streams to pad them with silence at the beginning. Once delayed, the streams are fed into the amix filter to be merged.

The FFmpeg Command

Here is the template command to mix three audio inputs where the first starts immediately, the second starts at 5 seconds, and the third starts at 10.5 seconds:

ffmpeg -i input1.mp3 -i input2.mp3 -i input3.mp3 -filter_complex \
"[1]adelay=5000:all=1[a2]; \
 [2]adelay=10500:all=1[a3]; \
 [0:a][a2][a3]amix=inputs=3:duration=longest:dropout_transition=0[out]" \
-map "[out]" output.mp3

Command Breakdown

  • -i input1.mp3 -i input2.mp3 -i input3.mp3: Loads the three input audio files. FFmpeg indexes these starting from 0 (so input1 is [0], input2 is [1], and input3 is [2]).
  • -filter_complex: Tells FFmpeg to use a complex filtergraph, which is required when dealing with multiple inputs and outputs.
  • [1]adelay=5000:all=1[a2]: Takes the second input ([1]) and delays it by 5000 milliseconds (5 seconds). The all=1 option ensures the delay is applied to all audio channels (stereo, mono, etc.) within that stream. The output of this step is saved to a temporary label named [a2].
  • [2]adelay=10500:all=1[a3]: Takes the third input ([2]) and delays it by 10,500 milliseconds (10.5 seconds), saving the output to the label [a3].
  • [0:a][a2][a3]amix=inputs=3...: Takes the original first audio stream ([0:a]) and the two delayed streams ([a2] and [a3]), feeding all three into the amix filter.
  • duration=longest: Ensures the output file only ends when the longest track (including its delay) finishes playing. Other options include first (ends when the first input ends) and shortest (ends when the shortest input ends).
  • dropout_transition=0: Prevents sudden volume drops or changes when one of the mixed tracks finishes playing before the others.
  • -map "[out]": Maps the final output of the filtergraph ([out]) to the output file output.mp3.

Handling Volume Reductions

By default, the amix filter scales down the volume of the input streams to prevent digital clipping (distortion) when mixing them together. If your output audio is too quiet, you can use the volume filter after mixing to restore the original loudness:

ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex \
"[1]adelay=3000:all=1[a2]; \
 [0:a][a2]amix=inputs=2:duration=longest[mixed]; \
 [mixed]volume=2[out]" \
-map "[out]" output.mp3

In this case, volume=2 doubles the volume of the mixed track. Adjust this multiplier as needed depending on your source files.