Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Multichannel AAC on iOS (Read 13056 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Multichannel AAC on iOS

Hi all,

We are testing 5.1 surround sound on iOS.

  • 5.1 .wav file with "no channel layout", all channels are mapped correctly
  • 5.1 .wav file with "Channel layout: 5.1 (L R C LFE Ls Rs)", all channels are mapped to Front Left & Front Right only

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

Any suggestions, please?

Re: Multichannel AAC on iOS

Reply #1
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.

Re: Multichannel AAC on iOS

Reply #2
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?

Re: Multichannel AAC on iOS

Reply #3
Hi all, thanks for your replies. We have tried the following:

afconvert (MacOS):
  • afconvert -d aac -f m4af -q 127 -s 3 infile.wav outfile.m4a
  • afconvert -d aac -f mp4f -q 127 -s 3 infile.wav outfile.mp4
  • afconvert -d aac -f m4af -q 127 -s 3 -l MPEG_5_1_A -l AAC_5_1 infile.wav outfile.m4a
  • afconvert -d aac -f mp4f -q 127 -s 3 -l MPEG_5_1_A -l AAC_5_1 infile.wav outfile.mp4

qaac (Windows):
  • qaac infile.wav -V127 -o outfile.m4a
  • qaac infile.wav -V127 -o outfile.mp4

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

infile.wav
  • kAudioChannelLayoutTag_MPEG_5_1_A = (121L<<16) | 6, // L R C LFE Ls Rs

outfile.m4a / outfile.mp4
  • kAudioChannelLayoutTag_AAC_5_1 = kAudioChannelLayoutTag_MPEG_5_1_D, // C L R Ls Rs Lfe

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:
  • Channel layout: 5.1 (C L R Ls Rs LFE)

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

5.1 .wav file with "no channel layout"
  • iOS  maps correctly

5.1 .wav file with "Channel layout: 5.1 (L R C LFE Ls Rs)"
  • iOS maps to Front Left & Front Right only

If we could somehow encode to AAC without the channel layout specified, or modify the file header, they might map correctly?

Re: Multichannel AAC on iOS

Reply #4
Hi all,

I have uploaded the following files:

6_Channel_ID_10sec.wav :
  • Original file with channel layout specified.
  • Cannot be encoded using afconvert (MacOS): Error: ExtAudioFileSetProperty ('cfmt') failed ('!dat')
  • Can be encoded using qaac (Windows)
  • All channels map to Front Left & Front Right only on iOS

6_Channel_ID_10sec_NoLayout.wav :
  • Modified file with NO channel layout specified.
  • Can be encoded using afconvert (MacOS)
  • Can be encoded using qaac (Windows)
  • All channels map correctly on iOS

6_Channel_ID_10sec_NoLayout_afconvert.m4a :
  • Encoded to AAC in .m4a container using afconvert (MacOS).
  • All channels map to Front Left & Front Right only on iOS

6_Channel_ID_10sec_NoLayout_afconvert.mp4 :
  • Encoded to AAC in .mp4 container using afconvert (MacOS).
  • All channels map to Front Left & Front Right only on iOS

6_Channel_ID_10sec_NoLayout_qaac.m4a :
  • Encoded to AAC in .m4a container using qaac (Windows).
  • All channels map to Front Left & Front Right only on iOS

6_Channel_ID_10sec_NoLayout_qaac.mp4 :
  • Encoded to AAC in .mp4 container using qaac (Windows).
  • All channels map to Front Left & Front Right only on iOS

Re: Multichannel AAC on iOS

Reply #5
Also these files encoded using ffmpeg and the Fraunhofer FDK AAC codec library (libfdk_aac):

6_Channel_ID_10sec_NoLayout_libfdk.m4a :
  • Encoded to AAC in .m4a container using ffmpeg/libfdk_aac (Windows).
  • ffmpeg -i 6_Channel_ID_10sec_NoLayout.wav -c:a libfdk_aac -vbr 5 6_Channel_ID_10sec_NoLayout_libfdk.m4a
  • All channels map to Front Left & Front Right only on iOS

6_Channel_ID_10sec_NoLayout_libfdk.mp4 :
  • Encoded to AAC in .mp4 container using ffmpeg/libfdk_aac (Windows).
  • ffmpeg -i 6_Channel_ID_10sec_NoLayout.wav -c:a libfdk_aac -vbr 5 6_Channel_ID_10sec_NoLayout_libfdk.mp4
  • All channels map to Front Left & Front Right only on iOS

Re: Multichannel AAC on iOS

Reply #6
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!

Re: Multichannel AAC on iOS

Reply #7
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.

Re: Multichannel AAC on iOS

Reply #8
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?

Re: Multichannel AAC on iOS

Reply #9
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.

Re: Multichannel AAC on iOS

Reply #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:

  • afconvert -d aac -f m4af -q 127 -s 3 infile.wav outfile_01.m4a
  • afconvert -d aac -f m4af -q 127 -s 3 -l MPEG_7_1_A -l AAC_7_1 infile.wav outfile_02.m4a

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.

Re: Multichannel AAC on iOS

Reply #11
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:

  • kAudioChannelLayoutTag_MPEG_5_1_A               = (121L<<16) | 6,                       //  L R C LFE Ls Rs
  • kAudioChannelLayoutTag_MPEG_5_1_B               = (122L<<16) | 6,                       //  L R Ls Rs C LFE
  • kAudioChannelLayoutTag_MPEG_5_1_C               = (123L<<16) | 6,                       //  L C R Ls Rs LFE
  • kAudioChannelLayoutTag_MPEG_7_1_A               = (126L<<16) | 8,                       //  L R C LFE Ls Rs Lc Rc
  • kAudioChannelLayoutTag_MPEG_7_1_B               = (127L<<16) | 8,                       //  C Lc Rc L R Ls Rs LFE
  • kAudioChannelLayoutTag_MPEG_7_1_C               = (128L<<16) | 8,                       //  L R C LFE Ls Rs Rls Rrs

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:

  • ffmpeg -i 6_Channel_ID_10sec.wav -acodec ac3 6_Channel_ID_10sec_ac3.m4a
  • ffmpeg -i 6_Channel_ID_10sec.wav -acodec ac3 6_Channel_ID_10sec_ac3.mp4

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.


Re: Multichannel AAC on iOS

Reply #13
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.

Re: Multichannel AAC on iOS

Reply #14
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.

Re: Multichannel AAC on iOS

Reply #15
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.

Re: Multichannel AAC on iOS

Reply #16
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.

Re: Multichannel AAC on iOS

Reply #17
Perfect, good to know, sorry I should've checked before asking.

Re: Multichannel AAC on iOS

Reply #18
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?

Re: Multichannel AAC on iOS

Reply #19
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.

Re: Multichannel AAC on iOS

Reply #20
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.

Re: Multichannel AAC on iOS

Reply #21
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:
  • .wav will map in the correct order
  • .m4a Apple Lossless need to correct the channel mapping

Re: Multichannel AAC on iOS

Reply #22
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?