Opened 4 years ago

Last modified 4 years ago

#3160 new defect

ac3 silently chooses 5.1(side) channel layout

Reported by: llogan Owned by:
Priority: minor Component: avcodec
Version: git-master Keywords: ac3
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

According to the AC-3 standards[1], as far as I can tell, AC-3 supports 5.1(side) [FL+FR+FC+LFE+SL+SR] but not 5.1 [FL+FR+FC+LFE+BL+BR] channel layout. The standards show "L, C, R, SL, SR", but no reference to any back or rear channels such as BL and BR.

ffmpeg will silently choose 5.1(side) even if 5.1 is attempted:

$ ffmpeg -f lavfi -i aevalsrc=0:d=1 -filter_complex "[0:a]asplit=6[fl][fr][fc][lfe][bl][br];[fl][fr][fc][lfe][bl][br]amerge=inputs=6,channelmap=0|1|2|3|4|5:channel_layout=5.1" out.ac3
ffmpeg version N-58330-g6a7980e Copyright (c) 2000-2013 the FFmpeg developers
  built on Nov 21 2013 12:42:31 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl
  libavutil      52. 53.100 / 52. 53.100
  libavcodec     55. 44.100 / 55. 44.100
  libavformat    55. 21.100 / 55. 21.100
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 91.100 /  3. 91.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, lavfi, from 'aevalsrc=0:d=1':
  Duration: N/A, start: 0.000000, bitrate: 2822 kb/s
    Stream #0:0: Audio: pcm_f64le, 44100 Hz, mono, dbl, 2822 kb/s
[Parsed_amerge_1 @ 0x344fd00] No channel layout for input 1
[Parsed_amerge_1 @ 0x344fd00] Input channel layouts overlap: output layout will be determined by the number of distinct input channels
Output #0, ac3, to 'out.ac3':
  Metadata:
    encoder         : Lavf55.21.100
    Stream #0:0: Audio: ac3, 44100 Hz, 5.1, fltp, 448 kb/s
Stream mapping:
  Stream #0:0 (pcm_f64le) -> asplit
  channelmap -> Stream #0:0 (ac3)
Press [q] to stop, [?] for help
size=      57kB time=00:00:01.03 bitrate= 450.5kbits/s    
video:0kB audio:57kB subtitle:0 global headers:0kB muxing overhead 0.000000%
$ ffmpeg -i out.ac3 
ffmpeg version N-58330-g6a7980e Copyright (c) 2000-2013 the FFmpeg developers
  built on Nov 21 2013 12:42:31 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl
  libavutil      52. 53.100 / 52. 53.100
  libavcodec     55. 44.100 / 55. 44.100
  libavformat    55. 21.100 / 55. 21.100
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 91.100 /  3. 91.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
[ac3 @ 0x1f33100] Estimating duration from bitrate, this may be inaccurate
Input #0, ac3, from 'out.ac3':
  Duration: 00:00:01.04, start: 0.000000, bitrate: 448 kb/s
    Stream #0:0: Audio: ac3, 44100 Hz, 5.1(side), fltp, 448 kb/s
At least one output file must be specified

The output file is correct, in my opinion, but an informative message indicating that 5.1(side) will be used instead is probably a good idea, and/or for the encoding command the console output should show 5.1(side) instead of 5.1.

[1] http://www.atsc.org/cms/standards/a_52-2010.pdf (page 40, table 5.8)

Change History (4)

comment:1 Changed 4 years ago by cehoyos

I (think I) understand the ticket but please note that the ac3 encoder does not "choose" 5.1(side), it encodes both 5.1 and 5.1(side) as AC3_CHMODE_3F2R (3 front channels, two rear channels) which is the only 3-2 configuration supported by ac3 (as you showed) - lfe is always encoded independently. This makes sense for performance reasons but also because I am not sure if all FFmpeg multichannel audio decoders distinguish correctly between 5.1 and 5.1(side).

I suggest that if you really believe such a warning makes sense, switch "case AV_CH_LAYOUT_5POINT0_BACK:" and "case AV_CH_LAYOUT_5POINT0:" in libavcodec/ac3enc.c (line 2087), add a warning in between (and commit) and send your patch to ffmpeg-devel.

