Hydrogenaudio Forums

Lossy Audio Compression => AAC => AAC - Tech => Topic started by: hkphooey on 2017-09-10 18:09:12

Title: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-10 18:09:12
Hi all,

We are testing 5.1 surround sound on iOS.


When either file is encoded to AAC, the .m4a / .mp4, all channels are mapped to Front Left & Front Right only.

Any suggestions, please?
Title: Re: Multichannel AAC on iOS
Post by: Klimis on 2017-09-10 21:12:21
Which encoder are you using? I cannot reproduce this error on Foobar with any AAC encoder. It might be some kind of middleware's fault for such weird behavior.
Title: Re: Multichannel AAC on iOS
Post by: Chibisteven on 2017-09-10 21:34:15
I think iOS cannot map the other channel layout format properly.

It probably just supports the legacy wav file 5.1 layout (FL, FC, FR, LFE, RL, RR) and not the other one (FL, FC, FR, LFE, SL, SR).

Has anyone tried 7.1  (FL, FC, FR, LFE, SL, SR, RL, RR)?  You can use the back channels as dummies (silence) for example with 5.1 material.

Also what are you using to encode AAC and it's settings?
Title: Re: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-11 06:51:36
Hi all, thanks for your replies. We have tried the following:

afconvert (MacOS):

qaac (Windows):

We are aware that files encoded to AAC will have a different channel layout than the original .wav

infile.wav

outfile.m4a / outfile.mp4

All encoded files play fine in Audacity (MacOS & Windows), and appear fine in afinfo (MacOS) / Mediainfo (Windows), however when played on iOS, all channels are mapped to Front Left & Front Right only.

We suspect the issue is related to how the channel layout is specified in the AAC encoded .m4a / .mp4 files, as follows:

Looking at the original .wav files with afinfo (MacOS) / Mediainfo (Windows):

5.1 .wav file with "no channel layout"

5.1 .wav file with "Channel layout: 5.1 (L R C LFE Ls Rs)"

If we could somehow encode to AAC without the channel layout specified, or modify the file header, they might map correctly?
Title: Re: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-11 13:16:47
Hi all,

I have uploaded the following files:

6_Channel_ID_10sec.wav :

6_Channel_ID_10sec_NoLayout.wav :

6_Channel_ID_10sec_NoLayout_afconvert.m4a :

6_Channel_ID_10sec_NoLayout_afconvert.mp4 :

6_Channel_ID_10sec_NoLayout_qaac.m4a :

6_Channel_ID_10sec_NoLayout_qaac.mp4 :
Title: Re: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-11 14:49:04
Also these files encoded using ffmpeg and the Fraunhofer FDK AAC codec library (libfdk_aac):

6_Channel_ID_10sec_NoLayout_libfdk.m4a :

6_Channel_ID_10sec_NoLayout_libfdk.mp4 :
Title: Re: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-11 15:12:40
Which encoder are you using? I cannot reproduce this error on Foobar with any AAC encoder. It might be some kind of middleware's fault for such weird behavior.
Please upload any example of an AAC encoded 5.1 audio file that does map correctly on iOS. Thanks!
Title: Re: Multichannel AAC on iOS
Post by: @KJAMMcom on 2017-09-11 15:18:35
The  not setting the flag issue might be a red herring? as one of the other responders pointed out you might be dealing with a 'legacy' multichannel format and not setting the flag allows the system to play correctly with PCM wavs. I'm not sure if this is standalone multi channel audio or is for use wrapped with video, but either way I'm seeing a lot of IOS aac multichannel issues full stop.  I've had issues with media with aac multichannel assignments in the past and always resorted to AC3 wrapping. Here's an indicative quote from 2014 - This is recommended to someone looking to deploy multichannel aac on IOS.

    If on Mac, check out MP4Tools.  It can create iOS native files that include both stereo AAC and multichannel AC3.  From a little of my research, AAC 5.1 is not really a thing.  iTunes purchases with multichannel audio have two audio tracks: one in AC3 format for multichannel and the other in AAC for stereo.


source
https://forums.plex.tv/discussion/110680/dolby-digital-with-aac-and-ac3

There are several discussions thrown up on HDMI (with IOS) and Apple TV playing aac multichannel groups downmixed (or stripped) to just L & R and usually the answer is to transcode to wav.
Title: Re: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-11 17:32:00
I think iOS cannot map the other channel layout format properly.

It probably just supports the legacy wav file 5.1 layout (FL, FC, FR, LFE, RL, RR) and not the other one (FL, FC, FR, LFE, SL, SR).

Has anyone tried 7.1  (FL, FC, FR, LFE, SL, SR, RL, RR)?  You can use the back channels as dummies (silence) for example with 5.1 material.

Also what are you using to encode AAC and it's settings?

If I understand correctly, you are suggesting we try encoding to a (supported?) 7.1 format, ie:


