FFmpeg: Convert audio streams to AC3

Both DTS and Dolby Atmos are widely used audio codecs, but they are proprietary, and the companies behind them charge licensing fees for their use. Therefore, TV manufacturers may choose not to pay these fees in order to keep costs down or because they prefer to use other audio codecs.

In case your video file comes with one of the above-mentioned codecs and your TV is not supporting them, you have two options:

  • Invest in new hardware (Blu-ray players, receivers, streaming devices, soundbars or game consoles) which is supporting them.
  • Us software to convert the audio stream of your video file into another format.

A free and open-source solution would be FFmpeg, a command line tool for converting, encoding, and transcoding multimedia files.

The following command will take the input video file “input.mkv”, copy the video and subtitle streams, re-encode the audio streams using AC3 with a bit rate of 640 kilo bits per second and write everything into the output file named “output.mkv”.

ffmpeg -i input.mkv -map 0 -vcodec copy -scodec copy -acodec ac3 -b:a 640k output.mkv

-i input.mkv specifies the input file.

-map 0 tells ffmpeg to use all streams from the input file.

-vcodec copy tells ffmpeg to copy the video codec from the input file to the output file, without re-encoding the video stream.

-scodec copy tells ffmpeg to copy the subtitle codec from the input file to the output file, without re-encoding the subtitle stream.

-acodec ac3 specifies the audio codec to be used in the output file. The audio codec used is AC3, which offers a wider compatibility on multiple devices.

-b:a 640k specifies the bit rate of the audio stream. The bit rate is set to 640 kilo bits per second.

output.mkv specifies the output file.

Extract only the converted audio streams

In case you would like to add the converted AC3 audio stream to the existing MKV file, it is also possible to just extract the audio streams as MKA file using FFmpeg:

ffmpeg -i input.mkv -map 0:a -c:a ac3 -b:a 640k output.mka

The command is more or less the same as above, beside the fact that this time the video stream is ignored.

-map 0:a tells FFmpeg to map -map all audio streams a from the input file indexed as 0. The 0 refers to the input file index, and a represents audio streams within that file.

Afterwards the MKA file can be multiplexed with the original MKV file using MKVToolNix GUI, as it has the ability to add new audio tracks to an existing MKV file:

  1. Open MKVToolNix and drag the original MKV file into the source files section.

  2. Also drag the extracted MKA file into the source file section and add it to the current multiplex settings.

  3. Adjust the properties for the added tracks if needed, like the default track, naming, language etc.

  4. Specify the destination folder for the output file and press “start multiplexing”.

Once the process is complete, you should have a new MKV file with the additional audio track included.

More FFmpeg commands

asterix Written by:

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *