As explained in the previous lesson, a container file (a MP4 video file for exmaple) may include several elements and they can be video, audio, subtitles or other metadata elements. These elements are usually called streams or tracks.

For example, a video may have 1 video stream and 2 audio streams, each audio stream containing audio in different a language. This could be the case of a movie with 2 audio tracks, one in English and the other in French.

If more than one video or audio streams are present in a file, the video player just plays one video and one audio stream, letting the user to choose his/her preference.

multilingual video file

Stream naming convention

When editing video or applying transformations with FFMPEG, you must refer to particular streams in the provided input files and FFMPEG has its own naming convention you must know.

This naming convention for referring to the different streams follows this schema:

Where:

Sounds complicated, but it's not, and it's easier to understand with a few examples:

Mapping streams to output files

Now that we know how to refer to particular streams, we can select what streams from the input files we want to be included in the output file.

In FFMPEG, this is done using the -map parameter. Let's see a few examples:

ffmpeg -i english.mp4 -i french.mp3 -map 0:v:0 -map 1:a:0 french.mp4:
Selects the first video stream from english.mp4 (0:v:0) and the first audio stream from french.mp3 (1:a:0) and saves them into french.mp4

ffmpeg -i english.mp4 -i french.mp3 -map 0 -map 1:a:0 english-french.mp4:
Selects all streams from english.mp4 file (0) and the first audio stream from french.mp4 file (1:a:0) creating english-french.mp4 that includes both audio streams.

This type of stream manipulation is very useful in the day to day operations, for example:

In the following lessons, we will go through several of these examples using the -map parameter.

Self-evaluation

In FFMPEG, 0:a refers to

In FFMPEG, -map 1:v:0 refers to

Published on February 2nd, 2022

Author
David Bosch
David Bosch David is an experienced engineer, now collaborating with JSON2Video.