How to prevent iTunes/QuickTime Player playing both the main (5.1 AC-3) and backup (2.0 AAC) audio tracks at the same time

audioitunesopen sourcequicktime

I have created for myself a build script to automatically import films into iTunes, making sure that they have compatible audio/video tracks. This generally means that if the input video track isn't H.264, it's converted to it, and if the input audio track isn't DTS, AC-3 or AAC, it's converted to a 2-channel AAC track.

In the special case that the input video's audio track is DTS, AC-3 or multichannel AAC, then a second, 2-channel AAC track is added for compatible with iDevices and my Apple TV 3 (which isn't connected to a device which can decode DTS or AC-3).

Generally this works well, except that if I play the resulting video on my Mac via iTunes or QuickTime Player, they play both audio tracks at the same time, and there doesn't seem to be an option to switch between them. Making them different languages via metadata works, but I'd rather have them both correct.

I use ffmpeg to do the necessary format conversions and AtomicParsley to set the iTunes-compatible metadata. I then use a custom AppleScript to import the resulting file and set the media kind to 'Movie' or 'TV Show' (since iTunes always seems to ignore the metadata set in the file and sets it to 'Home Video').

How can I create the video file with the preserved high-quality audio track and the backup 2-channel AAC, and get iTunes and QuickTime Player to play only the best-quality track they can (ideally in a way which can be automated)? I've noticed that films from the iTunes store include several audio streams, but iTunes never plays them simultaneously.

Update: Looks like at some point recently iPhones and iPads were updated to include an AC-3 decoder, and so are also playing both audio tracks simultaneously. I wouldn't even bother with the AAC stream if not for the Apple TV (pre 4)!

Best Answer

It turns out that streams have a 'default' status, and I guess that this status is copied from the input stream to both the output streams, even though you'd usually only want the high quality one to be the default. All Apple software plays all the default audio streams simultaneously.

To fix this, ffmpeg provides a disposition flag which can be 0 or default (see documentation for further options). To have the first audio track as default and the second one not, you would add as parameters:

-disposition:a:0 default -disposition:a:1 0

Having the AC-3 stream as default appears to automatically play the AAC stream if an AC-3 decoder isn't available, which is exactly what I wanted.