Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Force CBR #55

Closed
danrneal opened this issue Oct 16, 2019 · 8 comments
Closed

Feature Request: Force CBR #55

danrneal opened this issue Oct 16, 2019 · 8 comments

Comments

@danrneal
Copy link

When I am using the merge tool with --audio-bitrate=64k, 99% of the time it spits out a file that is of a constant bitrate (CBR). However, occasionally it spits out a file that has a variable bitrate. This typically only happens with books that have longish gaps of silence. The reason this is a problem is that it makes it very difficult to place chapter marks after the fact. Files that are VBR have problems seeking and also have different (reported) duration by differing software. For instance Audacity will report one duration and timestamp and VLC a different duration and different timestamps. I would be awesome if all of this could be avoided by simply having m4b-tool enforce that the output file be CBR.

@sandreas
Copy link
Owner

sandreas commented Oct 17, 2019

AFAIK m4b-tool only supports CBR at the moment. VBR is not supported at all - and so i think your problem with VBR on some kind of files could a problem with ffmpeg, which is used as encoder and merges the files.

The documentation (https://trac.ffmpeg.org/wiki/Encode/AAC) clearly states for libfdk_aac(the recommended non-free but best quality encoder for m4b-tool), that CBR is used, if
-b:a 128k is used as parameter while -vbr 3 means, that 48-56 kbps per channel are used.

For the native ffmpeg aac encoder the vbr option would be -q:a 1.0, with a range from 0.1 to 2.0, but it seems to be experimental.

Currently m4b-tool is using -ab 64k instead of -b:a 64k, which seems to be an old or generic way to specify the bitrate. So the solution of this feature request might be using -b:a instead of -ab, when libfdk_aac is available. But i have to check that.

@danrneal
Copy link
Author

danrneal commented Oct 17, 2019

I am using libfdk_acc (unless I am mistaken, but there is no warning from m4b-tool when I use it). For reference here are the settings I am using:

m4b-tool merge --audio-bitrate=64k --output-file="Audiobooks/Astrophysics for People in a Hurry.m4b" "Audiobooks/Astrophysics for People in a Hurry/"

The original files are all CBR mp3s. When I put the resulting m4b into this site: https://mediaarea.net/MediaInfoOnline , this is the result:

General
Complete name                            : Astrophysics for People in a Hurry.m4b
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/mp41)
File size                                : 103 MiB
Duration                                 : 3 h 41 min
Overall bit rate mode                    : Variable
Overall bit rate                         : 64.8 kb/s
Album                                    : Astrophysics for People in a Hurry
Track name                               : Preface
Performer                                : Neil deGrasse Tyson
Composer                                 : Neil deGrasse Tyson
ContentType                              : Audiobook
Description                              : What is the nature of space and time? How do we fit within the universe? How does the universe fit within us? There's no better guide through these mind-expanding questions than acclaimed astrophysicist and best-selling author Neil deGrasse Tyson. ...
Recorded date                            : 2017
Tagged date                              : UTC 2019-10-17 07:21:52
Writing application                      : Lavf58.32.104 / m4b-tool

@sandreas
Copy link
Owner

Nice. Thank you. I'll check this with some of the samples i use for testing and provide feedback in the next days.

@sandreas
Copy link
Owner

Could you try with the latest pre-build? That may fix the issue (and some others). As always: Be careful, it is not a stable release!

@danrneal
Copy link
Author

General
Complete name                            : Astrophysics for People in a Hurry.m4b
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/mp41)
File size                                : 102 MiB
Duration                                 : 3 h 41 min
Overall bit rate mode                    : Variable
Overall bit rate                         : 64.7 kb/s
Album                                    : Astrophysics for People in a Hurry
Track name                               : Preface
Performer                                : Neil deGrasse Tyson
Composer                                 : Neil deGrasse Tyson
ContentType                              : Audiobook
Description                              : What is the nature of space and time? How do we fit within the universe? How does the universe fit within us? There's no better guide through these mind-expanding questions than acclaimed astrophysicist and best-selling author Neil deGrasse Tyson. ...
Recorded date                            : 2019/10/19
Tagged date                              : UTC 2019-10-20 02:46:46
Writing application                      : m4b-tool
Cover                                    : Yes
LongDescription                          : What is the nature of space and time? .....