And map the required input channels to the required output channels?
Title: Re: Multichannel AAC on iOS
Post by: Chibisteven on 2017-09-12 09:47:58
I think iOS cannot map the other channel layout format properly.

It probably just supports the legacy wav file 5.1 layout (FL, FC, FR, LFE, RL, RR) and not the other one (FL, FC, FR, LFE, SL, SR).

Has anyone tried 7.1  (FL, FC, FR, LFE, SL, SR, RL, RR)?  You can use the back channels as dummies (silence) for example with 5.1 material.

Also what are you using to encode AAC and it's settings?

If I understand correctly, you are suggesting we try encoding to a (supported?) 7.1 format, ie:

  • kAudioChannelLayoutTag_AAC_7_1                  = kAudioChannelLayoutTag_MPEG_7_1_B,    // C Lc Rc L R Ls Rs Lfe

And map the required input channels to the required output channels?
5,1 Side mapping to 7.1
FL = FL
FR = FR
FC = FC
LFE = LFE
SL = SL
SL = SR
RL = Empty (silence)
RR = Empty (silence)

6.1 discrete mapping to 7.1
FL = FL
FR = FR
FC = FC
LFE = LFE
SL = SL
SL = SR
RL = RC (trimmed about -3 dB)
RR = RC (trimmed about -3 dB)

What I'm saying is that I wonder if 7.1 wav actually works on iOS or causes it's own issues as 8 uncompressed PCM channels is standard in HDMI 1.3 and newer (which has been around for quite a while) as you're in position to test it where I am not.  In my experience with dealing with iTunes and iPods is that sometimes using AIFF gets around wav issues.  It's the first I heard of AAC issues on iOS since I don't deal with AAC in multichannel form.  I'm more familiar with multichannel FLAC, OGG Vorbis, WavPack and of course formats like 5,1 Dolby Digital and DTS CDs.  5.1 Dolby Digital can be encoded with FFMPEG.
Title: Re: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-14 15:33:10
What I'm saying is that I wonder if 7.1 wav actually works on iOS or causes it's own issues as 8 uncompressed PCM channels is standard in HDMI 1.3 and newer (which has been around for quite a while) as you're in position to test it where I am not.  In my experience with dealing with iTunes and iPods is that sometimes using AIFF gets around wav issues.  It's the first I heard of AAC issues on iOS since I don't deal with AAC in multichannel form.  I'm more familiar with multichannel FLAC, OGG Vorbis, WavPack and of course formats like 5,1 Dolby Digital and DTS CDs.  5.1 Dolby Digital can be encoded with FFMPEG.
We have now tested this by encoding an 8-channel .wav to AAC with the following:


As with all of our tests to date, the original .wav file plays and maps correctly on iOS.
The encoded .m4a files play, but all channels are mapped to Front Left & Front Right only.

All files are attached to this post.
Title: Re: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-14 16:14:53
The  not setting the flag issue might be a red herring? as one of the other responders pointed out you might be dealing with a 'legacy' multichannel format and not setting the flag allows the system to play correctly with PCM wavs. I'm not sure if this is standalone multi channel audio or is for use wrapped with video, but either way I'm seeing a lot of IOS aac multichannel issues full stop.

Audio only. Please refer to the files attached to the posts in this thread.

We have now tested input .wav files that conform to the following standards:


I've had issues with media with aac multichannel assignments in the past and always resorted to AC3 wrapping. Here's an indicative quote from 2014 - This is recommended to someone looking to deploy multichannel aac on IOS.
If on Mac, check out MP4Tools.  It can create iOS native files that include both stereo AAC and multichannel AC3.  From a little of my research, AAC 5.1 is not really a thing.  iTunes purchases with multichannel audio have two audio tracks: one in AC3 format for multichannel and the other in AAC for stereo.
source
https://forums.plex.tv/discussion/110680/dolby-digital-with-aac-and-ac3
There are several discussions thrown up on HDMI (with IOS) and Apple TV playing aac multichannel groups downmixed (or stripped) to just L & R and usually the answer is to transcode to wav.

We are keen to avoid using AC3 if at all possible. The advantages of AAC vs AC3 are well documented.

However, we have now tested this by encoding a 6-channel .wav to AC3 with the following:


As with all of our tests to date, the original .wav file plays and maps correctly on iOS.
The encoded .m4a/.mp4 files play, but all channels are mapped to Front Left & Front Right only.

All files are attached to this post.
Title: Re: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-14 17:42:35
Hardware is iPad Pro → Lightning to USB 3 Camera Adapter → miniDSP U-DAC8

Lightning to USB 3 Camera Adapter:
https://www.apple.com/shop/product/MK0W2AM/A/lightning-to-usb-3-camera-adapter

miniDSP U-DAC8:
https://www.minidsp.com/products/usb-audio-interface/u-dac8
Title: Re: Multichannel AAC on iOS
Post by: Chibisteven on 2017-09-15 01:39:36
Here's the thing though.  Dolby Digital does have the best advantage of just working in most surround setups.  The patent for it has expired as well.
Title: Re: Multichannel AAC on iOS
Post by: eahm on 2017-09-15 01:50:31
Chibisteven, is there a CLI of Dolby Pulse AAC for foobar2000? I would like to test it, I remember EZ CD had the encoder included IIRC.
Title: Re: Multichannel AAC on iOS
Post by: Chibisteven on 2017-09-15 02:44:28
Chibisteven, is there a CLI of Dolby Pulse AAC for foobar2000? I would like to test it, I remember EZ CD had the encoder included IIRC.

Not that I know of and this looks like a newer version of Dolby Digital that is still covered by patents.
Title: Re: Multichannel AAC on iOS
Post by: LithosZA on 2017-09-15 09:47:55
Chibisteven, is there a CLI of Dolby Pulse AAC for foobar2000? I would like to test it, I remember EZ CD had the encoder included IIRC.

Not that I know of and this looks like a newer version of Dolby Digital that is still covered by patents.

It is HE-AACv2. From Wikipedia:
Quote
Dolby Pulse: released in 2009, it is identical to the HE-AAC v2 codec except for the addition of Dolby metadata, which is common to Dolby's other digital audio codecs. This metadata "ensures consistency of broadcast quality.
Title: Re: Multichannel AAC on iOS
Post by: eahm on 2017-09-15 10:38:01
Perfect, good to know, sorry I should've checked before asking.
Title: Re: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-15 10:41:39
Chibisteven, is there a CLI of Dolby Pulse AAC for foobar2000? I would like to test it, I remember EZ CD had the encoder included IIRC.
Are you suggesting we test this to get multichannel AAC working on iOS, or is this off-topic?
Title: Re: Multichannel AAC on iOS
Post by: eahm on 2017-09-15 11:03:55
Chibisteven, is there a CLI of Dolby Pulse AAC for foobar2000? I would like to test it, I remember EZ CD had the encoder included IIRC.
Are you suggesting we test this to get multichannel AAC working on iOS, or is this off-topic?
That too, I am always up for testing everything I can.
Title: Re: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-15 18:40:06
We are definitely seeing a pattern now...

Just encoded the 6_Channel_ID_10sec.wav to Apple Lossless using dBpoweramp Music Converter.

The output .m4a file does NOT have a channel layout specified in the file header, and maps to all 5.1 speakers on iOS, although the channel mapping is messed up:

AUDIO CH      SPEAKER
=============================
01 - FL       02 - FR
02 - FR       03 - FC
03 - FC       01 - FL
04 - LFE      06 - RR
05 - RL       04 - LFE
06 - RR       05 - RL


This is similar to the behavior described in the original post regarding .wav files, although channel mapping is correct with .wav files with no channel layout specified in the file header.

We have found that whenever we encode to AAC, AC3 or ALAC, and a channel layout IS specified in the file header, all channels are mapped to Front Left & Front Right only.

It seems only files with NO channel layout specified in the file header will map to all 5.1 outputs.

Can anyone provide any insight into how/why dBpoweramp Music Converter is outputting encoded files without a channel layout specified in the file header?

All files are attached to this post.
Title: Re: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-17 08:53:06
ffmpeg also encodes to Apple Lossless WITHOUT specifying a channel layout in the file header of the resulting .m4a file:
Code: [Select]
ffmpeg -i infile.wav -c:a alac outfile.m4a
iOS maps to all 5.1 channels, but the channel mapping is changed (same mapping as Apple Lossless files encoded by dBpoweramp, listed in previous post).
We can correct the channel mapping with the pan audio filter:
Code: [Select]
ffmpeg -i infile.wav -af "pan=5.1|c0=c1|c1=c2|c2=c0|c3=c5|c4=c3|c5=c4" -c:a alac outfile.m4a
Prevent the warning "Guessed Channel Layout for Input Stream #0.0 : 5.1" for input files with no channel layout specified in the file header:
Code: [Select]
ffmpeg -channel_layout 5.1 -i infile.wav -af "pan=5.1|c0=c1|c1=c2|c2=c0|c3=c5|c4=c3|c5=c4" -c:a alac outfile.m4a
So, all good for Apple Lossless, but how do we do the same with Apple AAC or Fraunhofer FDK AAC?
It seems iOS devices cannot parse standard MPEG channel layouts specified in the file header by these codecs, forcing iOS devices to fallback to mapping all channels to Front Left and Front Right only.
Only files with NO channel layout specified in the file header will map to all 5.1 channels:
Title: Re: Multichannel AAC on iOS
Post by: hkphooey on 2017-09-21 18:06:46
Can anyone upload any example of an AAC encoded 5.1 audio file that does map correctly on iOS?

Can anyone upload any example of an AAC encoded 5.1 audio file that does NOT have a channel layout specified in the file header?

Does such a thing exist?
SimplePortal 1.0.0 RC1 © 2008-2018