AC3 Channel Layout and Perian

HandBrake for Mac support
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
zorro2b
Posts: 2
Joined: Tue Dec 08, 2009 7:39 pm

AC3 Channel Layout and Perian

Post by zorro2b »

I am trying to follow this guide to get AC3 passthru working with Perian:
http://www.cod3r.com/2008/02/the-correc ... quicktime/

In step 7 I noticed that the channel layout that Handbrake is producing in the m4v files is not the same as is required for AC3 passthru to work.

Is it possible to specify the channel layout so that the m4v files will be correct for perian and quicktime?
jbrjake
Veteran User
Posts: 4805
Joined: Wed Dec 13, 2006 1:38 am

Re: AC3 Channel Layout and Perian

Post by jbrjake »

As step 7 tells you, those are *Apple's* bugs, not ours.

gbooker's first bug report to Apple:
The channel layout used by QT's built in 'eat ' 'ac-3' is inconsistent with Core Audio's default channel layout. From: http://developer.apple.com/documentatio ... ion_5.html in the channel layout chunk section, it states that if the channel layout is set to use the bitfield, the order is the same as order of the bits set (low order first). This means the layout is:
L R C LFE Ls Rs Cs (missing channels skipped).

The layout used by the built in importer for a 5.1 ac3 file is:
L C R Ls Rs LFE (kAudioChannelLayoutTag_MPEG_5_1_C)

The layout should be consistent with the CA default channel layout, especially since the only multi-channel AC3 decoder that I know of for CA/QT (A52Codec) assumes this layout. For reference, this is:
Channels w/o LFE w/LFE
Mono kAudioChannelLayoutTag_Mono N/A
2F kAudioChannelLayoutTag_Stereo kAudioChannelLayoutTag_DVD_4
3F kAudioChannelLayoutTag_ITU_3_0 kAudioChannelLayoutTag_DVD_10
2F1R kAudioChannelLayoutTag_ITU_2_1 kAudioChannelLayoutTag_DVD_5
3F1R kAudioChannelLayoutTag_ITU_3_1 kAudioChannelLayoutTag_DVD_11
2F2R kAudioChannelLayoutTag_ITU_2_2 kAudioChannelLayoutTag_DVD_6
3F2R kAudioChannelLayoutTag_ITU_3_2 kAudioChannelLayoutTag_ITU_3_2_1

Note: These can all be kAudioChannelLayoutTag_DVD_* formats, but the ITU constants are more descriptive where they exist.
His second:
I write the A52Codec as well as Perian. This is listed under QuickTime, but it may be a Core Audio bug (I cannot tell with information here).

Both A52Codec and Perian contain multi-channel core audio decoders. QuickTime expect the output of the Core Audio component to have channels in a certain order. This order is sent to the Core Audio component via kAudioCodecPropertyInputChannelLayout, and the output is queried via kAudioCodecPropertyOutputChannelLayout (code for handling these is not committed to our repository, but I can make it available upon request). However, in trying to track down the issue, I noticed that this data is sent to one instance of the decoder, while a different instance is used for decode. The instance of the decoder which is actually responsible for decompressing the audio data is *never* told the order of the channels. So, the decoder happily decodes using its default layout, which as I reported in 5799879 is different from Apple's QuickTimes .ac3 importer (which wasn't available until after A52Codec was written and in wide use). The only workaround I can see here is to make the layout a class variable, which goes against the entire object oriented design of core audio.

Perhaps this is merely a documentation issue, as channel layout is horribly undocumented. What is the proper course of action here? As A52Codec will soon be scrapped and AC3 will become part of Perian's binary (http://trac.perian.org/ticket/408), this is the opportune time to express the intent of multi-channel layouts within QuickTime/Core Audio.

I'm really starting to tire of users complaining about these issues which seem to be a bug in QuickTime or Core Audio. Please respond with the proper course of action.
HandBrake uses the proper, standards-based AC3-in-MP4 implementation method described in the spec. That mandates the use of a sound description atom that cannot even *include* a 5.1 channel layout, leaving it almost entirely up to the playback system.

ETSI TS 102 366, section F.3:
The layout of the AC3SampleEntry box is identical to that of AudioSampleEntry defined in ISO/IEC 14496-12 [i.6]
(including the reserved fields and their values), except that AC3SampleEntry ends with a box containing AC-3
bitstream information called AC3SpecificBox.
The AudioSampleEntry defined in ISO/IEC 14496-12, section 8.16.3:
ChannelCount is either 1 (mono) or 2 (stereo)
The problem here is entirely in Apple's court.
zorro2b
Posts: 2
Joined: Tue Dec 08, 2009 7:39 pm

Re: AC3 Channel Layout and Perian

Post by zorro2b »

I realise it's not a Handbrake bug. I am just looking for a way to get surround sound working.

Is there any output format from handbrake that does work well with quicktime? I'm not holding my breath for a fix from apple.
User avatar
Rodeo
HandBrake Team
Posts: 12679
Joined: Tue Mar 03, 2009 8:55 pm

Re: AC3 Channel Layout and Perian

Post by Rodeo »

zorro2b wrote:I realise it's not a Handbrake bug. I am just looking for a way to get surround sound working.
Then follow the instructions in the tutorial you linked to and re-arrange the channel layout if necessary as indicated in step 7.
User avatar
Ritsuka
HandBrake Team
Posts: 1208
Joined: Fri Jan 12, 2007 11:29 am

Re: AC3 Channel Layout and Perian

Post by Ritsuka »

Or change the default layout in the a52codec to the one apple uses.
MacFly
Posts: 23
Joined: Wed Mar 28, 2007 8:33 am

Re: AC3 Channel Layout and Perian

Post by MacFly »

Very intersting ... i know understand why it works in some software and not in others ... Apple's way.

So QTX or QT7 can't play AC3 in MP4 (so M4V) but iTunes plays them fine with m4v extension.

Ritsuka told to change the default layout to the one Apple uses, once this would be done i think passthrough in iTunes would then be broken.

The big problem is for Apple to improve QTX, and make all there apps to use the new Quicktime architecture

QTX player does handle the H.264 streams much better then QT7 (hardware acceleration), so does iTunes but QTX is better then iTunes

QTX, QT7, iTunes ... Apple has to fix all those software and make them work the same way.
jbrjake
Veteran User
Posts: 4805
Joined: Wed Dec 13, 2006 1:38 am

Re: AC3 Channel Layout and Perian

Post by jbrjake »

MacFly wrote:QTX player does handle the H.264 streams much better then QT7 (hardware acceleration), so does iTunes but QTX is better then iTunes
Err, hardware acceleration worked in QT7 long before QTX was even released. It debuted with the unibody MBPs.
iFullgaz
Posts: 2
Joined: Fri Apr 02, 2010 2:12 am

Re: AC3 Channel Layout and Perian

Post by iFullgaz »

Sorry to bump this old thread, but I'd like to know where is the place in the code where I could change the AC3 channel assignment to be kAudioChannelLayoutTag_MPEG_5_1_A instead of the current kAudioChannelLayoutTag_MPEG_5_1_C in MP4 files?
I read the whole explanation from jbrjake and I thank him for making the matter clearer. However, I'd still like to do that because I watch my movies (including my home movies, exported with Handbrake from a Sony cam in MPEG format with AC3 5.1 sound) on my TV using Front Row and an external decoder. This channel assignment problem causes the AC3 passthru to produce this enoying hissing sound in my speakers.
I understand that it might not be standard, advised or what have you but I'd just like to do that.
Anyone with an insight?

Thanks in advance.
Post Reply