28 April 2018

Fixing videos without sound on 2nd generation Apple TV

I was trying to watch some TV episodes recently that wouldn’t play sound through my second generation Apple TV due to their audio encoding. Fixing them turned out not to be too hard, but working it out took a while, so here it is documented for posterity.

The MP4 video files had AC3 5.1 surround sound audio, shown as “AC3 (6 ch)” in Subler. However, the 2nd gen Apple TV only supports playing stereo audio over HDMI, and 5.1 audio only works via “pass through” on the optical output to an AV receiver (when enabled via Dolby Audio in the Apple TV settings). I don’t have an AV receiver or anything else hooked up to the optical port on my Apple TV. So playing these files on the Apple TV results in no sound being sent via HDMI, and no sound for me while watching these videos.

The fix is to reencode the audio as AAC stereo, while passing through the video and subtitle streams without modification. Install ffmpeg via Homebrew, then run the following command:

ffmpeg -y -i file.mp4 -map 0 -c:v copy -c:a aac -ac 2 -c:s copy file-fixed.mp4

The arguments are as follows:

  • -y — overwrites any existing output file
  • -i file.mp4 — input file
  • -map 0 — sends all streams from the first (and only) input file to the output file
  • -c:v copy — uses the “copy codec” for the video stream, which means pass it through unchanged
  • -c:a aac -ac 2 — uses the AAC codec for the audio stream, with just 2 audio channels
  • -c:s copy — copies the subtitle tracks (if any)
  • file-fixed.mp4 — the output filename.

Looping this over all my files fixed the soundtrack, which appeared afterwards as “AAC (2 ch)” in Subler. It also shaved about 100 MB off the file size of each. I was happily watching the TV episodes (with glorious stereo sound) on my old Apple TV soon after.

Credit to this Stack Overflow post for leading me down the right track.