Opened 4 years ago

Last modified 2 years ago

#8939 open defect

libopus: mapping_family does not get set correctly for surround sound

Reported by: frk1337 Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: libopus channel_layout
Cc: lootafoytnanrspc@gmail.com Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
ffmpeg does not set mapping_family correct for surround sound when using libopus. This leads to wrong surround sound (e.g. for me voice was coming from the back speakers).

How to reproduce:

% ffmpeg -i 'source.mkv' -vn -sn -map 0:a:0 -c:a libopus ffmpeg.opus
ffmpeg version N-99608-g6ef55f54fe Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.0 (GCC)
configuration: --prefix=/usr --extra-cflags=-I/usr/include/tensorflow --disable-rpath --enable-gpl --enable-version3 --enable-nonfree --enable-shared --disable-static --disable-stripping --enable-gray --enable-avresample --enable-alsa --enable-avisynth --enable-bzlib --enable-chromaprint --enable-frei0r --enable-gcrypt --enable-gmp --enable-gnutls --enable-iconv --enable-ladspa --enable-libaom --enable-libaribb24 --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcelt --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libdavs2 --enable-libdc1394 --enable-libfdk-aac --enable-libflite --enable-fontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libiec61883 --enable-libilbc --enable-libjack --enable-libklvanc --enable-libkvazaar --enable-liblensfun --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-libopencv --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librav1e --enable-librsvg --enable-librubberband --enable-librtmp --enable-libshine --enable-libsmbclient --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvthevc --enable-libsvtav1 --enable-libtensorflow --enable-libtesseract --enable-libtheora --disable-libtls --enable-libtwolame --enable-libuavs3d --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libsvtvp9 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxavs2 --enable-libxcb --enable-libxcb-shm --enable-libxcb-xfixes --enable-libxcb-shape --enable-libxvid --enable-libxml2 --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-lzma --enable-decklink --disable-mbedtls --enable-libmysofa --enable-openal --enable-opencl --enable-opengl --disable-openssl --enable-pocketsphinx --enable-sndio --enable-sdl2 --enable-vapoursynth --enable-vulkan --enable-xlib --enable-zlib --enable-amf --enable-libdrm --enable-omx --enable-v4l2-m2m --enable-vaapi --enable-vdpau
libavutil      56. 60.100 / 56. 60.100
libavcodec     58.111.101 / 58.111.101
libavformat    58. 62.100 / 58. 62.100
libavdevice    58. 11.102 / 58. 11.102
libavfilter     7. 87.100 /  7. 87.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  8.100 /  5.  8.100
libswresample   3.  8.100 /  3.  8.100
libpostproc    55.  8.100 / 55.  8.100

Source file:

Format : DTS ES XXCH XLL
Format/Info : Digital Theater Systems
Commercial name : DTS-HD Master Audio
Codec ID : A_DTS
Duration : 3 h 48 min
Bit rate mode : Variable
Bit rate : 4 742 kb/s
Channel(s) : 7 channels
Channel layout : C L R Ls Rs LFE Cb
Sampling rate : 48.0 kHz
Frame rate : 93.750 FPS (512 SPF)
Bit depth : 24 bits
Compression mode : Lossless
Stream size : 7.56 GiB (13%)
Title : DTS-HD MA 6.1
Language : English
Default : Yes
Forced : No

The command above sets the layout (6.1) correctly but does not set mapping_family correctly so the channels get coupled wrong (voice is coming from the back). Converting to wav and using opusenc directly leads correct mapping. As does manually specifing -mapping_family 1.

Change History (3)

comment:1 by Safari, 4 years ago

Cc: lootafoytnanrspc@gmail.com added

comment:2 by ArseGnomes, 3 years ago

Status: newopen

I hit this too, but in converting via an intermediate 5.1 WAV (as editing was required). What made me suspicious was that libopus in default VBR with a target usually undershoots the specified rate by a decent amount when mapping_family is set correctly and this time it went over, so I did a second run with the same source file and mapping_family explicitly set to verify and came up with this:

>ffmpeg -i file.wav -c:a libopus -b:a 768k file.opus
Input #0, wav, from 'file.wav':
  Duration: 01:22:01.89, bitrate: 9216 kb/s
  Stream #0:0: Audio: pcm_f32le ([3][0][0][0] / 0x0003), 48000 Hz, 5.1, flt, 9216 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_f32le (native) -> opus (libopus))
Press [q] to stop, [?] for help
Output #0, opus, to 'file.opus':
  Metadata:
    encoder         : Lavf59.5.100
  Stream #0:0: Audio: opus, 48000 Hz, 5.1, flt, 768 kb/s
    Metadata:
      encoder         : Lavc59.7.103 libopus
size=  480778kB time=01:22:01.89 bitrate= 800.2kbits/s speed=34.5x
video:0kB audio:478567kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.461974%


>ffmpeg -i file.wav -c:a libopus -b:a 768k -mapping_family 1 test.opus

Input #0, wav, from 'file.wav':
  Duration: 01:22:01.89, bitrate: 9216 kb/s
  Stream #0:0: Audio: pcm_f32le ([3][0][0][0] / 0x0003), 48000 Hz, 5.1, flt, 9216 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_f32le (native) -> opus (libopus))
Press [q] to stop, [?] for help
Output #0, opus, to 'test.opus':
  Metadata:
    encoder         : Lavf59.5.100
  Stream #0:0: Audio: opus, 48000 Hz, 5.1, flt, 768 kb/s
    Metadata:
      encoder         : Lavc59.7.103 libopus
size=  396990kB time=01:22:01.89 bitrate= 660.7kbits/s speed=33.4x
video:0kB audio:395142kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.467612%

I didn't check whether there was actually a problem with channel mapping / sound quality in the larger file and just assumed it was due to the mapping_family=1 surround optimizations not being run. I also tried manually setting compression level to 10 but this didn't change results, so that part of the docs seems correct.

The input .wav was the >4GB .wav type Adobe Audition outputs and channels are handled correctly by ffmpeg so that's not an issue. (...The 4GB limit ffmpeg has for wav extension outputs but not for inputs is another oddity I haven't looked into)

So, either the codecs page, which says that anything > stereo defaults to 1 for mapping_family, or program behavior is wrong here.

comment:3 by Carl Eugen Hoyos, 2 years ago

Component: undeterminedavcodec
Keywords: channel_layout added; channellayout removed
Priority: importantnormal
Note: See TracTickets for help on using tickets.