Opened 19 months ago

Last modified 19 months ago

#10321 new enhancement

mov_channel_layout[] table possible issues

Reported by: Tim Owned by:
Priority: normal Component: avformat
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Note: this is kind of a "thinking out loud" thing, possibly worth discussing anyway.

Example:
https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/a3f4916:/libavformat/isom.c#l400

    { AV_CH_LAYOUT_7POINT1, (128<<16) | 8}, // kCAFChannelLayoutTag_MPEG_7_1_C

https://developer.apple.com/library/archive/documentation/MusicAudio/Reference/CAFSpec/CAF_spec/CAF_spec.html

    kCAFChannelLayoutTag_MPEG_7_1_C = (128<<16) | 8,         // L R C LFE Ls Rs Rls Rrs

Thus:

L | R | C | LFE | BL | BR | SL  | SR     AV_CH_LAYOUT_7POINT1
L | R | C | LFE | Ls | Rs | Rls | Rrs    kCAFChannelLayoutTag_MPEG_7_1_C

BL == Ls (kCAFChannelLabel_LeftSurround)
BR == Rs (kCAFChannelLabel_RightSurround)
but SL (kCAFChannelLabel_LeftSurroundDirect) != Rls (kCAFChannelLabel_RearSurroundLeft)
and SR (kCAFChannelLabel_RightSurroundDirect) != Rls (kCAFChannelLabel_RearSurroundRight)

…also, perhaps importantly, as far as I can understand, SL and SR are supposedly closer to
the front channels than BL/Ls and BR/Rs whereas Rls Rrs are behind BL/Ls and BL/Rs, making
the mapping rather problematic?

On the other hand:

L | R | C | LFE | BL | BR | FLC | FRC    AV_CH_LAYOUT_7POINT1_WIDE_BACK
L | R | C | LFE | Ls | Rs | Lc  | Rc     kCAFChannelLayoutTag_MPEG_7_1_A

but there is no mapping for it in the mov_channel_layout table.

L | R | C | LFE | SL | SR | FLC | FRC    AV_CH_LAYOUT_7POINT1_WIDE
L | R | C | LFE | Ls | Rs | Lc  | Rc     kCAFChannelLayoutTag_MPEG_7_1_A

exists with SL == Ls and SR == Rs, which is also used by AV_CH_LAYOUT_5POINT1 ==
kCAFChannelLayoutTag_MPEG_5_1_A and several other mappings, but is somewhat less
problematic since there are no back channels in the corresponding AV_CH_LAYOUTs.

Also:

L | R | C | LFE | BL | BR | BC    AV_CH_LAYOUT_6POINT1_BACK
L | R | C | LFE | Ls | Rs | Cs    kCAFChannelLayoutTag_MPEG_6_1_A

seems suitable but is absent from the table.

This would not work, on the other hand:

L | R | C | LFE | BC | SL | SR    AV_CH_LAYOUT_6POINT1
L | R | C | LFE | Ls | Rs | Cs    kCAFChannelLayoutTag_MPEG_6_1_A

(but does not exist in the table, just noteworthy)

Finally/FWIW https://developer.apple.com/documentation/coreaudiotypes/1572101-audio_channel_layout_tags?language=objc

Does list some additional WAVE-specific layout tags which are not
present in the CAF Channel Layout Chunk specification, for example:

kAudioChannelLayoutTag_WAVE_7_1 = (189U<<16) | 8

Change History (2)

comment:1 by Tim, 19 months ago

Here's some experiments re: "WAVE" layout tags in CAF (have not tested AIFF/MOV).

ffmpeg -i 7point1.dts -c:a pcm_s24le -f caf ffmpeg.caf

% afinfo ffmpeg.caf
File:           ffmpeg.caf
File type ID:   caff
Num Tracks:     1
----
Data format:     8 ch,  96000 Hz, lpcm (0x0000000C) 24-bit little-endian signed integer
Channel layout: 7.1 (L R C LFE Ls Rs Rls Rrs)
estimated duration: 111.110833 sec
audio bytes: 255999360
audio packets: 10666640
bit rate: 18432000 bits per second
packet size upper bound: 24
maximum packet size: 24
audio data file offset: 130
optimized
audio 10666640 valid frames + 0 priming + 0 remainder = 10666640
source bit depth: I24
----
%

Using afconvert to force a change of channel layout tag w/out
re-ordering (instead, overriding the layout tag for the input):

