Create Multi-Language HLS Streams with FFmpeg

This article provides a step-by-step guide on how to use FFmpeg to create an HTTP Live Streaming (HLS) packager that supports multiple language audio tracks. You will learn how to take a video file and multiple separate audio files, encode them, and package them into a single HLS master playlist where viewers can select their preferred language during playback.

The FFmpeg Command

To create an HLS stream with separate, selectable audio tracks, you need to map your video and audio inputs correctly and use the -var_stream_map option in FFmpeg. This option groups the different audio streams and associates them with the video stream.

Here is the template command using a single video file and two separate audio files (English and Spanish):

ffmpeg -i video.mp4 -i audio_en.mp3 -i audio_es.mp3 \
-map 0:v:0 -map 1:a:0 -map 2:a:0 \
-c:v libx264 -c:a aac -b:a 128k \
-f hls \
-hls_time 10 \
-hls_playlist_type vod \
-master_pl_name master.m3u8 \
-var_stream_map "v:0,agroup:hd_audio a:0,agroup:hd_audio,language:eng,name:English,default:yes a:1,agroup:hd_audio,language:spa,name:Spanish" \
-hls_segment_filename "stream_%v/data%03d.ts" \
stream_%v.m3u8

Command Breakdown

Resulting Structure

After running the command, FFmpeg will generate the following directory structure:

When you load master.m3u8 into an HLS-compatible player (like Safari, VLC, or web players like Video.js and Hls.js), the player will display a menu allowing the user to switch seamlessly between English and Spanish audio while the video plays.