20

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?

sion
  • 1,367
  • 6
  • 17
  • 21

3 Answers3

24

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 copyStream 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 copyStream 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?

llogan
  • 121,796
  • 28
  • 232
  • 243
AJ29
  • 1,381
  • 10
  • 10
8

I'm doing the same as the OP, but with an m4v container. I'm using the MacPorts "nonfree" variant of ffmpeg so that I can use libfaac, which gives better audio quality than the built-in AAC encoder and also had the same issue as @dkam. The command line I ended using is like this:

ffmpeg -i input.m4v -map 0:v -c:v copy -map 0:a -c:a:0 copy -map 0:a -c:a:1 libfaac output.m4v

(The videos are for playback on an iPad, which doesn't seem to be able to handle ac3.)

markshep
  • 728
  • 7
  • 17
0

This command will take a video with 1 audio stream, and downmix to stereo and convert the audio stream and add it as a 2nd audio stream. It will be in AAC 384k.

ffmpeg -i INPUT.mkv -strict -2 -map 0 -c copy -map 0:a:0 -c:a:1 aac -b:a 384k -ac 2 OUTPUT.mkv

Explanation of the command

  • ffmpeg -i INPUT.mkv The application and input file
  • -strict -2 Enable downmixing support
  • -map 0 Tell ffmpeg read all Video, Audio, and Subtitle streams for the following arguments
    • -c copy Copy everything
  • -map 0:a:0 Tell ffmpeg to read the first audio stream for the following arguments
    • -c:a:1 aac Output the audio to a 2nd audio channel (0 = first channel) in aac format. Important! You must change the output channel to a higher number if there are multiple audio streams to prevent overwriting them.
    • -b:a 384k 384k bitrate (I don't know what's good for aac stereo but this is really high since it's for 5.1 aac)
    • -ac 2 Downmix to stereo
  • OUTPUT.mkv Output file

More examples

A video with two audio streams. Creating a third audio stream by encoding the first.

ffmpeg -i INPUT.mkv -strict -2 -map 0 -c copy -map 0:a:0 -c:a:2 aac -b:a 384k -ac 2 OUTPUT.mkv

Again a video with two audio streams, but you want to encode the second one

ffmpeg -i INPUT.mkv -strict -2 -map 0 -c copy -map 0:a:1 -c:a:2 aac -b:a 384k -ac 2 OUTPUT.mkv

Jack Cole
  • 1,528
  • 2
  • 19
  • 41