FFmpeg Map Streams to Multiple Output Files

This guide explains how to use the FFmpeg -map option to extract and direct specific audio, video, or subtitle streams from a source file into separate output files. You will learn the fundamental syntax of stream selection and see practical, step-by-step examples of how to split multi-stream media files in a single command.

Understanding FFmpeg Stream Mapping Syntax

FFmpeg uses the -map option to select which streams from the input files should be sent to the output files. The basic syntax for identifying a stream is:

input_file_index:stream_type:stream_index

To write different streams to different files in a single command, you must place the -map option immediately before the output file it belongs to. FFmpeg applies mapping options to the output file that directly follows them.


Example 1: Separating Video and Audio into Different Files

If you have an MP4 file and want to save the video stream to one file and the audio stream to another, use the following command:

ffmpeg -i input.mp4 -map 0:v:0 output_video.mp4 -map 0:a:0 output_audio.mp3

How it works:


Example 2: Splitting Multiple Audio Tracks

For media files containing multiple audio tracks (such as different languages), you can export each language track to its own audio file.

ffmpeg -i input.mkv -map 0:a:0 english.wav -map 0:a:1 spanish.wav

How it works:


Example 3: Extracting Subtitles, Audio, and Video Simultaneously

You can split a single file into three separate files containing the video, a specific audio track, and the subtitle track:

ffmpeg -i input.mkv \
  -map 0:v:0 video_only.mp4 \
  -map 0:a:0 audio_only.m4a \
  -map 0:s:0 subtitles.srt

How it works: