| Version 19 (modified by , 7 years ago) ( diff ) |
|---|
The -map option is used to choose which streams from the input(s) should be included in the output(s). The -map option can also be used to exclude specific streams with negative mapping.
Default behavior
If you do not use the -map option then the default stream selection behavior will automatically choose streams.
- Default stream selection will not automatically choose all of the streams.
- Only one stream per type will be selected. For example, if the input has 3 video streams it will only choose 1.
- The default stream selection will choose streams based upon specific criteria.
Using the -map option disables the default stream selection behavior and allows you to manually choose streams.
Syntax
The syntax is:
-map input_file_index:stream_type_specifier:stream_index
Example:
-map 2:v:5
Translation:
2is input file #3.vis a stream specifier to choose the type of stream. Other stream specifiers includeaudio,subtitles,data, attachments.5is video stream #6.
So -map 2:v:5 will choose from input #3, audio stream #6. Note that counting starts from 0.
The stream specifier is optional and can be omitted. Example:
-map 1:2
From input #2 choose stream #3.
Examples
Choose all streams
Single input:
ffmpeg -i input.avi -map 0 output.mkv
Multiple inputs:
ffmpeg -i input0.mkv -i input1.mp4 -i input2.wav -map 0 -map 1 -map 2 output.mkv
Using stream copy (re-mux) to avoid re-encoding:
ffmpeg -i input.avi -map 0 -c copy output.mkv
Video streams only
ffmpeg -i input.mp4 -map 0:v output.mp4
Audio streams only
ffmpeg -i input.mp4 -map 0:a output.mp4
A specific video stream only
Choose video stream #5:
ffmpeg -i input.mkv -map 0:v:4 output.mp4
Note that counting starts from 0.
Video and audio from different files
ffmpeg -i video.mp4 -i audio.m4a -map 0:v -map 1:a output.mp4
Everything except audio
Using negative mapping:
ffmpeg -i input.mp4 -map 0 -map -0:a output.mp4
Specific language
Include all video and all streams with Spanish language metadata:
ffmpeg -i input.mkv -map 0:v -map 0:m:language:spa output.mp4
See List of ISO 639-1 codes for the 3 letter language names.
Choose outputs from filters
In this example the filtered video is named [v] and the filtered audio is named [a]:
ffmpeg -i input.mp4 -i logo.png -i audio.mp3 -filter_complex "[0]scale=1280:-1[bg];[bg][1]overlay[v];[2:a]volume=-3dB[a]" -map "[v]" -map "[a]" output.mp4
You can use almost any arbitrary names to label the filter outputs.
Different outputs
Video to video.mp4, audio #2 to audio_2.mp3, audio #3 to audio_3.wav:
ffmpeg -i input.mkv -map 0:v video.mp4 -map 0:a:1 audio_2.mp3 -map 0:a:2 audio_3.wav
Note that counting starts from 0.
Conditional mapping
Adding a trailing question mark (?) to -map will ignore the mapping if the stream does not exist.
To map the video and audio streams and ignore the audio mapping if no audio streams exist:
ffmpeg -i input.webm -map 0:v -map 0:a? output.mkv
If -map 0:a is used instead, and there are no audio streams, then ffmpeg will fail with Stream map '0:a' matches no streams. To ignore this, add a trailing '?' to the map..
Re-order streams
The order of your -map options determines the order of the streams in the output. In this example the input file has audio as stream #0 and video as stream #1 (which is possible but unusual). Example to re-position video followed by audio:
ffmpeg -i input.mp4 -map 0:v -map 0:a -c copy output.mp4
This example stream copies (re-mux) with -c copy to avoid re-encoding.
See also
Attachments (1)
-
map.png
(22.5 KB
) - added by 7 years ago.
diagram of -map option
Download all attachments as: .zip


