Audio Down mixing to stereo sometimes results in variable bit rate

This is not strictly a plex question but does have a plex slant on it.

Lets take an example. I have an video which has the following audio profile. You can see the bit rate mode is constant.

Audio
ID                                       : 2
Format                                   : E-AC-3 JOC
Format/Info                              : Enhanced AC-3 with Joint Object Coding
Commercial name                          : Dolby Digital Plus with Dolby Atmos
Codec ID                                 : A_EAC3
Duration                                 : 1 h 2 min
Bit rate mode                            : Constant
Bit rate                                 : 768 kb/s
Channel(s)                               : 6 channels
Channel layout                           : L R C LFE Ls Rs
Sampling rate                            : 48.0 kHz
Frame rate                               : 31.250 FPS (1536 SPF)
Compression mode                         : Lossy
Stream size                              : 341 MiB (7%)
Language                                 : English
Service kind                             : Complete Main
Default                                  : Yes
Forced                                   : No
Complexity index                         : 16
Number of dynamic objects                : 15
Bed channel count                        : 1 channel
Bed channel configuration                : LFE

Now, I want to down mix this to stereo and I’m using ffmpeg for this using ffmpeg -y -i input -c:v copy -c:a aac -ac 2 -b:a 256k -ar 48000 output.

Most of the time the resulting output file will results with the following…

Bit rate mode                            : Constant
Bit rate                                 : 256 kb/s

… however, every once in a while I get this which is Bit rate mode: Variable and Bit rate : 256 kb/s / 256 kb/s…

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 1 h 2 min
Source duration                          : 1 h 2 min
Source_Duration_LastFrame                : -11 ms
Bit rate mode                            : Variable
Bit rate                                 : 256 kb/s / 256 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 113 MiB (2%)
Source stream size                       : 113 MiB (2%)
Language                                 : English
Default                                  : Yes
Alternate group                          : 1
mdhd_Duration                            : 3722976

So, my two questions:

  • Anyone know why this happens ? I suspect it might have something to with 256 being a high bit rate for stereo but I’m not 100% sure.
  • Does it even matter and more importantly does it matter within the context of media in plex ?

BTW… I’ve not noticed any sound issues with the media which has this variable bit rate but I’ve only checked a few files with this and I’m kinda afraid I might be missing something.

EDIT: One last thing. If I switch to 192k ffmpeg -y -i input -c:v copy -c:a aac -ac 2 -b:a 192k -ar 48000 output then the resulting output goes to constant. Still, would like to know what is happening at 256k for my own knowledge and if it has any bearing in plex.

Thanks.

Lossy compression pretty much always produces variable bitrates. Even the classic mp3 constant bitrate is just a stream with variable bitrate, which has been “stuffed” with filler bits which don’t do anything for the sound reproduction. (That’s why you can later remove the filler and get back a variable bitrate stream with no change in sound, but slightly smaller file size.)

The same applies to AAC, which is closely related to mp3.

Thanks, informative as ever, much appreciated.

I’ve never experienced this and I’ve down mixed a fairly large amount of media over the years. However, up until recently I’ve used handbrake (setting below)…

Screenshot from 2023-07-08 17-39-06

… but wanted to learn ffmpeg so have switched to that using -c:a aac -ac 2 -b:a 256k -ar 48000 for the audio. Maybe handbrake is adding some filters when it does its encode to ensure it never goes to variable whereas at least for 256k ffmpeg sometimes ends up with variable over constant.

I ran some more tests today on a media file I’ve experiencing this behaviour. Using 128k, 192k and 224k all result in constant whereas 256k gives variable. I might just go with 224k as I’m kinda splitting hairs at this point.

Anyhow, do you have a perspective on what bit rate for stereo audio ? 128k to low, 256k to high and maybe 192k is the happy medium.

I use 224 kbps for AAC myself. It is the “sweet spot” for me, providing high quality audio without taking too much of storage space.

If you are downmixing from surround sound, you want to normalize the loudness of the downmixed signal. Otherwise the result is usually too quiet.

I am using XMedia Recode to do this, because I am too lazy to learn the command line syntax of ffmpeg. XMedia Recode is just a GUI for ffmpeg.
grafik
The normalization requires an “analysis” run before the actual conversion, so that clipping can be avoided and the volume of the source is correctly determined. So this makes processing slightly longer, but the results justify this for me.

Thanks. I do two pass encoding on the video stream anyhow so doing the analysis would not be a problem for audio.

Thanks again.

A brief update on this topic.

After some more investigation I’ve discovered that when down mixing to stereo using aac that there can be some drift with the bit rate which is why it then gets reported as variable even when the constant bit rate is passed -ab 256k. This is not audio drift but bit rate drift.

If for whatever reason you want true CBR with stereo the libfdk_aac encoder is required. I have tested this by building ffmpeg from source and adding libfdk_aac. Using …

Result: variable bit rate mode:

ffmpeg -y -i input -vn -acodec aac -ab 256k -ar 48000 -ac 2 -sn -dn output

Result: constant bit rate mode:

ffmpeg -y -i input -vn -acodec libfdk_aac -ab 256k -ar 48000 -ac 2 -sn -dn output

Anyhow, posting this here for anyone who find this useful into the future. The -vn -sn -dn are used to just ignore video, subtitles and data streams as I only cared about audio in this test.

References:

https://trac.ffmpeg.org/wiki/Encode/AAC
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu

The FDK library is recommended anyway, due to its superior sound quality. It’s just no longer included by default due to license issues.

1 Like

Thanks. I’ll continue to use that going forward.

It does bring up one follow on question. As I’m on linux I need to compile from source ffmpeg to include this encoder. That’s no problem but I’m wondering if this could have any unwanted side effects on my plex server which I know also uses ffmpeg. As your more of a windows expert maybe this question is best answered by @ChuckPa :slight_smile:

As an fyi… this is the configuration I used …

ffmpeg version N-111383-g20b8688092 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 11 (Ubuntu 11.3.0-1ubuntu1~22.04.1)
configuration: --prefix=/home/plex/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/plex/ffmpeg_build/include --extra-ldflags=-L/home/plex/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/plex/bin --enable-gpl --enable-gnutls --enable-libaom --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil      58. 14.100 / 58. 14.100
libavcodec     60. 22.100 / 60. 22.100
libavformat    60. 10.100 / 60. 10.100
libavdevice    60.  2.101 / 60.  2.101
libavfilter     9.  8.102 /  9.  8.102
libswscale      7.  3.100 /  7.  3.100
libswresample   4. 11.100 /  4. 11.100
libpostproc    57.  2.100 / 57.  2.100

The re-configured ffmpeg is placed under my home users ~/bin/ which is first in $PATH so in essence this makes it the default ffmpeg on the system.

May have found an answer to this. Assuming this Version of FFMPEG in Plex - #2 by anon18523487 is still true then it appears plex uses it’s own custom ffmpeg itself so anything I configure myself should be independent of that.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.