Multiplex Multiple Audio Streams into AVI Using FFmpeg

This article provides a quick and practical guide on how to combine a single video file with multiple separate audio tracks into a single AVI container using FFmpeg. You will learn the exact command-line syntax, the importance of stream mapping, and how to configure codecs for optimal compatibility with the AVI format.

The Basic Command Structure

To multiplex (mux) multiple audio streams into an AVI file, you must use FFmpeg’s -map option. By default, FFmpeg only includes one video stream and one audio stream in the output. The -map flag manually overrides this behavior, allowing you to select and assign multiple input streams to the output container.

Here is the standard command to combine one video file and two separate audio files into an AVI container:

ffmpeg -i video.mp4 -i audio1.wav -i audio2.wav -map 0:v -map 1:a -map 2:a -c:v copy -c:a ac3 output.avi

Understanding the Parameters

Labeling the Audio Streams (Metadata)

To help media players identify the different audio tracks (for example, different languages), you can add language metadata to each stream using the -metadata option:

ffmpeg -i video.mp4 -i english.wav -i spanish.wav -map 0:v -map 1:a -map 2:a -c:v copy -c:a ac3 -metadata:s:a:0 language=eng -metadata:s:a:1 language=spa output.avi

In this command: * -metadata:s:a:0 language=eng sets the language of the first audio stream (index 0) to English. * -metadata:s:a:1 language=spa sets the language of the second audio stream (index 1) to Spanish.