Audacity and VLC duration are different

I don’t know if I am missing something obvious or not but here is what is happening.

I open the same exact file with VLC and with Audacity and the duration shown for each is different (Audacity always has the shorter duration). This only happens in about 1 in 50 of the files I’m working with but it does happen it can be off by anywhere from 2 seconds to 30 seconds. I have compared the two and it seems that if a file has long bits of silence in the middle, Audacity cuts it down. Is this desired behavior? If so, how can I make it not do this?


The “1 in 50” files that this occurs with is probably in a compressed format (such as MP3) and has a “variable bit-rate” (“VBR”).

For “uncompressed” audio formats, and compressed formats with “constant bit-rate” (“CBR”), the exact length of a file is calculated by multiplying the number of samples by the sample rate (uncompressed formats) or the number of bits by the bit-rate (compressed “CBR”). This always gives the exact right answer.

For compressed “VBR” formats, there are several ways that the length can be determined. It can be read from the file header (if present), or from “metadata” (if present), or it may be calculated by multiplying the number of bits by the “overall bit-rate”. Note that the “overall bit-rate” is an approximation, because the bit-rate is constantly varying according to the complexity of the sound at any point in time. Different applications may report different durations, depending on which method they use, but note that this is only the “reported” duration - it should have no effect on the actual play time. Note also that “Audacity is always right”, because Audacity is reporting the actual play length after the file has been decoded.

[u]MP3diags[/u] should be able to repair your files so they show the correct time on VLC (or other players). Or if you have access to a Windows machine, [u]VBRfix[/u].

The files I am working with are m4b (audiobook) files.

The issue I am having with this is that I am using Audacity silence finder to find the chapter breaks in the audiobook. I then use mp4chaps (which leverages ffmpeg) to place a chapter mark at that timestamp. However, when I use the timestamp that audacity gives me, it places the mark 2-30 seconds away from where it should be. After placing the timestamp, I have tested with VLC, Smart Audiobook Player, and Listen Audiobook Player and the chapter break is placed in the wrong spot. Is there anyway I can get Audacity to report the timestamp in the equivalent location as ffmpeg would consider it?

What does this page say about the file?

Complete name : Black.m4b
Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/iso2/mp41)
File size : 406 MiB
Duration : 14 h 21 min
Overall bit rate mode : Variable
Overall bit rate : 65.8 kb/s
Album : The Black Swan
Album/Performer : Nassim Nicholas Taleb
Track name : 0101
Performer : Nassim Nicholas Taleb
Genre : Audiobooks
ContentType : Audiobook
Tagged date : UTC 2019-10-16 16:24:17
Writing application : Lavf58.32.104 / m4b-tool

ID : 1
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 14 h 21 min
Bit rate mode : Variable
Bit rate : 64.4 kb/s
Maximum bit rate : 77.8 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 44.1 kHz
Frame rate : 43.066 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 397 MiB (98%)
Default : Yes
Alternate group : 1
Menus : 4

Menu #1
00:00:00.000 : Prologue
00:36:38.121 : Part One - Umberto Eco’s Antilibrary, or How We Seek Validation
00:40:39.176 : Chapter One - The Apprenticeship of An Empirical Skeptic
01:39:56.033 : Chapter Two - Yevgenia’s Black Swan
01:46:37.006 : Chapter Three - The Speculator and the Prostitute
02:19:55.728 : Chapter Four - One Thousand and One Days, or How Not to Be a Sucker
02:56:44.451 : Chapter Five - Confirmation Shmonfirmation!
03:30:47.661 : Chapter Six - The Narrative Fallacy
04:39:21.990 : Chapter Seven - Living in the Antechamber of Hope
05:21:51.653 : Chapter Eight - Giacomo Casanova’s Unfailing Luck: The Problem of Silent Evidence
06:23:32.029 : Chapter Nine - The Ludic Fallacy, or the Uncertainty of the Nerd
06:58:42.924 : Part Two - We Just Can’t Predict
07:03:19.845 : Chapter Ten - The Scandal of Prediction
08:25:50.201 : Chapter Eleven - How to Look for Bird Poop
09:35:28.627 : Chapter Twelve - Epistemocracy, a Dream
10:06:09.292 : Chapter Thirteen - Appelles the Painter, or What Do You Do If You Cannot Predict?
10:38:08.740 : Part Three - Those Gray Swans of Extremistan
10:40:02.970 : Chapter Fourteen - From Mediocristan to Extremistan, and Back
11:22:49.512 : Chapter Fifteen - The Bell Curve, That Great Intellectual Fraud
12:27:12.528 : Chapter Sixteen - The Aesthetics of Randomness
13:20:31.428 : Chapter Seventeen - Locke’s Madmen, or Bell Curves in the Wrong Places
13:50:59.319 : Chapter Eighteen - The Uncertainty of the Phony
14:08:06.516 : Chapter Nineteen - Half and Half, Or How to Get Even with the Black Swan
14:16:48.567 : Epilogue: Yevgenia’s White Swans

Menu #2
ID : 4
Codec ID : text
Duration : 14 h 21 min
Encoded date : UTC 2019-10-16 16:24:17
Tagged date : UTC 2019-10-16 16:24:17
Menu For : 1
Bit rate mode : VBR

I just looked at some of the other m4b files and they say the bitrate is CBR. This is odd since I converted and encoded all the files with the same tool. But at least now I know the root issue. I need to get all my files to be CBR if I want chapter marks to work correctly. Which means that Audacity isn’t the place I need help. It is the perfect tool I had thought it to be, and I’m sorry to have ever doubted it. Off to go ask for help with a different tool. :wink: