Ffmpeg to duplicate an audio stream and encode this new stream

audio, ffmpeg, mapping

Solution

this works for me:

ffmpeg -y -i Source.mkv -map 0:v -c:v copy -map 0:a -c:a copy -map 0:a -strict -2 -c:a aac out.mkv

- `-y` – A global option to overwrite the output file if it already exists.

- `-map 0:v` – Designate the video stream(s) from the first input as a source for the output file.

- `-c:v copy` – Stream copy the video. This just muxes the input to the output. No re-encoding occurs.

- `-map 0:a` – Designate the audio stream(s) from the first input as a source for the output file.

- `-c:a copy` – Stream copy the audio. This just muxes the input to the output. No re-encoding occurs.

- `-strict -2 -c:a aac` – Use the native FFmpeg AAC audio encoder. `-strict -2` is required as a way that you acknowledge that the encoder is designated as experimental. It is not a great encoder, but it is not too bad at higher bitrates.

According to wikipedia, there is no difference between AC3 and ATSC A/52: the 1st one is the name of the codec, the 2nd is the name of the standard specifying the AC3 codec. Maybe someone have more knowledge about it?

Problem

I have some video files that I need to re-encode due to compatibility issues. They are currently mkv files with h.264 video and ac3-a52 audio. I want to keep the h.264 video, convert the container to m4v and create two audio tracks, one with the original ac3-a52 and one copied from that but in aac stereo. I assume there has to be some sort of audio stream mapping command but I don't know how to map and re-encode at the same time. What command should I enter into ffmpeg to achieve this? Also, what is the difference between ac3 and ac3-a52? Will an apple TV still be able to pass through ac3-a52 or does that have to be converted to ac3?

Original source