What is map in FFmpeg? Map explained

The -map functionality is an advanced feature that allows the user to select specific input audio or video that is sent to the output. In addition, virtual streams can be created to apply complex manipulations which can be accessed with -map. 

Normally, a map isn’t required to set an output as the result audio and video is known:

 $ ffmpeg -i input.mp4 output.mp4 

In examples where multiple inputs are available, the use of -map is specific on what the output will include. In this example, the video (v) from input1.mp4 (index 0) is selected for output while the audio (a) from input2.mp4 (index 1) is selected for output:

 $ ffmpeg -i input1.mp4 -i input2.mp4 -map 0:v -map 1:a -shortest output.mp4 

In the case of two inputs with a filter, the syntax is a little different. In this example, the output will have the video input1.mp4 and the audio from input2.mp4 with a volume increase of 10dB for the output result:

 $ ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[1:a]volume=10dB[new_audio]" -map 0:v -map [new_audio]:a -shortest output.mp4 

The volume filter is applied to [1:a], the audio in input2.mp4, and a new virtual stream, [new_audio], must be created for -map to set the new audio in the output. Accessing the audio from [new_audio] follows the same pattern with the [new_audio]:a.

If an input has multiple audio sources as seen in MKV files, the access to a specific audio channel syntax would be as seen below:

 $ ffmpeg -i input.mkv -map 0:v -map 0:a:1 output.mp4 

In addition to virtual streams being created, the virtual stream can also have a filter applied to it through chaining. For example, with the same concept as the last example except this time, the [new_audio] has a reverse filter applied:

 $ ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[1:a]volume=50dB[new_audio]; [new_audio]areverse[reversed_audio]" -map 0:v -map [reversed_audio]:a -shortest output.mp4 

A new audio stream, [reversed_audio], is created and set for the output. The final results being video from input1.mp4 with audio from input2.mp4 with 10dB higher volume and reverse is now complete. 

The syntax of -map accesses to a stream's audio and video is very similar to dictionaries in the Swift programming language. A dictionary has a key and value, [key:value], and in FFMPEG the key is the index/name while the value is either audio or video.

Note: If the output requires video and audio both must be mapped.

Love FFmpeg? Grab a copy of FFmpeg For Beginners on Kindle or Paperback to learn over 120 ways to master FFmpeg!

buy now on amazon

Related Posts

2 thoughts on “What is map in FFmpeg? Map explained

Comments are closed.