How to Convert 5.1 Audio to E-AC-3 with FFmpeg
This guide provides a quick and practical walkthrough on how to convert a multi-channel 5.1 audio stream to Dolby Digital Plus (E-AC-3) using the FFmpeg command-line utility. You will find the precise commands required to execute the conversion, configure the proper channel layout, and set the optimal bitrate for high-quality surround sound playback on supported home theater systems.
The Basic Conversion Command
To convert an existing audio stream inside a video file to Dolby
Digital Plus while keeping the original video stream untouched, use the
native FFmpeg eac3 encoder. Run the following command in
your terminal:
ffmpeg -i input.mkv -c:v copy -c:a eac3 -b:a 448k output.mkvCommand Breakdown:
-i input.mkv: Specifies the path to your input file.-c:v copy: Copies the video stream directly without re-encoding it, saving time and preserving video quality.-c:a eac3: Selects the Dolby Digital Plus (E-AC-3) audio encoder.-b:a 448k: Sets the audio bitrate to 448 kbps, which is a highly compatible and high-quality bitrate for 5.1 surround sound.output.mkv: The name of your newly created output file containing the E-AC-3 audio track.
Ensuring 5.1 Channel Layout (6 Channels)
If your input file has more channels (such as 7.1) or you want to
explicitly force FFmpeg to output a 5.1 channel layout, use the
-ac flag to define the channel count:
ffmpeg -i input.mkv -c:v copy -c:a eac3 -ac 6 -b:a 640k output.mkv-ac 6: Forces the output to use exactly 6 channels (the standard configuration for 5.1 surround sound: Left, Right, Center, Low-Frequency Effects/Subwoofer, Left Surround, and Right Surround).-b:a 640k: Increases the bitrate to 640 kbps, which is the maximum standard bitrate for consumer E-AC-3 5.1 audio, providing near-lossless quality.
Extracting 5.1 Audio to a Standalone E-AC-3 File
If you want to extract the 5.1 audio track from a video file and save
it as a standalone audio file, discard the video stream by using the
-vn flag:
ffmpeg -i input.mkv -vn -c:a eac3 -ac 6 -b:a 448k output.eac3-vn: Blocks the video stream from being included in the output.output.eac3: Saves the output with the.eac3(or.ec3) file extension, which is standard for raw Dolby Digital Plus audio streams.