How to Set Audio Language Code in FFmpeg

This article explains how to set or change the language metadata code of an audio stream within a media file using FFmpeg. You will learn the exact command-line syntax required to apply ISO 639 language codes (such as ‘fre’ for French or ‘ger’ for German) to your audio tracks quickly without needing to re-encode the audio.

To set the language of an audio stream, you use the -metadata:s:a option in FFmpeg. This option targets the metadata of a specific audio stream. By combining this with stream copying (-c copy), you can update the language tag instantly because the video and audio data are not re-encoded.

Basic Syntax for a Single Audio Stream

To set the language of the first audio stream in a file, use the following command:

ffmpeg -i input.mp4 -map 0 -c copy -metadata:s:a:0 language=fre output.mp4

Here is what each part of the command does: * -i input.mp4: Specifies the input video file. * -map 0: Tells FFmpeg to copy all streams (video, audio, subtitles) from the input file to the output file. * -c copy: Copies all streams without re-encoding, ensuring the process is fast and loses no quality. * -metadata:s:a:0 language=fre: Targets the first audio stream (a:0) and sets its language metadata key to French (fre). * output.mp4: The name of the newly created output file.

Setting Languages for Multiple Audio Streams

If your video file contains multiple audio tracks, you can specify the language for each track individually by changing the stream index number (e.g., a:0 for the first track, a:1 for the second track).

For example, to set the first audio track to English and the second audio track to German:

ffmpeg -i input.mkv -map 0 -c copy -metadata:s:a:0 language=eng -metadata:s:a:1 language=ger output.mkv

Choosing Language Codes

FFmpeg supports both bibliographic and terminology codes from the ISO 639-2 standard (three-letter codes) as well as ISO 639-1 (two-letter codes). While most media players support both, using the three-letter ISO 639-2 codes (e.g., eng for English, fre or fra for French, ger or deu for German, spa for Spanish) is recommended for the best compatibility across hardware and software players.