Create MPEG-TS with Multiple Audio Languages in FFmpeg

This guide explains how to use FFmpeg to package a video with multiple audio tracks into an MPEG-TS (.ts) container while assigning distinct language descriptors to each track. You will learn how to map multiple audio sources and apply the correct metadata tags so that media players can identify and switch between the language tracks.

The Basic FFmpeg Command

To create an MPEG-TS file with multiple audio tracks and distinct language descriptors, you must map the inputs correctly and use the stream metadata specifier (-metadata:s:a) to define the languages using ISO 639-2 three-letter codes (e.g., eng for English, spa for Spanish, fre for French).

Here is the template command:

ffmpeg -i video.mp4 -i audio_en.ac3 -i audio_es.ac3 \
-map 0:v:0 \
-map 1:a:0 \
-map 2:a:0 \
-c:v copy \
-c:a copy \
-metadata:s:a:0 language=eng \
-metadata:s:a:1 language=spa \
output.ts

Command Breakdown

  • -i video.mp4 -i audio_en.ac3 -i audio_es.ac3: Defines the input files. The video file is input 0, the English audio is input 1, and the Spanish audio is input 2.
  • -map 0:v:0: Selects the first video stream from the first input file (input 0).
  • -map 1:a:0: Selects the first audio stream from the second input file (input 1) to become the first audio track (index 0) in the output file.
  • -map 2:a:0: Selects the first audio stream from the third input file (input 2) to become the second audio track (index 1) in the output file.
  • -c:v copy -c:a copy: Copies the video and audio streams directly without re-encoding, preserving quality and saving processing time. Change copy to an encoder like aac or mp2 if re-encoding is required for MPEG-TS compatibility.
  • -metadata:s:a:0 language=eng: Assigns the English language descriptor (eng) to the first output audio stream (index 0).
  • -metadata:s:a:1 language=spa: Assigns the Spanish language descriptor (spa) to the second output audio stream (index 1).
  • output.ts: Specifies the output path and forces the MPEG-TS container format based on the .ts extension.

Mapping Tracks from a Single Multi-Track Input

If your source file already contains multiple audio tracks and you want to remux them into an MPEG-TS container with updated language tags, use this command:

ffmpeg -i input.mkv \
-map 0:v:0 -map 0:a:0 -map 0:a:1 \
-c copy \
-metadata:s:a:0 language=eng \
-metadata:s:a:1 language=fra \
output.ts

In this variation, -map 0:a:0 and -map 0:a:1 pull the first two audio streams from the single input file, and the metadata tags label them as English and French (fra) respectively.