FFmpeg amix vs amerge Difference
When working with audio in FFmpeg, combining multiple audio tracks is
a common task, but the method you choose depends on your desired output.
This article explains the difference between the amix and
amerge filters, helping you understand when to mix audio
signals together and when to merge them into a single multi-channel
stream.
What is the amix
Filter?
The amix filter mixes multiple audio inputs into a
single audio output. It overlays the audio signals on top of each other
within the same channels. For example, if you input two stereo tracks,
amix will blend them together into a single stereo track
where you can hear both sounds playing simultaneously.
Key Characteristics of
amix
- Channel Layout: The output channel layout is usually the same as the input with the most channels (e.g., mixing stereo and mono results in stereo).
- Use Case: Perfect for adding background music to a voiceover or sound effects to a video.
- Duration: By default, the output duration matches
the longest input, though this can be configured using the
durationoption.
Example Command
To mix a voiceover (voice.mp3) and background music
(music.mp3) into one output:
ffmpeg -i voice.mp3 -i music.mp3 -filter_complex amix=inputs=2:duration=first output.mp3What is the amerge
Filter?
The amerge filter merges two or more audio streams into
a single multi-channel audio stream. Instead of blending the sounds
together into the same channels, it places each input stream into its
own dedicated channel. For example, merging two separate mono streams
will create a single stereo stream where one input becomes the Left
channel and the other becomes the Right channel.
Key Characteristics of
amerge
- Channel Layout: The output channel count is the sum of the input channel counts (e.g., merging two 1-channel mono streams results in one 2-channel stereo stream).
- Use Case: Perfect for combining separate microphone recordings into a single multi-channel file or creating surround sound tracks.
- Requirements: All input streams must have the same sample rate. The output duration will automatically match the shortest input stream.
Example Command
To merge two mono audio files into a single stereo file:
ffmpeg -i left.wav -i right.wav -filter_complex amerge=inputs=2 output.wavSummary of Key Differences
| Feature | amix (Mixing) |
amerge (Merging) |
|---|---|---|
| Primary Function | Blends multiple audio tracks into the same channels. | Groups separate audio tracks into new, distinct channels. |
| Output Channels | Keeps the channel layout of the primary/widest input. | Sums the input channels (e.g., 1 + 1 = 2 channels). |
| Common Use Case | Adding background music to a voiceover. | Combining two mono mics into a single stereo track. |
| Input Requirements | Flexible; handles different sample rates and durations. | Strict; requires identical sample rates. |
| Default Duration | Matches the longest input. | Matches the shortest input. |