How to Map Audio Streams by Language in FFmpeg

This article provides a quick guide on how to use FFmpeg to select and map only the audio streams that match a specific language from a multi-language media file. You will learn the exact command-line syntax required to filter audio tracks using ISO 639-2 language codes, allowing you to easily customize your output files.

When dealing with media files that contain multiple audio tracks in different languages, FFmpeg allows you to selectively copy streams using the -map option combined with metadata specifiers.

The Syntax for Language Mapping

To target a specific language, FFmpeg uses the language metadata tag (usually a three-letter ISO 639-2 code, such as eng for English, spa for Spanish, or fra for French).

The basic syntax for mapping streams by metadata is:

-map 0:a:m:language:code

Here is what each part of this selector means: * 0: Targets the first input file. * a: Selects the audio streams. * m:language:code: Filters the streams by the metadata (m) key named “language” with the value of your specified three-letter language code.

Practical Examples

Example 1: Copy Video and Only English Audio

To copy the video stream and only the English audio streams from an input file without re-encoding, use the following command:

ffmpeg -i input.mkv -map 0:v -map 0:a:m:language:eng -c copy output.mkv

In this command: * -map 0:v selects all video streams from the first input. * -map 0:a:m:language:eng selects all audio streams tagged as English. * -c copy copies the video and audio packets directly without re-encoding, preserving the original quality and saving processing time.

Example 2: Extract Only Spanish Audio to a New File

If you want to extract all Spanish audio tracks from a video file and save them into a new audio-only file, run:

ffmpeg -i input.mkv -map 0:a:m:language:spa -c:a flac output.flac

This command filters for Spanish audio (spa) and encodes the resulting output into the lossless FLAC format.

Verifying Language Tags

If your command does not seem to map any streams, the input file might not have the language metadata tagged correctly. You can check the available streams and their metadata tags by running:

ffprobe input.mkv

Look for the DISPOSITION or Metadata section under the audio streams to verify if the language tag exists and see what three-letter code it uses.