Audio
ID                                       : 1
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 3 h 41 min
Bit rate mode                            : Variable
Bit rate                                 : 64.0 kb/s
Maximum bit rate                         : 69.8 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 22.05 kHz
Frame rate                               : 21.533 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 101 MiB (99%)
Default                                  : Yes
Alternate group                          : 1
Menus                                    : 2

Still outputting Variable bit rate.

@sandreas
Copy link
Owner

Ok, so during my experiments i did not find any way to get real cbr with ffmpeg.

Here is a bug regarding mp3:
https://trac.ffmpeg.org/ticket/431
(the Redirection trick did not work for me: - >myoutputfile.mp3)

Some more resources:
https://superuser.com/questions/1234688/unable-to-create-aac-mp3-cbr-256k-using-ffmpeg
https://stackoverflow.com/questions/10908796/how-to-force-constant-bit-rate-using-ffmpeg

There are even more things i could try, but perhaps you can help out... If you find any way to get cbr with an ffmpeg command, you can tell me and i try to fix it - e.g. with variations of:

 ffmpeg -i test.wav -c:a libfdk_aac -b:a 256k -y test.aac –

or

ffmpeg 
-i input 
-b 1200k 
-minrate 1200k 
-maxrate 1200k 
-bufsize 1200k 
-ab 64k 
-vcodec libx264 
-acodec aac -strict -2 
-ac 2 
-ar 44100 
-s 320x240 
-y output.mp4

Otherwise i would try to achieve this with fdkaac binary, but since ffmpeg is the more common binary used in m4b-tool i would prefer this.

@sandreas
Copy link
Owner

sandreas commented Oct 20, 2019

Ok, did some more research. It seems, that NONE of the available encoders / tools is able to produce REAL cbr (which also is reported as cbr by mediainfo).

See: https://forum.videohelp.com/threads/391032-[ffmpeg]-why-using-AAC-codec-the-bitrate-is-alwais-VBR-I-need-CBR#post2535470

Anyway, I tried four different AAC encoders in CBR mode (ffmpeg, QAAC, FDKAAC and NeroAAC) and they all resulted in bitrates that varied a little, so I guess there's no such thing as truly CBR AAC.
To add to the fun through, QAAC and FDK AAC both added CBR to the written encoder information, and (coincidentally?) MediaInfo declared them both to be variable bitrate.

So even using fdkaac did not produce a file, that is reported as cbr by mediainfo.

Although this means, that this feature request cannot be added due to limitations of the dependencies (or more precisely due limitations of all available free tools) at the moment, you may be comforted by the fact, that during my research, i integrated some improvements using the fdkaac encoder, which should at least make it possible to force using fdkaac, which may produce the result, that you are expecting (but maybe not...) and at least adds CBR to the written encoder, which is the closest thing to cbr you can get. Another improvement that fell out, was, that you can provide a new option --audio-quality, which takes a percentage of the wanted quality and produce a vbr file of the given quality option without providing a valid --audio-bitrate or --audio-samplerate

Now you can force the use of fdkaac by providing a valid profile, e.g. --audio-profile=aac_lc in the latest release.

Read more at:
https://forum.videohelp.com/threads/391032-%5Bffmpeg%5D-why-using-AAC-codec-the-bitrate-is-alwais-VBR-I-need-CBR

@danrneal
Copy link
Author

I've been too busy the past few days to test this. But I just tested my most "problem-child" file that I have and I am please to report that --audio-profile=aac_lc works as expected and is a huge improvement. Thank you for your help!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants