[Matroska-devel] Spec update regarding audio timecodes

Steve Lhomme steve.lhomme at free.fr
Tue Jan 20 23:03:41 CET 2004

I think things should be explained in a more specific way...

To compute the timecode of a Block we use the following formula :

a) Timecode in ns = (Block Timecode Value * Track TimecodeScale + 
Cluster Timecode) * Global TimecodeScale

That means we have :
b) float = (int16 * float + uint64) * uint64

Which is usually transformed into an integer :
c) uint64 = (int16 * float + uint64) * uint64

In most cases, the Track TimecodeScale is 1.0, so we get :
d) uint64 = (int16 + uint64) * uint64

So the sample accurate problem only occurs for audio. For video and 
subs, we can keep the Track TimecodeScale to 1.0.

So how can we mix audio and video and keep sample accuracy seeking ? You 
just use a sufficient Track TimecodeScale on the audio track. Let's take 
an example.

Audio at 44100 Hz (PCM)
Video at 25fps (RGB)

A good Cluster size is usually 2s long. That means
88200 = 2*44100 audio samples
50 = 2*25 video frames

Let's take the first Cluster (they are all equivalent for the example).
The Cluster timecode is 0. And usually the Global TimecodeScale is 

So for the video formula d) becomes :
VideoTimecode = int16 * uint64

And for the audio formula c) becomes :
AudioTimecode = int16 * float * uint64

The range of the resulting uint64 is from 0 to 2,000,000,000. So without 
the Global TimecodeScale we have :
VideoTimecode = int16
AudioTimecode = int16 * float

With the timecodes ranging from 0 to 2,000. For the video, there is no 
problem as a int16 ranges from 0 to 32767 (in the positive side). But 
for the audio, we need to have 88200 samples that can only span over 
32768 values. This is basically impossible.

Conclusion : it is impossible to have large Clusters & Sample accurate 
precision of the timecode. And the bigger the audio sampling rate, the 
smaller the Cluster has to be. (in this case we need a Cluster smaller 
than 0.743s = 32768/44100 to be able to have a distinctive timecode for 
each sample)

More information about the Matroska-devel mailing list