kAudioChannelLayoutTag_WAVE_7_1 = (189U<<16)
% afconvert -v -f caff -d LEI24 -l WAVE_7_1 -l WAVE_7_1 ffmpeg.caf afconvert.caf
Input file: ffmpeg.caf, 10666640 frames, MPEG_7_1_C
Formats:
  Input file     8 ch,  96000 Hz, lpcm (0x0000000C) 24-bit little-endian signed integer
                 WAVE_7_1 -- overriding layout MPEG_7_1_C in file
  Output file    8 ch,  96000 Hz, lpcm (0x0000000C) 24-bit little-endian signed integer
                 WAVE_7_1
Optimizing afconvert.caf... done
Output file: afconvert.caf, 10666640 frames
%

Result:

% afinfo afconvert.caf
File:           afconvert.caf
File type ID:   caff
Num Tracks:     1
----
Data format:     8 ch,  96000 Hz, lpcm (0x0000000C) 24-bit little-endian signed integer
Channel layout: 7.1 (L R C LFE Rls Rrs Ls Rs)
estimated duration: 111.110833 sec
audio bytes: 255999360
audio packets: 10666640
bit rate: 18432000 bits per second
packet size upper bound: 24
maximum packet size: 24
audio data file offset: 4096
optimized
audio 10666640 valid frames + 0 priming + 0 remainder = 10666640
source bit depth: I24
----
tim@Timothys-MBP Downloads %
Channel layout: 7.1 (L R C LFE Rls Rrs Ls Rs)
AV_CH_LAYOUT_7POINT1 L R C LFE BL  BR  SL SR

Making kAudioChannelLayoutTag_WAVE_7_1 potentially useful.

However, the WAVE layout tags were not present several years ago, so I am unsure what is
the oldest version of macOS/afconvert that can actually read files with such tags "correctly".

kAudioChannelLayoutTag_WAVE_6_1 = (188U<<16) | 7

afconvert -v -f caff -d LEI24 -l WAVE_6_1 -l WAVE_6_1 6.1.ffmpeg.caf 6.1.afconvert.caf

% afinfo 6.1.afconvert.caf
File:           6.1.afconvert.caf
File type ID:   caff
Num Tracks:     1
----
Data format:     7 ch,  96000 Hz, lpcm (0x0000000C) 24-bit little-endian signed integer
Channel layout: 6.1 (L R C LFE Cs Ls Rs)
estimated duration: 111.110833 sec
audio bytes: 223999440
audio packets: 10666640
bit rate: 16128000 bits per second
packet size upper bound: 21
maximum packet size: 21
audio data file offset: 4096
optimized
audio 10666640 valid frames + 0 priming + 0 remainder = 10666640
source bit depth: I24
----
%
Channel layout: 6.1 (L R C LFE Cs Ls Rs)
AV_CH_LAYOUT_6POINT1 L R C LFE BC SL SR

Other WAVE layout tags:

kAudioChannelLayoutTag_WAVE_2_1   = kAudioChannelLayoutTag_DVD_4
kAudioChannelLayoutTag_WAVE_3_0   = kAudioChannelLayoutTag_MPEG_3_0_A
kAudioChannelLayoutTag_WAVE_4_0_A = kAudioChannelLayoutTag_ITU_2_2
kAudioChannelLayoutTag_WAVE_4_0_B = (185U<<16) | 4
kAudioChannelLayoutTag_WAVE_5_0_A = kAudioChannelLayoutTag_MPEG_5_0_A
kAudioChannelLayoutTag_WAVE_5_0_B = (186U<<16) | 5
kAudioChannelLayoutTag_WAVE_5_1_A = kAudioChannelLayoutTag_MPEG_5_1_A
kAudioChannelLayoutTag_WAVE_5_1_B = (187U<<16) | 6

The _B layout tags are a bit redundant and can arguably only map to the _BACK channel layouts,
whereas the _A variants are a bit more versatile; the difference being Ls vs. Rls and Rs vs. Rrs:

afconvert -v -f caff -d LEI24 -l WAVE_5_1_B -l WAVE_5_1_B 5.1.ffmpeg.caf 5.1.afconvert.caf

Channel layout: 5.1 (L R C LFE Rls Rrs)
_LAYOUT_5POINT1_BACK L R C LFE BL  BR

afconvert -v -f caff -d LEI24 -l WAVE_5_1_A -l WAVE_5_1_A 5.1.ffmpeg.caf 5.1.afconvert.caf

Channel layout: 5.1 (L R C LFE Ls Rs)
_LAYOUT_5POINT1_BACK L R C LFE BL BR
AV_CH_LAYOUT_5POINT1 L R C LFE SL SR

comment:2 by Tim, 19 months ago

Also, when using -c:a copy for e.g. ac3 input and CAF output, a chan will be written with the incorrect tag (corresponding to Libav's native channel order, not the ac3 bitstream's actual order)…

Note: See TracTickets for help on using tickets.