comment:2 Changed 4 years ago by cehoyos

  • Component changed from undetermined to avcodec

comment:3 follow-up: Changed 4 years ago by Selur

When using:

ffmpeg -y -threads 8 -analyzeduration 100M -probesize 100M -i "h:\Outp
ut\cut.m2ts" -map 0:1 -vn -filter_complex "aevalsrc=0:0:0:0:0:0::d=0.138:sample_
rate=48000[silence];[silence][0:a]concat=n=2:v=0:a=1[out]" -map [out]  -c:a ac3
-ab 384000 -map_metadata -1 "H:\Output\iId_3_aid_4352_15_30_47_8910_01.ac3"

I get:

ffmpeg version N-58971-g945a440 Copyright (c) 2000-2013 the FFmpeg developers built on Dec 11 2013 15:17:28 with gcc 4.8.2 (rev0, Built by MinGW-W64 project)
  configuration: --arch=x86_64 --prefix=/local64 --extra-cflags='-DPTW32_STATIC_LIB -DLIBTWOLAME_STATIC' --extra-libs='-lxml2 -lz -liconv -lws2_32 -lstdc++ -lpng -lm -lpthread -lwsock32' --disable-debug --enable-gpl--enable-version3 --enable-postproc --enable-w32threads --enable-runtime-cpudetect --enable-memalign-hack --disable-shared --enable-static --enable-avfilter --enable-bzlib --enable-zlib --enable-librtmp --enable-gnutls --enable-avisynth --enable-frei0r --enable-filter=frei0r --enable-libbluray --enable-libcaca --enable-libopenjpeg --enable-fontconfig --enable-libfreetype --enable-libass --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-libschroedinger --enable-libsoxr --enable-libtwolame --enable-libutvideo --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvo-aacenc --enable-libopus --enable-libvidstab --enable-libvpx --enable-libxavs --enable-libx264 --enable-libxvid --enable-libzvbi
  libavutil      52. 58.100 / 52. 58.100
  libavcodec     55. 45.100 / 55. 45.100
  libavformat    55. 22.100 / 55. 22.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     3. 92.100 /  3. 92.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
[h264 @ 000000000043f340] SEI type 1 size 56 truncated at 53
[h264 @ 000000000043f340] mmco: unref short failure
    Last message repeated 1 times
[h264 @ 000000000043f340] number of reference frames (0+4) exceeds max (3; probably corrupt input), discarding one
[h264 @ 000000000043f340] SEI type 1 size 56 truncated at 53
    Last message repeated 38 times
Input #0, mpegts, from 'h:\Output\cut.m2ts':
  Duration: 00:00:30.11, start: 4292.050000, bitrate: 7719 kb/s
  Program 1
    Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x1100]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 384 kb/s
[Parsed_aevalsrc_0 @ 000000000043d7a0] This syntax is deprecated. Use '|' to separate the list items.
[ac3 @ 00000000070e41e0] ac3 files have exactly one stream
Output #0, ac3, to 'H:\Output\iId_3_aid_4352_15_30_47_8910_01.ac3':
  Metadata:
    encoder         : Lavf55.22.100
    Stream #0:0: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:1: Audio: ac3, 48000 Hz, 5.1, fltp, 384 kb/s
Stream mapping:
  Stream #0:1 (ac3) -> concat:in1:a0 (graph 0)
  Stream #0:1 -> #0:0 (ac3 -> ac3)
  concat (graph 0) -> Stream #0:1 (ac3)
Could not write header for output file #0 (incorrect codec parameters ?): Error
number -22 occurred
}}

The problem for me seem so be the difference between 5.1 and 5.1(side), which is why I posted this here.

-> is there a way to tell ffmpeg which to use "5.1" or "5.1(side)" ?

Last edited 4 years ago by Selur (previous) (diff)

comment:4 in reply to: ↑ 3 Changed 4 years ago by Cigaes

Replying to Selur:

Could not write header for output file #0 (incorrect codec parameters ?): Error number -22 occurred

This is certainly unrelated to your problem, but this line, the "error number -22", shows that something is seriously rotten in your ffmpeg build.

Note: See TracTickets for help on using tickets.